From f85e63b6e00373d5239c4d405b796e5780b3b3b9 Mon Sep 17 00:00:00 2001 From: Benjamin Loison <12752145+Benjamin-Loison@users.noreply.github.com> Date: Mon, 13 May 2024 18:30:28 +0200 Subject: [PATCH] #62: First lazy load try MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` OPERATION = RESOLUTION = 100 Image: 0%|▍ | 1/200 [00:00<00:00, 5084.00it/s] Camera: 0%| | 0/2 [00:00 rawColorChannels = np.load(numpyFilePath, mmap_mode = 'r', allow_pickle = True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/benjamin/venv/lib/python3.11/site-packages/numpy/lib/npyio.py", line 453, in load return format.open_memmap(file, mode=mmap_mode, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/benjamin/venv/lib/python3.11/site-packages/numpy/lib/format.py", line 932, in open_memmap raise ValueError(msg) ValueError: Array can't be memory-mapped: Python objects in dtype. ``` --- datasets/raise/benchmark_load_part_of_images.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/datasets/raise/benchmark_load_part_of_images.py b/datasets/raise/benchmark_load_part_of_images.py index d4e8c37..c5a39b0 100755 --- a/datasets/raise/benchmark_load_part_of_images.py +++ b/datasets/raise/benchmark_load_part_of_images.py @@ -16,7 +16,10 @@ class Operation(Enum): SAVE = auto() LOAD_NPY = auto() -OPERATION = Operation.LOAD_RAW + def __str__(self): + return self.name + +OPERATION = Operation.LOAD_NPY RESOLUTION = 100 print(f'{OPERATION = }') if OPERATION == Operation.LOAD_NPY: @@ -37,7 +40,7 @@ for camera in tqdm(IMAGES_CAMERAS_FOLDER, 'Camera'): if OPERATION == Operation.SAVE: np.save(numpyFilePath, rawColorChannels) if OPERATION == Operation.LOAD_NPY: - rawColorChannels = np.load(numpyFilePath, allow_pickle = True) + rawColorChannels = np.load(numpyFilePath, mmap_mode = 'r', allow_pickle = True) rawColorChannelsItem = rawColorChannels.item() for color in Color: - print(color, rawColorChannelsItem[color].mean()) \ No newline at end of file + print(color, rawColorChannelsItem[color][:RESOLUTION].mean()) \ No newline at end of file