0

Val and test data shape:

x_train = train_data.reshape(train_data.shape[0], train_data.shape[1], train_data.shape[2], INPUT_DIMENSION)
#x_t =x_train = train_data.reshape(train_data.shape[0], train_data.shape[1], train_data.shape[2])
x_test_all = test_data.reshape(test_data.shape[0], test_data.shape[1], test_data.shape[2], INPUT_DIMENSION)

x_val = x_test_all[-VAL_SIZE:]
y_val = y_test[-VAL_SIZE:]

x_test = x_test_all[:-VAL_SIZE]
y_test = y_test[:-VAL_SIZE]


history_fdssc = model_fdssc.fit(
        [x_train.reshape(x_train.shape[0], x_train.shape[1], x_train.shape[2], x_train.shape[3], 1), 
         x_train.reshape(x_train.shape[0], x_train.shape[1], x_train.shape[2], x_train.shape[3])], [y_train, y_train, y_train],
        validation_data=(x_val.reshape(x_val.shape[0], x_val.shape[1], x_val.shape[2], x_val.shape[3], 1), y_val),
        batch_size=batch_size, epochs=nb_epoch, shuffle=True,
        callbacks=[early_Stopping, save_Best_Model, reduce_LR_On_Plateau, history, tensor_board])

When I run the program I am getting the following error:

Please input the name of Dataset(IN, UP, KSC or SS):KSC
(512, 614, 176)
The class numbers of the HSI data is: 13
-----Importing Setting Parameters-----
-----Starting the  1 Iteration-----
Train size:  1048
Test size:  4163
Validation size:  524

-----Selecting Small Pieces from the Original Cube Data-----

Traceback (most recent call last): File "hyb.py", line 189, in x_t =x_train = train_data.reshape(train_data.shape[0], train_data.shape[1], train_data.shape[2]) ValueError: cannot reshape array of size 14940288 into shape (1048,9,9)

1 Answer 1

0

The error is originating from the first line because the total size of the array is not divisible by given reshaping parameters. Here is a toy example::

x_train = train_data.reshape(train_data.shape[0], train_data.shape[1], train_data.shape[2], INPUT_DIMENSION)
>>> x = np.arange(14940288)
>>> x.reshape(1049,9,9)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: cannot reshape array of size 14940288 into shape (1049,9,9)

Here is what you should try. Also, notice that you are not providing the variable INPUT_DIMENSION:

>>> x.reshape(-1,9,9).shape  #-1 takes the whole length
(184448, 9, 9)
>>> INPUT_DIMENSION = 16 
>>> x.reshape(-1,9,9,INPUT_DIMENSION).shape
(11528, 9, 9, 16)

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.