【报错记录MaskRCNN】#931-> raise ValueError(error_str) ValueError: The following Variables were created w

@[TOC](#931-> raise ValueError(error_str) ValueError: The following Variables were created within a Lambda layer (anchors)but are not tracked by said layer报错记录)

使用说明

使用的是Colab运行 MaskRCNN 链接[https://github.com/matterport/Mask_RCNN]
colab中使用命令:!git clone https://github.com/matterport/Mask_RCNN.git 就可以下载

版本:【Keras+tensorflow/tensorflow-gpu+h5py】
!pip install keras == 2.4.3
!pip install tensorflow == 2.3.1
!pip install tensorflow-gpu == 2.3.1
!pip install h5py==2.10.0

报错记录

  1. 出错位置:
    model = modellib.MaskRCNN(mode=“training”, config=config,model_dir=MODEL_DIR)
    该行代码出现红色波浪线
  2. 报错显示
    图片展示:
    在这里插入图片描述
    错误提示:
    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, 16368, 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.

修改方法:

找到位于file: /mrcnn/model.py line: 1935repo 中): IN[0]: 的这行代码
anchors = KL.Lambda(lambda x: tf.Variable(anchors), name=“anchors”)(input_image)
改为:

  class AnchorsLayer(tf.keras.layers.Layer):
            def __init__(self, name="anchors", **kwargs):
                super(AnchorsLayer, self).__init__(name=name, **kwargs)def call(self, anchor):
                return anchor

            def get_config(self) :
                config = super(AnchorsLayer, self).get_config()
                return config

        anchor_layer = AnchorsLayer(name="anchors")
        anchors = anchor_layer(anchors)

参考链接

链接1: https://qa.1r1g.com/sf/ask/4555140411/.
链接2: https://blog.csdn.net/qq_22520587/article/details/104823338.

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值