MX TV
MX TV

Reputation: 25

ValueError: cannot reshape array of size 2251 into shape (48,48)

i am geeting this error when i try to run this part of code in Google colab to train the cnn:

ValueError                                Traceback (most recent call last) <ipython-input-12-0b1325cd4065> in <module>()
      3 for xseq in datapoints:
      4     xx = [int(xp) for xp in xseq.split(' ')]
----> 5     xx = np.asarray(xx).reshape(width, height)
      6     X.append(xx.astype('float32'))
      7  ValueError: cannot reshape array of size 2251 into shape (48,48)

my code

# getting features for training
X = []
for xseq in datapoints:
    xx = [int(xp) for xp in xseq.split(' ')]
    xx = np.asarray(xx).reshape(width, height)
    X.append(xx.astype('float32'))

Upvotes: 0

Views: 242

Answers (1)

Samuel Armbrust
Samuel Armbrust

Reputation: 71

Once you are splitting you xseq data, you may have lost some data. See that a shape of 2251 = (47.44 x 47.44), so it does not fit and is not a multiple of desired shape (48 x 48).

Check what is the original size of xseq object and confirm that you need to split. Then confirm that the shape matches the expected (48,48).

Another possibility is to resize your object instead of reshape, but you may also lose some important information.

Upvotes: 1

Related Questions