属性错误:模块'keras.utils'没有使用segmentation_models属性'get_file'

dgenwo3n  于 2022-11-13  发布在  其他
关注(0)|答案(3)|浏览(109)

我正在尝试使用分段模型,但无法修复此错误。我已搜索此特定模型,但无法找到答案。我正在使用pycharm,此错误与此特定代码行相关BACKBONE = 'resnet 34'

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

这也是第83个。我在文档中搜索,显然tensorflow keras等版本满足要求。我真的不知道该怎么做,因为我真的试图安装和卸载许多组合的一切,以使这段代码的工作。感谢大家的帮助和时间!下面有完整的错误,希望它可能会帮助你!

`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'
afdcj2ne

afdcj2ne1#

您可以尝试:

import segmentation_models as sm

sm.set_framework('tf.keras')

sm.framework()

在谷歌colab上为我工作!

ql3eal8s

ql3eal8s2#

这里提供的另一个答案对我不起作用。相反,升级keras对我起了作用:

pip install --upgrade keras
k5ifujac

k5ifujac3#

要解决此问题,请尝试直接导入模块EfficientNetB0,如以下代码所示:

import efficientnet.tfkeras as efn

相关问题