I am trying to replicate VGG16 model in keras, the following is my code:
model = Sequential()
model.add(ZeroPadding2D((1,1),input_shape=(3,224,224)))
model.add(C
Quoting an answer mentioned in github, you need to specify the dimension ordering:
Keras is a wrapper over Theano or Tensorflow libraries. Keras uses the setting variable image_dim_ordering
to decide if the input layer is Theano or Tensorflow format. This setting can be specified in 2 ways -
'tf'
or 'th'
in ~/.keras/keras.json
like so - image_dim_ordering: 'th'
. Note: this is a json file.image_dim_ordering
in your model like so: model.add(MaxPooling2D(pool_size=(2, 2), dim_ordering="th"))
Update: Apr 2020 Keras 2.2.5 link seems to have an updated API where dim_ordering
is changed to data_format
so:
keras.layers.MaxPooling2D(pool_size=(2, 2), strides=None, padding='valid', data_format='channels_first')
to get NCHW or use channels_last
to get NHWC
Appendix: image_dim_ordering
in 'th'
mode the channels dimension (the depth) is at index 1 (e.g. 3, 256, 256). In 'tf'
mode is it at index 3 (e.g. 256, 256, 3). Quoting @naoko from comments.