qubvel / segmentation_models

Segmentation models with pretrained backbones. Keras and TensorFlow Keras.
MIT License
4.67k stars 1.03k forks source link

Module 'keras.utils' has no attribute 'get_file' #493

Open JVedant opened 2 years ago

JVedant commented 2 years ago

Hi, when I'm trying to load the weights of imagenet in any model it's showing me an error that says "module 'keras.utils' has no attribute 'get_file'.

I also tried sm.set_framework("tf.keras") but it's throwing an error that says there is no method named set_framework in segmentation_model.

what can be done to solve this ?

ffreller commented 2 years ago

Same problem here. Are you also using Google Colab?

JVedant commented 2 years ago

No, I'm using a local system

alex-virodov commented 2 years ago

Hello. I suspect you are using the latest tensorflow (my tf.__version__ is 2.6.0 and I have this issue). This fixes it for me:

import os
os.environ['SM_FRAMEWORK'] = 'tf.keras'

import segmentation_models as sm

Then it should print: Segmentation Models: using 'tf.keras' framework

Hope that helps.

alex-virodov commented 2 years ago

Looking further, it seems the sm.set_framework('tf.keras') does work for me:

import os
# os.environ['SM_FRAMEWORK'] = 'tf.keras'
import segmentation_models as sm

print('sm.version=' + sm.__version__)
sm.set_framework('tf.keras')

model = sm.Unet('efficientnetb0', classes=1, input_shape=(128, 128, 3),
                decoder_filters=(512, 256, 128, 64, 32), activation='sigmoid')

output:

Segmentation Models: using `keras` framework.
sm.version=1.0.1

Maybe a version mismatch or import issue? Again, hope this helps as a comparison point.

syaxx0819 commented 2 years ago

Looking further, it seems the sm.set_framework('tf.keras') does work for me:

import os
# os.environ['SM_FRAMEWORK'] = 'tf.keras'
import segmentation_models as sm

print('sm.version=' + sm.__version__)
sm.set_framework('tf.keras')

model = sm.Unet('efficientnetb0', classes=1, input_shape=(128, 128, 3),
                decoder_filters=(512, 256, 128, 64, 32), activation='sigmoid')

output:

Segmentation Models: using `keras` framework.
sm.version=1.0.1

Maybe a version mismatch or import issue? Again, hope this helps as a comparison point.

OHHHHHHHHHHHHHHHHHHHHH, it does works for me .thank you very much !great!