ValueError: Tensor Tensor("mrcnn_detection/PyFunc:0", dtype=float32) is not an element of this graph

参考:
1. https://github.com/keras-team/keras/issues/2397

今天在把Mask RCNN改成ROS Server来使用的时候,遇到了这个错误,我是根据这个ROS Subscriber版的Mask RCNN的基础上来改的,原代码运行很正常,但是我在改成ROS Node之后出现了这个错误,看了一晚上才意识到,正如参考[1]里有人提到的:

I had this problem when doing inference in a different thread than where I loaded my model. Here’s how I fixed the problem:

我改完成ROS server之后,load model是在实例化我的调用mask rcnn的类的时候进行的,然而inference是在接收到request的时候才进行,显然不在一个进程里。而那个写成subscriber的版本,他们是在同一个进程里的,subscribe的图片不断的写入一个类成员变量里,这里利用了python多线程中互斥锁确保不会同时读写这个变量,然后就可以让model对当前的图片进行inference了,代码如下:

class MaskRCNNNode(object):
    def __init__(self):
        self._cv_bridge = CvBridge()

        config = InferenceConfig()
        config.display()

        self._visualization = rospy.get_param('~visualization', True)

        # Create model object in inference mode.
        self._model = modellib.MaskRCNN(mode="inference", model_dir="",
                                        config=config)
        # Load weights trained on MS-COCO
        model_path = rospy.
  • 5
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值