0

here is the code that i'm trying to run

labelled_data = [data, Label]
X,Y = [labelled_data[0],labelled_data[1]]

X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.4, 
random_state=4)

x_test, x_validation, y_test, y_validation=train_test_split(X_test, 
Y_test, test_size=0.5,
 random_state=4)
import numpy as np


print(X_train.shape)

the output is:

(2266, 196608)

now i want to reshape the matrices for training set, validation set and test set.

X_train = X_train.reshape((X_train.shape[0],256,256,1))
x_validation = x_validation.reshape((x_validation.shape[0],256,256,1))
x_test =x_test.reshape((x_test.shape[0],256,256,1))

X_train = X_train.astype('float32')
x_validation = x_validation.astype('float32')
x_test = x_test.astype('float32')


X_train = X_train/255
x_validation = x_validation/255
x_test =x_test/255

from keras.utils import np_utils
Y_train = np_utils.to_categorical(Y_train,8)
y_validation =np_utils.to_categorical(y_validation,8)
y_test =np_utils.to_categorical(y_test,8)

while running tis i'm getting some error.

ValueError                                Traceback (most recent call last)
<ipython-input-30-fc799feec008> in <module>
----> 1 X_train = X_train.reshape((X_train.shape[0],256,256,1))
      2 x_validation = x_validation.reshape((x_validation.shape[0],256,256,1))
      3 x_test =x_test.reshape((x_test.shape[0],256,256,1))
      4 
      5 X_train = X_train.astype('float32')

ValueError: cannot reshape array of size 445513728 into shape (2266,256,256,1)

please help me out with this

1 Answer 1

0

If the output of print(X_train.shape) is (2266, 196608), then X_train.shape[0] is 2266.

If you then say

X_train = X_train.reshape((X_train.shape[0],256,256,1))

you are trying to reshape 2266 x 196608 (=445513728) into 2266 x 256 x 256 x 1 (=148504576) so you get the message

ValueError: cannot reshape array of size 445513728 into shape (2266,256,256,1)

One of those 256 values needs to be 768 to make that reshape work.

0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.