1

I am working on a large dataset consisting images.

When I run the following code:

data=[]
def image_to_feature_vector(image, size=(128, 128)):
   return cv2.resize(image, size).flatten()

for i in range(0,len(imagePath)):
    image = cv2.imread(imagePath[i])
    features = image_to_feature_vector(image)
    data.append(features)

data = np.array(data) / 255.0

I got an error as:

np.array(data) / 255.0

MemoryError

How to fix this? Thanks in advance!!!

2
  • Let me guess, 32bit build of Python? Commented Nov 29, 2017 at 16:56
  • 1
    @DanMašek No, I am using 64bit build version. Commented Nov 29, 2017 at 17:07

1 Answer 1

2

Some easy memory saving strategies include

1 preallocate data and avoid creating a temporary list

data = np.empty((len(imagePath),) + features_shape)
for i, slc in enumerate(data):
     ...
     slc[...] = features

2 use in-place operations where possible

data /= 255.0
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.