带Keras的Mask-RCNN:试图将“形状”转换为张量,但失败了。错误:不支持任何值

时间:2019-05-24 09:04:23

标签: python tensorflow keras

我正在尝试在推断模式下运行Keras implemention of Mask_RCNN。基本上是运行此代码demo.ipynb

但是当我运行它时,在创建模型时出现以下错误:

ValueError: Tried to convert 'shape' to a tensor and failed. Error: None values not supported.

这是stacktrace:

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))

看来我的问题与here中所述的问题相同,但没有真正的答案。

注意:

  • 我正在使用Python 3.6和Tensorflow 1.13.1运行它
  • 我已编辑Keras导入以使用Tensorflow中嵌入的Keras版本
  • 我运行的有此错误的代码对应于演示笔记本的前3个块。

2 个答案:

答案 0 :(得分:1)

我遇到了同样的错误,直到:

  1. 使用keras.__version__ == 2.2.4
  2. Tensorflow-gpu version == 1.12.0
  3. Skimage.__version__ == 0.14.2

不确定其余版本有什么错误,可能是pycocotools

不适合的地方
optimizer = keras.optimizers.SGD(
            lr=learning_rate, momentum=momentum,
            clipnorm=self.config.GRADIENT_CLIP_NORM) #this portion.

答案 1 :(得分:1)

我做了这个官方issue thread中推荐的所有更改。

这些基本上是在 model.py 脚本中进行的更改,以使用 tf.keras 函数而不是纯 keras 函数。

这是 my working fork(针对 TF 2.4.1 更新 - 2021 年 5 月)。

您可以在其中或通过此 link

找到我的 colab 样本