Expected Input_0 to have shape (3, 96, 96) but got array with shape (96, 96, 3)


#1

Hi,
I’m trying to download trained model using:
image
When running the downloaded code I get the following error:
ValueError: Error when checking input: expected Input_0 to have shape (3, 96, 96) but got array with shape (96, 96, 3)
Which is king of strange, as this is the code from the Studio without changes and I even try at the beginning to run it on the same data set that is used for the training, just to get results.
Any help will be appreciated.

Thanks,
Ilan


#2

It seems as you are using tensorflow(tf) dimension ordering instead of using default ordering.


#3

Thanks for the answer.
It is all DLS code. If something should be changed, let me know where should I change it.


#4

I found the problem, in the lines:

if K.image_dim_ordering() == ‘tf’:
print(‘in --> if K.image_dim_ordering() == tf:’)
test_data[i] = np.transpose(test_data[i], (0, 2, 3, 1))

it take the test_data[i] and change the way it order.
I changed it to:

if K.image_dim_ordering() == ‘tf’:
print(‘in --> if K.image_dim_ordering() == tf:’)
test_data[i] = np.transpose(test_data[i], (0, 1, 2, 3)) #(0, 2, 3, 1))

and I don’t get the error anymore, but I do get the following error:

/usr/lib/python3.4/site-packages/ipykernel_launcher.py:236: DeprecationWarning: imread is deprecated!
imread is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
Use imageio.imread instead.
/usr/lib/python3.4/site-packages/ipykernel_launcher.py:260: DeprecationWarning: imread is deprecated!
imread is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
Use imageio.imread instead.
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your InputLayer call to the Keras 2 API: InputLayer(batch_input_shape=[None, 3, ..., name="Input_0", sparse=False, dtype="float32")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(kernel_constraint=None, filters=256, strides=[1, 1], kernel_initializer="glorot_uniform", bias_regularizer=None, kernel_regularizer=None, kernel_size=(2, 2), padding="same", use_bias=True, bias_constraint=None, name="convolution2d_218328", activity_regularizer=None, data_format="channels_first", trainable=True, activation="relu")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(kernel_constraint=None, filters=256, strides=[1, 1], kernel_initializer="glorot_uniform", bias_regularizer=None, kernel_regularizer=None, kernel_size=(2, 2), padding="same", use_bias=True, bias_constraint=None, name="convolution2d_218329", activity_regularizer=None, data_format="channels_first", trainable=True, activation="linear")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your MaxPooling2D call to the Keras 2 API: MaxPooling2D(pool_size=[2, 2], name="maxpooling2d_91874", data_format="channels_first", trainable=True, strides=[2, 2], padding="valid")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(kernel_constraint=None, filters=128, strides=[1, 1], kernel_initializer="glorot_uniform", bias_regularizer=None, kernel_regularizer=None, kernel_size=(2, 2), padding="same", use_bias=True, bias_constraint=None, name="convolution2d_218330", activity_regularizer=None, data_format="channels_first", trainable=True, activation="relu")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(kernel_constraint=None, filters=128, strides=[1, 1], kernel_initializer="glorot_uniform", bias_regularizer=None, kernel_regularizer=None, kernel_size=(2, 2), padding="same", use_bias=True, bias_constraint=None, name="convolution2d_218331", activity_regularizer=None, data_format="channels_first", trainable=True, activation="linear")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your BatchNormalization call to the Keras 2 API: BatchNormalization(epsilon=0.001, name="batchnormalization_78248", momentum=0.99, beta_regularizer=None, trainable=True, axis=-1, gamma_regularizer=None)
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your MaxPooling2D call to the Keras 2 API: MaxPooling2D(pool_size=[2, 2], name="maxpooling2d_91875", data_format="channels_first", trainable=True, strides=[2, 2], padding="valid")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(kernel_constraint=None, filters=64, strides=[1, 1], kernel_initializer="glorot_uniform", bias_regularizer=None, kernel_regularizer=None, kernel_size=(2, 2), padding="same", use_bias=True, bias_constraint=None, name="convolution2d_218332", activity_regularizer=None, data_format="channels_first", trainable=True, activation="relu")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(kernel_constraint=None, filters=64, strides=[1, 1], kernel_initializer="glorot_uniform", bias_regularizer=None, kernel_regularizer=None, kernel_size=(2, 2), padding="same", use_bias=True, bias_constraint=None, name="convolution2d_218333", activity_regularizer=None, data_format="channels_first", trainable=True, activation="linear")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(kernel_constraint=None, filters=64, strides=[1, 1], kernel_initializer="glorot_uniform", bias_regularizer=None, kernel_regularizer=None, kernel_size=(2, 2), padding="same", use_bias=True, bias_constraint=None, name="convolution2d_218334", activity_regularizer=None, data_format="channels_first", trainable=True, activation="relu")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(kernel_constraint=None, filters=64, strides=[1, 1], kernel_initializer="glorot_uniform", bias_regularizer=None, kernel_regularizer=None, kernel_size=(2, 2), padding="same", use_bias=True, bias_constraint=None, name="convolution2d_218335", activity_regularizer=None, data_format="channels_first", trainable=True, activation="relu")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your MaxPooling2D call to the Keras 2 API: MaxPooling2D(pool_size=[2, 2], name="maxpooling2d_91876", data_format="channels_first", trainable=True, strides=[2, 2], padding="valid")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(kernel_constraint=None, filters=32, strides=[1, 1], kernel_initializer="glorot_uniform", bias_regularizer=None, kernel_regularizer=None, kernel_size=(2, 2), padding="same", use_bias=True, bias_constraint=None, name="convolution2d_218336", activity_regularizer=None, data_format="channels_first", trainable=True, activation="relu")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(kernel_constraint=None, filters=32, strides=[1, 1], kernel_initializer="glorot_uniform", bias_regularizer=None, kernel_regularizer=None, kernel_size=(2, 2), padding="same", use_bias=True, bias_constraint=None, name="convolution2d_218337", activity_regularizer=None, data_format="channels_first", trainable=True, activation="linear")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your BatchNormalization call to the Keras 2 API: BatchNormalization(epsilon=0.001, name="batchnormalization_78249", momentum=0.99, beta_regularizer=None, trainable=True, axis=-1, gamma_regularizer=None)
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(kernel_constraint=None, filters=32, strides=[1, 1], kernel_initializer="glorot_uniform", bias_regularizer=None, kernel_regularizer=None, kernel_size=(2, 2), padding="same", use_bias=True, bias_constraint=None, name="convolution2d_218338", activity_regularizer=None, data_format="channels_first", trainable=True, activation="relu")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(kernel_constraint=None, filters=32, strides=[1, 1], kernel_initializer="glorot_uniform", bias_regularizer=None, kernel_regularizer=None, kernel_size=(2, 2), padding="same", use_bias=True, bias_constraint=None, name="convolution2d_218339", activity_regularizer=None, data_format="channels_first", trainable=True, activation="relu")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your MaxPooling2D call to the Keras 2 API: MaxPooling2D(pool_size=[2, 2], name="maxpooling2d_91877", data_format="channels_first", trainable=True, strides=[2, 2], padding="valid")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(kernel_constraint=None, filters=32, strides=[1, 1], kernel_initializer="glorot_uniform", bias_regularizer=None, kernel_regularizer=None, kernel_size=(2, 2), padding="same", use_bias=True, bias_constraint=None, name="convolution2d_218340", activity_regularizer=None, data_format="channels_first", trainable=True, activation="relu")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(kernel_constraint=None, filters=32, strides=[1, 1], kernel_initializer="glorot_uniform", bias_regularizer=None, kernel_regularizer=None, kernel_size=(2, 2), padding="same", use_bias=True, bias_constraint=None, name="convolution2d_218341", activity_regularizer=None, data_format="channels_first", trainable=True, activation="linear")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(kernel_constraint=None, filters=32, strides=[1, 1], kernel_initializer="glorot_uniform", bias_regularizer=None, kernel_regularizer=None, kernel_size=(2, 2), padding="same", use_bias=True, bias_constraint=None, name="convolution2d_218342", activity_regularizer=None, data_format="channels_first", trainable=True, activation="relu")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Conv2D call to the Keras 2 API: Conv2D(kernel_constraint=None, filters=32, strides=[1, 1], kernel_initializer="glorot_uniform", bias_regularizer=None, kernel_regularizer=None, kernel_size=(2, 2), padding="same", use_bias=True, bias_constraint=None, name="convolution2d_218343", activity_regularizer=None, data_format="channels_first", trainable=True, activation="relu")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your MaxPooling2D call to the Keras 2 API: MaxPooling2D(pool_size=[2, 2], name="maxpooling2d_91878", data_format="channels_first", trainable=True, strides=[2, 2], padding="valid")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Dense call to the Keras 2 API: Dense(kernel_constraint=None, bias_constraint=None, name="dense_95912", bias_regularizer=None, kernel_initializer="glorot_uniform", units=2048, input_dim=288, kernel_regularizer=None, trainable=True, activation="linear", activity_regularizer=None, use_bias=True)
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Dense call to the Keras 2 API: Dense(kernel_constraint=None, bias_constraint=None, name="dense_95913", bias_regularizer=None, kernel_initializer="glorot_uniform", units=1024, input_dim=2048, kernel_regularizer=None, trainable=True, activation="linear", activity_regularizer=None, use_bias=True)
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your BatchNormalization call to the Keras 2 API: BatchNormalization(epsilon=0.001, name="batchnormalization_78250", momentum=0.99, beta_regularizer=None, trainable=True, axis=-1, gamma_regularizer=None)
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Dropout call to the Keras 2 API: Dropout(trainable=True, rate=0.4, name="dropout_44138")
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Dense call to the Keras 2 API: Dense(kernel_constraint=None, bias_constraint=None, name="dense_95914", bias_regularizer=None, kernel_initializer="glorot_uniform", units=1024, input_dim=1024, kernel_regularizer=None, trainable=True, activation="linear", activity_regularizer=None, use_bias=True)
return cls(**config)
/usr/lib64/python3.4/site-packages/keras/engine/base_layer.py:1109: UserWarning: Update your Dense call to the Keras 2 API: Dense(kernel_constraint=None, bias_constraint=None, name="dense_95915", bias_regularizer=None, kernel_initializer="glorot_uniform", units=3, input_dim=1024, kernel_regularizer=None, trainable=True, activation="softmax", activity_regularizer=None, use_bias=True)
return cls(**config)

Any help on this?


#5

Any solve for it? Im getting the same problem.

Update: Nevermind your solution worked thanks a lot!!


#6

I also fixed all your errors but I got another one:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “testOriginal.py”, line 254, in test_model
res = customPredict(test_data, config, modelFile)
File “testOriginal.py”, line 212, in customPredict
mod = load_model(modelFile)
File “C:\Users\Florian\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\engine\saving.py”, line 419, in load_model
model = _deserialize_model(f, custom_objects, compile)
File “C:\Users\Florian\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\engine\saving.py”, line 287, in _deserialize_model
K.batch_set_value(weight_value_tuples)
File “C:\Users\Florian\AppData\Local\Programs\Python\Python37\lib\site-packages\keras\backend\tensorflow_backend.py”, line 2465, in batch_set_value
assign_op = x.assign(assign_placeholder)
File “C:\Users\Florian\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\ops\variables.py”, line 1952, in assign
name=name)
File “C:\Users\Florian\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\ops\state_ops.py”, line 227, in assign
validate_shape=validate_shape)
File “C:\Users\Florian\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\ops\gen_state_ops.py”, line 69, in assign
use_locking=use_locking, name=name)
File “C:\Users\Florian\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\op_def_library.py”, line 788, in _apply_op_helper
op_def=op_def)
File “C:\Users\Florian\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\util\deprecation.py”, line 507, in new_func
return func(*args, **kwargs)
File “C:\Users\Florian\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\ops.py”, line 3616, in create_op
op_def=op_def)
File “C:\Users\Florian\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\ops.py”, line 2027, in init
control_input_ops)
File “C:\Users\Florian\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\framework\ops.py”, line 1867, in _create_c_op
raise ValueError(str(e))
ValueError: Shapes must be equal rank, but are 1 and 0 for ‘Assign’ (op: ‘Assign’) with input shapes: [1], [].


#7

Hi
you are getting this error because of the different configuration of keras API.
DLS uses old keras API whereas on your system you have the updated version installed.

Regards
Rajat


#8

Hi Rajat
Now I installed everything as in the tutorial video from DeepCognition! But I get still the same error!

Thank’s for your replies!
Florian