📌  相关文章
📜  ValueError:试图将“形状”转换为张量并失败.错误:不支持无值. - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:14.537000             🧑  作者: Mango

代码示例1
To solve this for the mask RCNN
The solution I found and worked for me was from "mayurmahurkar commented on Dec 8, 2020"
PS: some of the functions lines are with slightly different names but they should be there in the model.py file
The following steps worked for me:

1. Upgrade the scripts by using the following line on the root folder:

tf_upgrade_v2 --intree Mask_RCNN --inplace --reportfile report.txt

This will automatically update the existing code to TF2. You will also get a list of changes made in report.txt

2. Replace the following line:

mrcnn_bbox = layers.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x)
with this this if-else code block:

if s[1]==None:
  mrcnn_bbox = layers.Reshape((-1, num_classes, 4), name="mrcnn_bbox")(x)
 else:
  mrcnn_bbox = layers.Reshape((s[1], num_classes, 4), name="mrcnn_bbox")(x)

3. Change the following line:

indices = tf.stack([tf.range(probs.shape[0]), class_ids], axis=1)
with this line:

indices = tf.stack([tf.range(tf.shape(probs)[0]), class_ids], axis = 1)

4. Now, you need to replace:

from keras import saving
with:

from tensorflow.python.keras import saving
then you will also want to replace the lines in both if and else block:

saving.load_weights_from_hdf5_group(f, layers)
and so on with the follwoing lines, inside if and else block respectively:

saving.hdf5_format.load_weights_from_hdf5_group_by_name(f, layers)

saving.hdf5_format.load_weights_from_hdf5_group(f, layers)

Thanks to: @deluongo, @Trotts, @nielsuit227, @ibrahimLearning