ml4a / ml4a

A python library and collection of notebooks for making art with machine learning.

Home Page:https://ml4a.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ValueError: Negative dimension size caused by subtracting 3 from 1

mneunomne opened this issue · comments

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.

i think this might be related to changes to the API in the latest release of keras, cc @frnsys

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)

I can't test this at the moment, but you may also need to switch around the values for the line:

model.add(Convolution2D(n_filters, n_conv, n_conv))

to be:

model.add(Convolution2D(n_conv, n_conv, n_filters))

Thanks for the quick response,

i made this change and now gives another error: ValueError: Negative dimension size caused by subtracting 32 from 26

ps.: im testing it for study so there is no hurry

cheers!

Just add this

from keras import backend as K
K.set_image_dim_ordering('th')

this has actually been fixed recently, was a mismatch in the guide and most recent version of keras. if you have the latest versions of keras and ml4a-guides, the image ordering flag should no longer be necessary.