VGG16_avg.py modification for keras version 2+


#1

I use keras version =2.03 and the first time I tried to run VGG16_avg.py, I got the error saying:

"_obtain_input_shape() got an unexpected keyword argument 'dim_ordering"

This, apparently , is due to an API change in the newer version of keras. Easily solvable by replacing the parameter with data_format in vgg16_avg.py, as below:

# Determine proper input shape
input_shape = _obtain_input_shape(input_shape,
                                  default_size=224,
                                  min_size=48,
                                  data_format=K.image_data_format(),
                                  include_top=include_top)

Python 3 Upgrade Troubleshooting (Aug 2017 edition :))
(Anil Pandey) #2

if K.image_dim_ordering() == ‘th’:
data_format = "channels_first"
else:
data_format = “channels_last”


(Jason Carter) #3

On a related note… keras v2 also updated/renamed initialization

In utils2.py update:
``- from keras import initialization

  • from keras import initializers``

(Jeremy Weasley) #4

For keras’ latest version (2.0.8) the “include_top” should be “require_flatten”:
# Determine proper input shape
input_shape = _obtain_input_shape(input_shape,
default_size=224,
min_size=48,
data_format=K.image_data_format(),
require_flatten=include_top)


(Srikanth) #5

i changed to what you have said…but still showing the same error.


#6

same problem occurred to me, i downgraded keras and it worked

it seems that keras 2 has changed many syntaxes that used in the script