python - 带有 Keras 的 Mask-RCNN:尝试将“形状”转换为张量但失败了。错误:不支持无值
问题描述
我正在尝试在推理模式下运行Mask_RCNN 的 Keras 实现。基本上就是运行这段代码demo.ipynb
但是当我运行它时,我在创建模型时收到以下错误:
ValueError: Tried to convert 'shape' to a tensor and failed. Error: None values not supported.
这是堆栈跟踪:
Traceback (most recent call last):
File "/snap/pycharm-community/128/helpers/pydev/pydevd.py", line 1758, in <module>
main()
File "/snap/pycharm-community/128/helpers/pydev/pydevd.py", line 1752, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/snap/pycharm-community/128/helpers/pydev/pydevd.py", line 1147, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/snap/pycharm-community/128/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "[PATH/TO/Mask_RCNN/]/Own_code/Test.py", line 44, in <module>
model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config)
File "[PATH/TO/Mask_RCNN/]/Mask_RCNN/mrcnn/model.py", line 1833, in __init__
self.keras_model = self.build(mode=mode, config=config)
File "[PATH/TO/Mask_RCNN/]/Mask_RCNN/mrcnn/model.py", line 2035, in build
fc_layers_size=config.FPN_CLASSIF_FC_LAYERS_SIZE)
File "[PATH/TO/Mask_RCNN/]/Mask_RCNN/mrcnn/model.py", line 947, in fpn_classifier_graph
mrcnn_bbox = KL.Reshape((s[1], num_classes, 4), name="mrcnn_bbox")(x)
File "[PATH/TO/venv/]lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 554, in __call__
outputs = self.call(inputs, *args, **kwargs)
File "[PATH/TO/venv/]lib/python3.6/site-packages/tensorflow/python/keras/layers/core.py", line 439, in call
(array_ops.shape(inputs)[0],) + self.target_shape)
File "[PATH/TO/venv/]lib/python3.6/site-packages/tensorflow/python/ops/gen_array_ops.py", line 7179, in reshape
"Reshape", tensor=tensor, shape=shape, name=name)
File "[PATH/TO/venv/]lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 529, in _apply_op_helper
(input_name, err))
看起来我的问题与此处描述的相同,但没有真正的答案。
备注:
- 我正在使用 Python 3.6 和 Tensorflow 1.13.1 运行它
- 我已经编辑了 Keras 导入以使用嵌入在 Tensorflow 中的 Keras 版本
- 我运行出现此错误的代码对应于演示笔记本的前 3 个块。
编辑
这是我正在运行的代码:
# Root directory of the project
ROOT_DIR = os.path.abspath("../")
# Import Mask RCNN
sys.path.append(ROOT_DIR) # To find local version of the library
# Import COCO config
sys.path.append(os.path.join(ROOT_DIR, "samples/coco/")) # To find local version
# Directory to save logs and trained model
MODEL_DIR = os.path.join(ROOT_DIR, "logs")
# Local path to trained weights file
COCO_MODEL_PATH = os.path.join(ROOT_DIR, "mask_rcnn_coco.h5")
# Download COCO trained weights from Releases if needed
if not os.path.exists(COCO_MODEL_PATH):
utils.download_trained_weights(COCO_MODEL_PATH)
# Directory of images to run detection on
IMAGE_DIR = os.path.join(ROOT_DIR, "images")
class InferenceConfig(coco.CocoConfig):
# Set batch size to 1 since we'll be running inference on
# one image at a time. Batch size = GPU_COUNT * IMAGES_PER_GPU
GPU_COUNT = 1
IMAGES_PER_GPU = 1
config = InferenceConfig()
# Create model object in inference mode.
model = modellib.MaskRCNN(mode="inference", model_dir=MODEL_DIR, config=config)
这实际上是来自 maskRCNN 存储库的demo.ipynb的复制/粘贴。最后一行是发生错误的地方。
解决方案
我得到了同样的错误,直到:
- 使用
keras.__version__ == 2.2.4
Tensorflow-gpu version == 1.12.0
Skimage.__version__ == 0.14.2
不确定其他版本的错误是什么,可能不适合pycocotools
或
optimizer = keras.optimizers.SGD(
lr=learning_rate, momentum=momentum,
clipnorm=self.config.GRADIENT_CLIP_NORM) #this portion.
推荐阅读
- wildfly - Wildfly 集群设置问题
- api - Kotlin - 设置缩放级别谷歌地图 Android Studio
- python - 如何使主题标签可点击并在 Django 的帖子中显示?
- python - 如何在不使用 sum 函数的情况下获得平均值
- javascript - Undefined 不是 React native 的对象 - 但之后会显示数据
- arrays - 从 Google 表格中的表格中删除一些列
- java - 在 Fragment 和 Activity 之间链接天气数据连接
- jupyter - Windows 10 更新:是什么导致我的分层建模代码运行缓慢而痛苦?
- powershell - PowerShell PGP 加密挂起
- kubernetes - 什么是 kubernete pod 中的“i/o 超时”问题?