-
Notifications
You must be signed in to change notification settings - Fork 19.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keras MaxPooling2D gives ValueError: Negative dimension size caused by subtracting 2 from 1 for 'MaxPool_x' #3945
Comments
Hello, I think taht you need to specify the dimension ordering:
model.add(MaxPooling2D(pool_size=(2, 2), dim_ordering="th")) hope that helps 👍 |
thanks @cdalbergue That actually resolves the issue however I'm not sure why it's needed as we are using the Tensorflow backend - shouldn't the dim_ordering be 'tf' ? |
@burgalon It depends of the version of tensorflow that you are using. 0.10 would use "tf", 0.11 would use "th" Edit: or the opposite, can't really remember |
That's weired. It's th for the latest version of keras... is there any reason? behind it @cdalbergue ? |
In fact, this problem results from your initial input. |
Just add this: from keras import backend as K |
Your suggestion really helped me,arashmh! |
guys how am i supposed to set image dim ordering to theano while my backend is tensorflow? I made your suggested fix, and it's somehow working |
guys I'm lost I have tried everything mentioned here and on stackoverflow. My dataset is grayscale 17x17x1, 3 classes, and I'm using Alexnet architecture. This is output of x_train.shape & y_train.shape :
Explicitly I have used : |
This helped me thanks. |
|
Hi @sammilei how does this help. can u explain! |
This help me, Thanks very much |
in keras 2.2.5, I tried: |
there is no dim_ordering parameter when using tensorflow.keras this line will throw another error |
there is no parameter dim_ordering() when you're using functions from tensorflow.keras. The problem here has different reasons in keras and TF. In keras: change the input shape accoring to the backend framework in use or change the dim_ordering=(tf/th) In tensorflow: goto the the code line where error is raised and change the padding='valid' parameter to padding='same'.If the parameter doesn't exist then add as in the example below. model.add(MaxPooling2D((2,2), strides=(2,2), padding='same')) more info on the topic can be found here - https://www.tensorflow.org/api_docs/python/tf/keras/layers/MaxPool2D |
thank you |
ValueError: Negative dimension size caused by subtracting 2 from 1 for '{{node max_pooling2d_2/MaxPool}} = MaxPoolT=DT_FLOAT, data_format="NHWC", ksize=[1, 2, 2, 1], padding="VALID", strides=[1, 2, 2, 1]' with input shapes: [?,1,1,64]. Tried all of the above solutions but nothing has worked. Please help! CODE is below for reference: import os img_width, img_height = 150, 150 train_data_dir = '/home/jashshah999/Desktop/data/train/' datagen = ImageDataGenerator(rescale=1./255) train_generator = datagen.flow_from_directory( model = Sequential() model.add(Convolution2D(32, 3, 3)) model.add(Convolution2D(64, 3, 3)) model.add(Flatten()) model.compile(loss='binary_crossentropy', nb_epoch = 10 model.fit_generator( |
this worked for me... Thanks |
save my life |
thanks a lot , it helped me:)) |
For keras 2.0, it becomes:
See the link below: |
Please look into the following link.
http://stackoverflow.com/questions/39815518/keras-maxpooling2d-layer-gives-valueerror
I have been facing this issue on the following config Ubuntu 16.04, Keras, TensorFlow GPU and Cuda 7.5.
On my windows config with GPU enabled Theano there is no issue in executing the script.
What might be the reason for this?
The text was updated successfully, but these errors were encountered: