To use ResNeXt50, I wrote my code as the API documentation for Keras:
keras.applications.resnext.ResNeXt50(...)
But it reported errors:
AttributeError: module 'keras.applications' has no attribute 'resnext'
That’s weird. The code doesn’t work as documentation said.
So I checked the code of Keras-2.2.4 (the version in my computer), and noticed that this version of code use ‘keras_applications’ instead of ‘keras.applications’.
Then I changed my code:
keras_applications.resnext.ResNeXt50((input_tensor = pinp, include_top = False, weights = 'imagenet')
But it reported another error:
Using TensorFlow backend. Traceback (most recent call last): File "ktrain.py", line 292, inmain() File "ktrain.py", line 277, in main model, orig_model, branch_model, head_model = build_model(args) File "ktrain.py", line 210, in build_model branch_model = resnet_model(args, img_shape) File "ktrain.py", line 164, in resnet_model base_model = keras_applications.resnext.ResNeXt50(input_tensor = pinp, include_top = False, weights = 'imagenet') File "/usr/lib/python3.6/site-packages/keras_applications/resnet_common.py", line 555, in ResNeXt50 **kwargs) File "/usr/lib/python3.6/site-packages/keras_applications/resnet_common.py", line 348, in ResNet data_format=backend.image_data_format(), AttributeError: 'NoneType' object has no attribute 'image_data_format'
Witout choice, I had to check code of ‘/usr/lib/python3.6/site-packages/keras_applications/resnet_common.py’ too. Finally, I realise the ResNeXt50() function need three more arguments:
keras_applications.resnext.ResNeXt50(
input_tensor = pinp, include_top = False, weights = 'imagenet',
backend = keras.backend, layers = keras.layers, models = keras.models, utils = keras.utils)
Now the program could run ResNeXt50 model correctly. This github issue explained the detail: the ‘keras_applications’ could be used both for Keras and Tensorflow, so it needs to pass library details into model function.
I was aiming in that direction, but you saved me time. Thank you !
Can you tell me how did you find add the 3 more arguments,the code works.
I go to the source code, and didn’t find the 3 arguments,
From the code of resnet_common.py I found the function ‘ResNet()’ will call ‘get_submodules_from_kwargs()’ to get extra arguments.
The implementation of ‘get_submodules_from_kwargs()’ is here. Therefore I found the 3 more arguments.