Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras input shape ValueError

I have a problem and at the same time a question. I want to make an image classifier with Keras using Theano as Backend and a Sequential model.

>>> keras.__version__
'2.0.1'  
>>> theano.__version__
'0.9.0'

My input shape: INPUT_SHAPE = (3, 28, 28) #depth, size, size

Let's come to my problem. If I run my script at Windows 7 32 Bit, it gives me the error below out:

ValueError: ('The specified size contains a dimension with value <= 0', (-1024, 512))

If run it with the the input shape: INPUT_SHAPE = (28, 28, 3) #size, size, depth
It gives me out this error below:

ValueError: Error when checking model input: expected conv2d_1_input to have shape (None, 48, 48, 3) but got array with shape (1000, 3, 48, 48)

If I run the code on Elementary OS 64 Bit, it runs without any problems (INPUT_SHAPE = (3, 28, 28)).

My keras.json file for windows is:

{
  "backend": "theano",
  "epsilon": 1e-07,
  "floatx": "float32",
  "image_dim_ordering": "tf"
}

So, my question is: Is there such a big difference between different Operating Systems or where is my mistake? Just to remind, I used exactly the same code for both systems.

like image 291
Dragonblf Avatar asked Nov 30 '22 09:11

Dragonblf


2 Answers

If your problem is not solved yet try using: from keras import backend as K K.set_image_dim_ordering('th') This would work good if you wish to use theano backend and have to use channels first configuration for image dimension ordering.

like image 71
Aniket Bhatnagar Avatar answered Dec 05 '22 03:12

Aniket Bhatnagar


The problem you are having has to do with the expected dimension ordering.

  • Tensorflow ordering (tf): Shapes are expected to be (size_lines,size_columns,channel)
  • Theano ordering (th): Shapes are expected to be (channel,size_lines,size_columns)

If you change the ordering line in the keras.json file to "image_dim_ordering": "th" it should work. (i'd bet that's what's in your Elementary OS keras.json).

like image 35
maz Avatar answered Dec 05 '22 02:12

maz