Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
325 views
in Technique[技术] by (71.8m points)

python - 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],
question from:https://stackoverflow.com/questions/65641094/blank-memory-error-when-trying-to-divide-the-numpy-image-array-by-255

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just restart your machine and try again.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...