deep learning - ValueError: Error when checking input: expected conv1d_1_input to have 3 dimensions, but got array with shape (500000, 3253)? -
i want train data convolution neural network, have reshaped data: parameters have used:
'x_train.shape'=(500000, 3253) 'y_train.shape', (500000,) 'y_test.shape', (20000,) 'y_train[0]', 97 'y_test[0]', 99 'y_train.shape', (500000, 256) 'y_test.shape', (20000, 256) this how define model architecture:
# 3. define model architecture model = sequential() model.add(conv1d(64, 8, strides=1, padding='valid', dilation_rate=1, activation=none, use_bias=true, kernel_initializer='glorot_uniform', bias_initializer='zeros', kernel_regularizer=none, bias_regularizer=none, activity_regularizer=none, kernel_constraint=none, bias_constraint=none, input_shape=x_train.shape)) print('***done***') ###### input_traces=n_features ###### input_shape=(batch_size, trace_lenght,num_of_channels) model.add(maxpooling1d(pool_size=2,strides=none, padding='valid',input_shape=x_train.shape)) print('***done***') model.add(flatten()) print('***done***') model.add(dropout(0.5)) print('***done***') #print(model.summary()) model.add(dense(1, activation='relu')) print('***done***') # # # 4. compile model model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy']) # # # # # 5. fit model on training data model.fit(x_train, y_train, batch_size=100, epochs=500,verbose=2) the result is:
........ ***done*** ***done*** traceback (most recent call last): file "cnn_based_attack.py", line 128, in <module> model.fit(x_train, y_train, batch_size=100, epochs=500,verbose=2) file "/home/meriem/.local/lib/python2.7/site-packages/keras/models.py", line 853, in fit initial_epoch=initial_epoch) file "/home/meriem/.local/lib/python2.7/site-packages/keras/engine/training.py", line 1424, in fit batch_size=batch_size) file "/home/meriem/.local/lib/python2.7/site-packages/keras/engine/training.py", line 1300, in _standardize_user_data exception_prefix='input') file "/home/meriem/.local/lib/python2.7/site-packages/keras/engine/training.py", line 127, in _standardize_input_data str(array.shape)) valueerror: error when checking input: expected conv1d_1_input have 3 dimensions, got array shape (500000, 3253) the error have in reshaping data , in step 5:
# # # # # 5. fit model on training data model.fit(x_train, y_train, batch_size=100, epochs=500,verbose=2) how resolve problem?
the input shape wrong, should input_shape = (1, 3253) theano or (3253, 1) tensorflow. input shape doesn't include number of samples.
then need reshape data include channels axis:
x_train = x_train.reshape((500000, 1, 3253)) or move channels dimension end if use tensorflow. after these changes should work.
Comments
Post a Comment