I'd like to concurrently load multiple grayscale images from files on disk and put them inside a large numpy array in order to speed up loading time. Basic code looks like this:
import numpy as np
import matplotlib.pyplot as plt
# prepare filenames
image_files = ...
mask_files = ...
n_samples = len(image_files) # == len(mask_files)
# preallocate space
all_images = np.empty(shape=(n_samples, IMG_HEIGHT, IMG_WIDTH), dtype=np.float32)
all_masks = np.empty(shape=(n_samples, IMG_HEIGHT, IMG_WIDTH), dtype=np.float32)
# read images and masks
for sample, (img_path, mask_path) in enumerate(zip(image_files, mask_files)):
all_images[sample, :, :] = plt.imread(img_path)
all_masks[sample, :, :] = plt.imread(mask_path)
I'd like to execute this loop in parallel, however, I know that Python true multithreading capabilities are limited due to GIL.
Do you have any ideas?