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?