TAI*_*AOU 6 python artificial-intelligence machine-learning conv-neural-network keras
----> 6 from mrcnn.model 导入 MaskRCNN
/usr/local/lib/python3.7/dist-packages/mrcnn/model.py in () 253 254 --> 255 class ProposalLayer(KE.Layer): 256 """接收anchor分数并选择子集通过作为第二阶段的建议 257。过滤是基于锚点分数和
AttributeError: 模块 'keras.engine' 没有属性 'Layer'
小智 12
对于使用图层的行,例如ProposalLayer(KE.Layer)
而不是使用KE.Layerdo
import keras.layers as KL
Run Code Online (Sandbox Code Playgroud)
并替换所有KE实例KL
小智 11
我在 github 问题讨论中发现了这个,它对我有用。
您需要卸载那些:
pip uninstall keras -y
pip uninstall keras-nightly -y
pip uninstall keras-Preprocessing -y
pip uninstall keras-vis -y
pip uninstall tensorflow -y
pip uninstall h5py -y
Run Code Online (Sandbox Code Playgroud)
并强加这些版本:
pip install tensorflow==1.13.1
pip install keras==2.0.8
pip install h5py==2.10.0
Run Code Online (Sandbox Code Playgroud)
我在运行项目时遇到了这个问题。 https://github.com/matterport/Mask_RCNN
在文件model.py中,有一行
import keras.engine as KE
我把它改成
import keras.engine.topology as KE
问题就消失了。
安装tensorflow,版本如下
pip uninstall tensorflow -y
pip uninstall keras -y
pip install tensorflow==2.4.3
pip install keras==2.4.0
Run Code Online (Sandbox Code Playgroud)
经过上述操作后,会出现一些错误。您可以通过以下步骤解决它们。
@Error:[模块“tensorflow”没有属性 XXXXXXXX]
在model.py或 您的代码中,使用 解析某些 api tf.compat.v1,例如tf.compat.v1.Session或import tensorflow.compat.v1 as tf
@Error:[ValueError:尝试将“形状”转换为张量但失败。错误:不支持任何值。]
pip uninstall tensorflow -y
pip uninstall keras -y
pip install tensorflow==2.4.3
pip install keras==2.4.0
Run Code Online (Sandbox Code Playgroud)
将此 if-else 代码块替换为:
if s[1]==None:
mrcnn_bbox = KL.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x)
else:
mrcnn_bbox = KL.Reshape((s[1], num_classes, 4), name="mrcnn_bbox")(x)
Run Code Online (Sandbox Code Playgroud)
@Error:[ValueError:不支持任何值。]
indices = tf.stack([tf.range(probs.shape[0]), class_ids], axis=1)
Run Code Online (Sandbox Code Playgroud)
用。。。来代替
indices = tf.stack([tf.range(tf.shape(probs)[0]), class_ids], axis = 1)
Run Code Online (Sandbox Code Playgroud)
@Error:[AttributeError:模块'keras.engine. saving'没有属性'load_weights_from_hdf5_group_by_name']
mrcnn_bbox = KL.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x)
Run Code Online (Sandbox Code Playgroud)
用。。。来代替
from tensorflow.python.keras.saving import hdf5_format
Run Code Online (Sandbox Code Playgroud)
和
if s[1]==None:
mrcnn_bbox = KL.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x)
else:
mrcnn_bbox = KL.Reshape((s[1], num_classes, 4), name="mrcnn_bbox")(x)
Run Code Online (Sandbox Code Playgroud)
用。。。来代替
hdf5_format.load_weights_from_hdf5_group(f, layers)
hdf5_format.load_weights_from_hdf5_group_by_name(f, layers)
Run Code Online (Sandbox Code Playgroud)
参考:
小智 5
这严格来说是\xe2\x80\x99t 的重复项,但在这里找到了类似的问题: AttributeError: module 'keras.engine' has no attribute 'input_layer'
\n本质上,keras 的许多导入和属性错误都来自于 keras 根据您使用的是 CPU 还是 GPU 或 ASIC 来更改其导入。某些引擎类在每种情况下都不会导入\xe2\x80\x99。
\n相反,使用from keras.layers import Layer并使用该图层类来代替引擎中的图层类。