segmentation_models icon indicating copy to clipboard operation
segmentation_models copied to clipboard

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

Open JVedant opened this issue 3 years ago • 5 comments

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 ?

JVedant avatar Sep 08 '21 14:09 JVedant

Same problem here. Are you also using Google Colab?

ffreller avatar Sep 08 '21 17:09 ffreller

No, I'm using a local system

JVedant avatar Sep 08 '21 17:09 JVedant

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 avatar Sep 15 '21 17:09 alex-virodov

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.

alex-virodov avatar Sep 15 '21 17:09 alex-virodov

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!

syaxx0819 avatar Sep 19 '21 13:09 syaxx0819