AttributeError:module 'keras.engine.topology' has no attribute 'load_weights_from_hdf5_group_by_name

转载请注明转自:https://blog.youkuaiyun.com/c20081052/article/details/80745969
在windows下运行tensorflow-keras 版的mask-rcnn时遇到如题所示的错误。
声明我的机子是:win10 + 64位 + Anaconda3 + Python3.5

错误发生在运行Mask_RCNN-master\samples\中的demo.ipynb文件的如下行:



解决方案一:

网上资料说造成这个错误的原因是keras版本不对,在mask-rcnn仓库文件中的requirement.txt中提到要求安装的keras>=2.0.8

load_weights_from_hdf5_group_by_name只在keras2.0.8的版本中出现,不会出现在最新的keras版本中出现。我查看了下当前安装的keras版本,是2.2.0,按照建议,将其更改到2.0.8,操作如下——


先查看版本,用pip uninstall keras  卸载,在用pip install keras==2.0.8 安装指定版本。重新安装后再执行demo.ipynb那行代码,然后立马尝试运行Mask_RCNN-master\samples\中的demo.ipynb文件,问题没有解决啊!!!然后啥也没再继续,第二天打算尝试解决方案二,奇怪的是再次运行那个demo.ipynb的时候居然成功了~,什么情况?!

解决方案二:
这个问题在mask R-CNN的issue中有提到,由farzadzare提出:

分析的大致原因也是keras的版本问题,采取的解决方案就是用saving来取代代码中的topology,具体如下:

欢迎交流,我是ciky-Y

参考:
https://blog.youkuaiyun.com/u014513323/article/details/80659352
https://github.com/matterport/Mask_RCNN/issues/694

源代码import jieba import numpy as np import matplotlib.pyplot as plt from keras.models import Model from keras.layers import Input, Embedding, Bidirectional, LSTM, Dense, Dropout from keras.preprocessing.text import Tokenizer from keras.preprocessing.sequence import pad_sequences from keras.utils import to_categorical from keras import backend as K from tensorflow import kerasimport warnings from keras.src.api_export import keras_export from keras.src.utils.module_utils import dmtree from keras.src.utils.module_utils import optree if optree.available: from keras.src.tree import optree_impl as tree_impl elif dmtree.available: from keras.src.tree import dmtree_impl as tree_impl else: raise ImportError( "To use Keras, you need to have `optree` installed. " "Install it via `pip install optree`" ) def register_tree_node_class(cls): return tree_impl.register_tree_node_class(cls) @keras_export("keras.tree.MAP_TO_NONE") class MAP_TO_NONE: """Special value for use with `traverse()`.""" pass @keras_export("keras.tree.is_nested") def is_nested(structure): """Checks if a given structure is nested. Examples: >>> keras.tree.is_nested(42) False >>> keras.tree.is_nested({"foo": 42}) True Args: structure: A structure to check. Returns: `True` if a given structure is nested, i.e. is a sequence, a mapping, or a namedtuple, and `False` otherwise. """ return tree_impl.is_nested(structure) @keras_export("keras.tree.traverse") def traverse(func, structure, top_down=True): """Traverses the given nested structure, applying the given function. The traversal is depth-first. If `top_down` is True (default), parents are returned before their children (giving the option to avoid traversing into a sub-tree). Examples: >>> v = [] >>> keras.tree.traverse(v.append, [(1, 2), [3], {"a": 4}], top_down=True) [(1, 2), [3], {'a': 4}] >>> v [[(1
03-14
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值