I am trying to read images in numpy array images the following way:
import os
import psutil
import numpy as np
from skimage.transform import resize
from skimage.io import imread
img_names = sorted(glob(my_dir + '/' + '*.jpg'))
images = np.empty((len(img_names),) + basic_shape, dtype='float32')
process = psutil.Process(os.getpid())
print('MEM:', process.memory_info().rss)
for i in range(0, len(img_names)):
images[i] = resize(imread(img_names[i]), basic_shape)
process = psutil.Process(os.getpid())
print('MEM:', process.memory_info().rss)
Before I start reading process.memory_info().rss says that process is using 926846976 bytes. After reading the process is using 2438307840 bytes which is approximately 2.5 times more than before.
Why after reading the process memory is increasing that much and is there any way to reduce the size of allocated memory when reading images?