I am working on a facial recognition use case. I have 57k jpg images and am converting them into an array. While executing the program, I am getting a memory error.
The function I am using:
def image_array(l):
features = []
for pgm in l:
pic = image.load_img(pgm, target_size=(224, 224))
x = image.img_to_array(pic)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
features.append(x)
npfeatures = np.array(features)
img_dt = np.rollaxis(npfeatures, 1, 0)
return img_dt[0]
The input for this function is a list which looks like:
l =['/home/user/image1.jpg','/home/user/image2.jpg','/home/user/image3.jpg'......]
The error that I am getting:
Traceback (most recent call last):
File "FR.py", line 145, in <module>
vec_image1 = image_array(final_df['image1'].values.tolist())
File "FR.py", line 140, in image_array
npfeatures = np.array(features)
MemoryError
The imports that I used for above function are:
> from keras.preprocessing import image
> from keras.applications.vgg16 import preprocess_input