简体   繁体   English

AttributeError:模块'keras.utils'没有使用segmentation_models的属性'get_file'

[英]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 = 're.net34'我正在使用 pycharm 并且此错误链接到此特定代码行 BACKBONE = 're.net34'

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

which is also the 83rd.这也是第 83 个。 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!我在文档中搜索,显然 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'

You can try:你可以试试:

import segmentation_models as sm

sm.set_framework('tf.keras')

sm.framework()

Worked for me on google colab!在 google colab 上为我工作!

This solves the problem on my laptop.这解决了我笔记本电脑上的问题。

The other answer provided here didn't work for me.这里提供的另一个答案对我不起作用。 Instead, upgrading keras did the trick for me via:相反,升级 keras 通过以下方式对我有用:

pip install --upgrade keras

To solve this issue, try importing the module EfficientNetB0 directly, as the code below:为了解决这个问题,尝试直接导入模块EfficientNetB0,如下代码:

import efficientnet.tfkeras as efn

I had same problem but with vgg u.net model, This worked for me我遇到了同样的问题,但使用 vgg u.net model,这对我有用

!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或者在这里查看它是如何实现的https://gitee.com/sanyanjie/image-segmentation-keras

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError: 模块&#39;keras.utils&#39; 没有使用classification_models.keras 的属性&#39;get_file&#39; - AttributeError: module 'keras.utils' has no attribute 'get_file' using classification_models.keras AttributeError:模块“keras.utils”没有属性“get_file” - AttributeError: module 'keras.utils' has no attribute 'get_file' AttributeError:模块“keras.utils”没有属性“to_categorical” - AttributeError: module 'keras.utils' has no attribute 'to_categorical' AttributeError: 模块 &#39;keras.utils&#39; 没有属性 &#39;Sequence&#39; - AttributeError: module 'keras.utils' has no attribute 'Sequence' importefficientnet.keras as efn - AttributeError: module 'keras.utils' has no attribute 'generic_utils' - import efficientnet.keras as efn - AttributeError: module 'keras.utils' has no attribute 'generic_utils' AttributeError: 模块 'keras.utils' 没有属性 'plot_model' 但安装了 Keras 和 tensorflow - AttributeError: module 'keras.utils' has no attribute 'plot_model' but installed Keras and tensorflow AttributeError:类型对象“ h5py.h5r.Reference”在使用“从keras.utils导入HDF5Matrix”时没有属性“ __reduce_cython__” - AttributeError: type object 'h5py.h5r.Reference' has no attribute '__reduce_cython__' on using “from keras.utils import HDF5Matrix” AttributeError:模块'tensorflow.python.keras.utils.generic_utils'没有属性'populate_dict_with_module_objects' - AttributeError: module 'tensorflow.python.keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects' AttributeError:模块“keras.utils.generic_utils”没有属性“populate_dict_with_module_objects” - AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects' AttributeError: 模块 'tensorflow.keras.models' 没有属性 'experimental' - AttributeError: module 'tensorflow.keras.models' has no attribute 'experimental'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM