简体   繁体   中英

Blank Memory error when trying to divide the numpy image array by 255

Here im basically trying to predict age and gender by some images and labels through image recognition. But im getting the below error when im trying to divide the image numpy array by 255 to normalize it.

import csv
import os
from pathlib import *

dir_path = Path('C:\\Users\\Yeshan\\Desktop\\my projs\\UTKFace')
files = dir_path.glob('*.jpg')

import cv2
ages=[]
genders=[]
images=[]

for fle in files:
    filename = Path(fle).name
    age=int(str(filename).split('_')[0])
    ages.append(age)
    gender = int(str(filename).split('_')[1])
    genders.append(gender)
    
    img = cv2.imread(os.path.join(dir_path,filename))
    
    image= cv2.resize(img,(48,48))
    images.append(image)

labels=[]
i=0
while i<len(ages):
  label=[]
  label.append([ages[i]])
  label.append([genders[i]])
  labels.append(label)
  i+=1

from sklearn.model_selection import train_test_split

images_f=np.array(images)
print(images[0])
labels_f=np.array(labels)

images_f_2=images_f/255

The error:

MemoryError Traceback (most recent call last) in ----> 1 images_f_2=images_f/255 MemoryError:

BTW: I did try =/ 255 and still did not work, trie converting to float and diving and still no luck.

And this is how images_f array looks like:

array([[[[196, 201, 210],
         [176, 183, 192],
         [127, 137, 146],
         ...,
         [103, 100,  99],
         [ 97,  96,  91],
         [103,  95,  91]],

        [[197, 202, 211],
         [140, 147, 156],
         [123, 134, 142],
         ...,
         [108, 109, 107],
         [103, 100,  99],
         [105,  95,  95]],

        [[188, 193, 202],
         [155, 162, 171],
         [141, 152, 160],

Just restart your machine and try again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM