From 462bd9250994ad1840978321a2229fedc328e439 Mon Sep 17 00:00:00 2001 From: Benjamin Loison <12752145+Benjamin-Loison@users.noreply.github.com> Date: Wed, 15 May 2024 16:23:39 +0200 Subject: [PATCH] Make production ready `benchmark_load_part_of_images.py` --- .../raise/benchmark_load_part_of_images.py | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/datasets/raise/benchmark_load_part_of_images.py b/datasets/raise/benchmark_load_part_of_images.py index c5a39b0..ce1576e 100755 --- a/datasets/raise/benchmark_load_part_of_images.py +++ b/datasets/raise/benchmark_load_part_of_images.py @@ -17,7 +17,7 @@ class Operation(Enum): LOAD_NPY = auto() def __str__(self): - return self.name + return self.name.lower() OPERATION = Operation.LOAD_NPY RESOLUTION = 100 @@ -25,22 +25,23 @@ print(f'{OPERATION = }') if OPERATION == Operation.LOAD_NPY: print(f'{RESOLUTION = }') +def getNumpyFilePath(imageFilePath, color): + numpyFilePath = f'{imageFilePath}.{color}.npy' + return numpyFilePath + for camera in tqdm(IMAGES_CAMERAS_FOLDER, 'Camera'): imagesCameraFolder = IMAGES_CAMERAS_FOLDER[camera] for file in tqdm(os.listdir(imagesCameraFolder), 'Image'): if file.endswith('.NEF') or file.endswith('.ARW'): #print(file) imageFilePath = f'{imagesCameraFolder}/{file}' - numpyFilePath = f'{imageFilePath}.npy' - rawColorChannels = {} - if OPERATION in [Operation.LOAD_RAW, Operation.SAVE]: - for color in Color: + for color in Color: + if OPERATION in [Operation.LOAD_RAW, Operation.SAVE]: rawColorChannel = getColorChannel(imageFilePath, color) - rawColorChannels[color] = rawColorChannel - if OPERATION == Operation.SAVE: - np.save(numpyFilePath, rawColorChannels) - if OPERATION == Operation.LOAD_NPY: - rawColorChannels = np.load(numpyFilePath, mmap_mode = 'r', allow_pickle = True) - rawColorChannelsItem = rawColorChannels.item() - for color in Color: - print(color, rawColorChannelsItem[color][:RESOLUTION].mean()) \ No newline at end of file + if OPERATION == Operation.SAVE: + numpyFilePath = getNumpyFilePath(imageFilePath, color) + np.save(numpyFilePath, rawColorChannel) + if OPERATION == Operation.LOAD_NPY: + numpyFilePath = getNumpyFilePath(imageFilePath, color) + rawColorChannel = np.load(numpyFilePath, mmap_mode = 'r') + print(color, rawColorChannel[:RESOLUTION].mean()) \ No newline at end of file