亲测:在Tensorflow2.3的环境下,网上的办法全部无用,经查官方文档后修改如下:
有Tensorflow2.3兼容性问题的Mask RCNN的github项目:
https://github.com/matterport/Mask_RCNN
报错信息:
ValueError: The following Variables were created within a Lambda layer (anchors) but are not tracked by said layer: <tf.Variable ‘anchors/Variable:0’ shape=(1, 261888, 4) dtype=float32> The layer cannot safely ensure proper Variable reuse across multiple calls, and consquently this behavior is disallowed for safety. Lambda layers are not well suited to stateful computation; instead, writing a subclassed Layer is the recommend way to define layers with Variables.
问题原因:
从Tensorflow2.3开始,由于安全性原因,官方不推荐使用Lambda layer,需要使用subclass(Layer子类)方式实现。
将:
anchors = KL.Lambda(lambda x: tf.Variable(anchors), name="anchors")(input_image)
改为:
class ConstLayer(tf.keras.layers.Layer):
def __init__(self, x, name=None):
super(ConstLayer, self).__init__(name=name)
self.x = tf.Variable(x)
def call(self, input):
return self.x
anchors = ConstLayer(anchors, name="anchors")(input_image)
10万+

被折叠的 条评论
为什么被折叠?



