0

I have 200000 colored images each of dimensions (50x50x3) stored as a list of list in Python. Because its all in a list, I want to change it to numpy array of dimension (200000,50,50,3). However, using np.toarray(list) returns an array of shape (200000,)

But if I shorten the list (say take only 10000 elements) and then do np.toarray(shortened_list), it returns a correct array of shape (10000,50,50,3)

I want to do this to feed the images to a CNN using Keras.

1 Answer 1

1

One or more images doesn't have the correct shape, or is not an image, thus it's impossible to put them into an array of numbers.

Numpy is then creating an array of objects. Find the wrong image and remove it from the list or resize it correctly.

Hint:

for i, img in enumerate(shortened_list):

    if not hasattr(img, 'shape'):
        print("wrong image at index " + str(i))
    elif img.shape != (50,50,3):
        print("wrong image at index " + str(i))
Sign up to request clarification or add additional context in comments.

1 Comment

This helped a lot. There was quiet a few images with different shapes in the data set

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.