Reputation: 111
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'
Upvotes: 11
Views: 17786
Reputation: 11
If you are using Google Colab, I recommend running:
import os
import time
os.environ['SM_FRAMEWORK'] = 'tf.keras'
time.sleep(3)
import semantic_model as sm
or:
os.environ['SM_FRAMEWORK'] # and import statements on seperate cells
it may be there is someprocess with setting of environ variable and working i dont know how it works but it works
Upvotes: 0
Reputation: 1873
I had same problem but with vgg u-net model , This worked for me
!apt-get install -y libsm6 libxext6 libxrender-dev
!pip install opencv-python
!pip install git+https://github.com/divamgupta/image-segmentation-keras
from keras_segmentation.models.unet import vgg_unet
or check here how it's implemented https://gitee.com/sanyanjie/image-segmentation-keras
Upvotes: 0
Reputation: 1
To solve this issue, try importing the module EfficientNetB0 directly, as the code below:
import efficientnet.tfkeras as efn
Upvotes: 0
Reputation: 3700
The other answer provided here didn't work for me. Instead, upgrading keras did the trick for me via:
pip install --upgrade keras
Upvotes: -1
Reputation: 230
You can try:
import segmentation_models as sm
sm.set_framework('tf.keras')
sm.framework()
Worked for me on google colab!
Upvotes: 23