Make production ready benchmark_load_part_of_images.py

This commit is contained in:
Benjamin Loison 2024-05-15 16:23:39 +02:00
parent f7c08849dc
commit 462bd92509
No known key found for this signature in database

View File

@ -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())
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())