Jeanne Chaverot
Jeanne Chaverot

Reputation: 157

AttributeError: module 'keras.utils' has no attribute 'get_file' using classification_models.keras

When I try to run the simple code snippet below on my computer or on Google Colab:

from classification_models.keras import Classifiers

ResNet18, preprocess_input = Classifiers.get('resnet18')
resnet = ResNet18((170, 170, 3), weights='imagenet', include_top=False)

I get the following error:

AttributeError                            Traceback (most recent call last)
<ipython-input-4-b208d68b42cf> in <module>()
      2 
      3 ResNet18, preprocess_input = Classifiers.get('resnet18')
----> 4 resnet = ResNet18((170, 170, 3), weights='imagenet', include_top=False)

3 frames
/usr/local/lib/python3.7/dist-packages/classification_models/weights.py in load_model_weights(model, model_name, dataset, `classes`, include_top, **kwargs)
     23                              ' as true, classes should be {}'.format(weights['classes']))
     24 
---> 25         weights_path = keras_utils.get_file(
     26             weights['name'],
     27             weights['url'],

AttributeError: module 'keras.utils' has no attribute 'get_file'

Any idea why? Thank you in advance!

Upvotes: 1

Views: 2751

Answers (1)

programandoconro
programandoconro

Reputation: 2729

It seems to be the latest issue of the package. Nevertheless, in this documentation it says that weights defaults to imagenet if you do not give any path to a file. Therefore you could try removing that parameter and it should work. Please try:

from classification_models.keras import Classifiers

ResNet18, preprocess_input = Classifiers.get('resnet18')
resnet = ResNet18((170, 170, 3), include_top=False)

Upvotes: 1

Related Questions