Python 用Keras屏蔽RCNN:试图转换';形状';一个张量,失败了。错误:不支持任何值

Python 用Keras屏蔽RCNN:试图转换';形状';一个张量,失败了。错误:不支持任何值,python,tensorflow,keras,Python,Tensorflow,Keras,我正在尝试以推断模式运行。它基本上是在运行这个代码 但当我运行它时,在创建模型时会出现以下错误: 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

我正在尝试以推断模式运行。它基本上是在运行这个代码

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

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

这实际上是maskRCNN回购协议的复制/粘贴。最后一行是发生错误的地方。

我得到了相同的错误,直到:

  • 使用
    keras.\uuuuu版本=2.2.4
  • Tensorflow gpu版本==1.12.0
  • Skimage.\uuuuu版本=0.14.2
  • 不确定rest版本的错误是什么,可能是某些东西不适合
    pycocotools

    optimizer = keras.optimizers.SGD(
                lr=learning_rate, momentum=momentum,
                clipnorm=self.config.GRADIENT_CLIP_NORM) #this portion.
    

    我做了这份官方文件中建议的所有修改

    这些基本上是model.py脚本中使用tf.keras函数而不是纯keras函数的更改

    以下是(更新TF 2.4.1-2021年5月)


    你可以在它里面找到我的colab样本,或者通过这个

    如果我们能看到你的代码会有所帮助。实际上,问题似乎是使用了Tensorflow中嵌入的Keras。当分别使用Tensorflow 1.13和Keras 2.2.4时,其工作正常。不知道为什么。是的。我也遇到了同样的情况…只是重新安装了它们,它们工作了!!是的,Tensorflow中嵌入的KERA与独立的KERA之间存在一些差异。现在建议使用Tensorflow中嵌入的Keras,而不是简单的Keras,我真的希望存储库将更新以包含必要的更改。正确,如果我们朝实际生产力发展,tf提供了比普通Keras更多的选项。至少我喜欢在做事情的时候有更多的选择
    optimizer = keras.optimizers.SGD(
                lr=learning_rate, momentum=momentum,
                clipnorm=self.config.GRADIENT_CLIP_NORM) #this portion.