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

I'm trying to use segmentation models but I can't fix this error. I've searched for this particular one but couldn't find an answer. I'm using pycharm and this error is linked to this specific line of code BACKBONE = 'resnet34'

model1 = sm.Unet(BACKBONE, weights=None,
                 encoder_weights='imagenet',
                 classes=num_classes,
                 activation='softmax',
                 decoder_block_type = 'upsampling') 

which is also the 83rd. I searched in the documentation and apparently the versions of tensorflow keras etc satisfy the requirements.I really don't know what to do given the fact that I really tried to install and uninstall everything in many combinations in order to get this piece of code to work.Thank you all for your help and time! Below there's the complete error, hoping it might help you!

    `Traceback (most recent call last):
      File "C:\Users\Giulia\PycharmProjects\multiclass_new\main.py", line 83, in <module>
        model1 = sm.Unet('resnet34', weights=None,
      File "C:\Users\Giulia\PycharmProjects\multiclass_new\venv\lib\site- 
   packages\segmentation_models\__init__.py", line 34, in wrapper
        return func(*args, **kwargs)
      File "C:\Users\Giulia\PycharmProjects\multiclass_new\venv\lib\site- 
   packages\segmentation_models\models\unet.py", line 221, in Unet
        backbone = Backbones.get_backbone(
      File "C:\Users\Giulia\PycharmProjects\multiclass_new\venv\lib\site- 
   packages\segmentation_models\backbones\backbones_factory.py", line 103, in get_backbone
        model = model_fn(*args, **kwargs)
      File "C:\Users\Giulia\PycharmProjects\multiclass_new\venv\lib\site- 
   packages\classification_models\models_factory.py", line 78, in wrapper
        return func(*args, **new_kwargs)
      File "C:\Users\Giulia\PycharmProjects\multiclass_new\venv\lib\site- 
   packages\classification_models\models\resnet.py", line 314, in ResNet34
        return ResNet(
      File "C:\Users\Giulia\PycharmProjects\multiclass_new\venv\lib\site- 
   packages\classification_models\models\resnet.py", line 280, in ResNet
        load_model_weights(model, model_params.model_name,
      File "C:\Users\Giulia\PycharmProjects\multiclass_new\venv\lib\site- 
   packages\classification_models\weights.py", line 25, in load_model_weights
        weights_path = keras_utils.get_file(
    AttributeError: module 'keras.utils' has no attribute 'get_file'

Solution 1:

You can try:

import segmentation_models as sm

sm.set_framework('tf.keras')

sm.framework()

Worked for me on google colab!