Memory error (digits recognition in python av article ) - train_x = np.stack(temp) and in test_x = np.stack(temp)

python

#1

temp = []
for img_name in train.filename:
image_path = os.path.join(data_dir, ‘Train’, ‘Images’, ‘train’, img_name)
img = imread(image_path, flatten=True)
img = img.astype(‘float32’)
temp.append(img)

train_x = np.stack(temp)

temp = []
for img_name in test.filename:
image_path = os.path.join(data_dir, ‘Train’, ‘Images’, ‘test’, img_name)
img = imread(image_path, flatten=True)
img = img.astype(‘float32’)
temp.append(img)

test_x = np.stack(temp)


#2

Hi @Krishtetali,
I think this is because your computer is not having sufficient memory to contain the entire dataset in RAM.
Try this:
nsample = 1000 #number of samples, try to keep is small
for img_name in train.filename[0:nsample]:

for img_name in test.filename[0:nsample]:

Thanks,
Sohom


#3

Yeah , just remove stack() form line it works fine , thanks for replying