question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueError: Negative dimension size caused by subtracting 3 from 1

See original GitHub issue

First of all, great work with this project, Its been really helpful!

I’m a beginner at Python so I don’t know if there is something im doing wrong.

I’m running into a problem when trying to run the convolutional_neural_networks example in notebooks repository

When I try to run the following code:

model.add(Convolution2D(
n_filters, n_conv, n_conv,
border_mode='valid',
input_shape=(1, height, width)
)) 

I run into this error:

Traceback (most recent call last): File “/usr/local/lib/python3.5/site-packages/tensorflow/python/framework/common_shapes.py”, line 594, in call_cpp_shape_fn status) File “/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/contextlib.py”, line 66, in exit next(self.gen) File “/usr/local/lib/python3.5/site-packages/tensorflow/python/framework/errors.py”, line 463, in raise_exception_on_not_ok_status pywrap_tensorflow.TF_GetCode(status)) tensorflow.python.framework.errors.InvalidArgumentError: Negative dimension size caused by subtracting 3 from 1

cheers, Alberto.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
muneebablecommented, Mar 28, 2019

Just add this

from keras import backend as K
K.set_image_dim_ordering('th')
3reactions
mneunomnecommented, Dec 5, 2016

yeah I checked the keras ‘mnist_cnn.py’ file and and I was able to go through this error by inverting the parameters in input_shape from (height, width, 1) instead of (1, height, width). But later on when running:

model.fit(X_train,
          y_train,
          batch_size=batch_size,
          nb_epoch=n_epochs,
          validation_data=(X_test, y_test))

I get the following error :

Exception: Error when checking model input: expected convolution2d_input_2 to have shape (None, 28, 28, 1) but got array with shape (60000, 1, 28, 28)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Negative dimension size caused by subtracting 3 from 1 for ...
ValueError : Negative dimension size caused by subtracting 3 from 1 for 'Conv2D' (op: 'Conv2D') with input shapes: [?,1,28,28], [3,3,28,32]. ...
Read more >
Negative dimension size caused by subtracting 3 ... - GitHub
I got this error message when declaring the input layer in Keras. ValueError: Negative dimension size caused by subtracting 3 from 1 for...
Read more >
Error: Negative dimension size caused by subtracting 3 from 1
Here's the error: Negative dimension size caused by subtracting 3 from 1 for 'conv2d_8/convolution' (op: 'Conv2D') with input shapes: [?,1,1 ...
Read more >
ValueError: Negative dimension size caused by ... - iTecNote
Binary classification problem: I want to have One input layer(optional), One Conv1D layer then output layer of 1 neuron predicting either 1 or...
Read more >
Negative dimension size caused by subtracting 2 from 1 - Reddit
ValueError : Negative dimension size caused by subtracting 2 from 1 for '{{node max_pooling2d_4/MaxPool}} = MaxPool[T=DT_FLOAT, data_format="NHWC ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found