I got this error message when declaring the input layer in Keras.
ValueError: Negative dimension size caused by subtracting 3 from 1 for 'conv2d_2/convolution' (op: 'Conv2D') with input shapes: [?,1,28,28], [3,3,28,32].
My code is like this
model.add(Convolution2D(32, 3, 3, activation='relu', input_shape=(1,28,28)))
Sample application: https://github.com/IntellijSys/tensorflow/blob/master/Keras.ipynb
Please advice. Thank you.
@datomnurdin , that link fixed the same error I have. My line of code is (note the data_format arg):
model.add(Convolution2D(32, (3, 3), activation='relu', input_shape=(1,28,28), data_format='channels_first'))
It is doesn't work for me..
@warpdriv
Your code worked for me :)
model.add(Convolution2D(32, (3, 3), activation='relu', input_shape=(1,28,28), data_format='channels_first'))
my query is also somewhat related to this my training dataset Bx_train =(39998,20) size,and Fx_train= (39998,20) size,
please do the needful it gives error
"Error when checking input: expected conv2d_36_input to have 4 dimensions, but got array with shape (39998, 20)".
Please do the needful
model = models.Sequential()
model.add(convolutional.Convolution2D(64, 3, 3, border_mode='same', input_shape=(3, 256, 256), activation='relu'))
model.add(pooling.MaxPooling2D(pool_size=(2, 2), border_mode='same'))
model.add(convolutional.Convolution2D(20, 3, 3, activation='relu', border_mode='same'))
model.add(pooling.MaxPooling2D(pool_size=(2, 2), border_mode='same'))
model.add(convolutional.Convolution2D(64, 3, 3, activation='relu', border_mode='same'))
model.add(pooling.MaxPooling2D(pool_size=(2, 2), border_mode='same'))
model.add(core.Flatten())
model.add(core.Dense(500, activation='relu'))
model.add(core.Dropout(.5))
model.add(core.Dense(100, activation='relu'))
model.add(core.Dropout(.25))
model.add(core.Dense(20, activation='relu'))
model.add(core.Dense(1))
model.compile(loss='mean_squared_error', optimizer=sgd)
model.fit(Bx_train, Fx_train, batch_size=1, epochs=10)
@datomnurdin , that link fixed the same error I have. My line of code is (note the data_format arg):
model.add(Convolution2D(32, (3, 3), activation='relu', input_shape=(1,28,28), data_format='channels_first'))
it solved my problem, thank you :)
I am getting this error
train.py:227: UserWarning: Update your
Conv2D
call to the Keras 2 API:Conv2D(32, (3, 3), strides=(1, 1), padding="valid", kernel_initializer="orthogonal")
x = Convolution2D(n_filters, kH, kW, subsample=(sH, sW),border_mode=border_mode,
init=init_conv)(x)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Negative dimension size caused by
subtracting 3 from 1 for 'conv2d_1/convolution' (op: 'Conv2D') with input shapes: [?,1,32,32],
[3,3,32,32].
Anyone Help me please
Sir @vamsitharun, you can solve this isse by providing paddind parameter as suggested below -
model.add(Conv2D(32, (3,3), activation='relu', padding='same',input_shape=(1,1,6), data_format='channels_first'))
You can fix this problem throughout the entire CNN network by setting the data_format='NHWC'
from within your arg_scope
Despite the changing of data format to be "data_format='channels_first'" but I still have this issue:
"InvalidArgumentError: Default MaxPoolingOp only supports NHWC on device type CPU
[[{{node max_pooling2d_2/MaxPool}}]]"
any other solution?
Most helpful comment
@datomnurdin , that link fixed the same error I have. My line of code is (note the data_format arg):
model.add(Convolution2D(32, (3, 3), activation='relu', input_shape=(1,28,28), data_format='channels_first'))