Faster-rcnn代码python2转换python3的KeyError: b‘TEST‘问题

一直用的一个faster-rcnn代码是python2的,决定把它改为python3。

很多报错都是print函数,xrange函数,较好解决。

解决到最后被一个报错,卡了一天,在网上也无法找到解决方案,记录一下:

报错如下:

Caused by op 'PyFunc', defined at:
  File "/home/q/yd/Faster-RCNN-21/tools/demo.py", line 118, in <module>
    net = get_network(args.demo_net)
  File "/home/q/yd/Faster-RCNN-21/tools/../lib/networks/factory.py", line 29, in get_network
    return networks.VGGnet_test()
  File "/home/q/yd/Faster-RCNN-21/tools/../lib/networks/VGGnet_test.py", line 18, in __init__
    self.setup()
  File "/home/q/yd/Faster-RCNN-21/tools/../lib/networks/VGGnet_test.py", line 55, in setup
    .proposal_layer(_feat_stride, anchor_scales, str('TEST'), name='rois'))
  File "/home/q/yd/Faster-RCNN-21/tools/../lib/networks/network.py", line 24, in layer_decorated
    layer_output = op(self, layer_input, *args, **kwargs)
  File "/home/q/yd/Faster-RCNN-21/tools/../lib/networks/network.py", line 164, in proposal_layer
    [tf.float32]), [-1, 5], name=name)
  File "/home/q/anaconda3/envs/py35/lib/python3.5/site-packages/tensorflow/python/ops/script_ops.py", line 212, in py_func
    input=inp, token=token, Tout=Tout, name=name)
  File "/home/q/anaconda3/envs/py35/lib/python3.5/site-packages/tensorflow/python/ops/gen_script_ops.py", line 50, in _py_func
    "PyFunc", input=input, token=token, Tout=Tout, name=name)
  File "/home/q/anaconda3/envs/py35/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "/home/q/anaconda3/envs/py35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2956, in create_op
    op_def=op_def)
  File "/home/q/anaconda3/envs/py35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1470, in __init__
    self._traceback = self._graph._extract_stack()  # pylint: disable=protected-access

UnknownError (see above for traceback): KeyError: b'TEST'
     [[Node: PyFunc = PyFunc[Tin=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_STRING, DT_INT32, DT_INT32], Tout=[DT_FLOAT], token="pyfunc_0", _device="/job:localhost/replica:0/task:0/device:CPU:0"](rpn_cls_prob_reshape/_95, rpn_bbox_pred/rpn_bbox_pred/_97, _arg_Placeholder_1_0_1, PyFunc/input_3, PyFunc/input_4, PyFunc/input_5)]]
     [[Node: PyFunc/_99 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_218_PyFunc", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]]

 

 

报错里最后的提示词只有KeyError: b'TEST',

经分析,最终定位原因是tf初始化中输入的一个‘TEST’字符串无法解析。

报错位置在VGG_test.py文件里的

(self.feed('rpn_cls_prob_reshape', 'rpn_bbox_pred', 'im_info')
 .proposal_layer(_feat_stride, anchor_scales, str('TEST'), name='rois'))

这里有一个‘TEST’,这个‘TEST’会输入到tf.py_func()函数里

无法解析原因不明

最终解决方法为在proposal_layer_tf.py文件中,直接把‘TEST’赋值

cfg_key = 'TEST'
pre_nms_topN  = cfg[cfg_key].RPN_PRE_NMS_TOP_N
post_nms_topN = cfg[cfg_key].RPN_POST_NMS_TOP_N
nms_thresh    = cfg[cfg_key].RPN_NMS_THRESH
min_size      = cfg[cfg_key].RPN_MIN_SIZE

加上了标红的这句,成功运行。

原始代码中,语法检查差不出问题,只能先手动将‘TEST’赋值给cfg_key来解决这个问题。

 

网上很多说python2和python3的编码不同,加utf-8的编码,测试无效。

 

 

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页