首页 炼丹房 帖子详情
Cannot find fetch variab
收藏
快速回复
炼丹房 问答新手上路 742 2
Cannot find fetch variab
收藏
快速回复
炼丹房 问答新手上路 742 2
  1. 参考官方的eval.pyinfer.py结合,想在exe.runfetch_list中返回fluid.layers.detection_output的输出,报错如下:

C++ Callstacks:
Cannot find fetch variable in scope, fetch_var_name is detection_output_0.tmp_0 at [/paddle/paddle/fluid/operators/controlflow/fetch_op.cc:37]

具体代码如下:

  • 在函数体中返回fluid.layers.detection_output的输出:

with fluid.program_guard(main_prog, startup_prog):

        py_reader = fluid.layers.py_reader(

            capacity=64,

            shapes=[[-1] + image_shape, [-1, 4], [-1, 1], [-1, 1]],

            lod_levels=[0, 1, 1, 1],

            dtypes=["float32", "float32", "int32", "int32"],

            use_double_buffer=True)




        image, gt_box, gt_label, difficult = fluid.layers.read_file(

                py_reader)

        locs, confs, box, box_var = build_ssd(image, num_classes,

                                                            image_shape)

        nmsed_out = fluid.layers.detection_output(

            locs, confs, box, box_var, nms_threshold=args.nms_threshold)

     

    return py_reader, nmsed_out

在测试程序调用:

def test(args, data_args, test_list, batch_size, model_dir=None):

    startup_prog = fluid.Program()

    test_prog = fluid.Program()

    test_py_reader, detection_output = build_program(

        main_prog=test_prog,

        startup_prog=startup_prog,

        args=args,

        data_args=data_args)




    place = fluid.CUDAPlace(0) if args.use_gpu else fluid.CPUPlace()

    exe = fluid.Executor(place)

    if model_dir:

        def if_exist(var):

            return os.path.exists(os.path.join(model_dir, var.name))

        fluid.io.load_vars(exe, model_dir, predicate=if_exist)

    test_reader = reader.test(data_args, test_list, batch_size=batch_size)

    test_py_reader.decorate_paddle_reader(test_reader)




    test_py_reader.start()




    # switch network to test mode (i.e. batch norm test mode)

    test_program = fluid.default_main_program().clone(for_test=True)

    detection_output_v, = exe.run(test_program,

                           fetch_list=[detection_output],

                           return_numpy=False)

以上

0
收藏
回复
全部评论(2)
时间顺序
AIStudio810261
#2 回复于2020-01

亲, 原始项目url是什么?

1
回复
点到为止丶11
#3 回复于2020-01

我fork的这个项目,https://aistudio.baidu.com/aistudio/projectDetail/189267

根据里面infer.py中用到了

image = fluid.layers.data(name='image', shape=image_shape, dtype='float32')
    locs, confs, box, box_var = build_ssd(image, num_classes,
                                                    image_shape)
    nmsed_out = fluid.layers.detection_output(
        locs, confs, box, box_var, nms_threshold=args.nms_threshold)

    |
    |
    |
    nmsed_out_v, = exe.run(test_program,
                           feed=feeder.feed([[data]]),
                           fetch_list=[nmsed_out],
                           return_numpy=False)

 

0
回复
在@后输入用户全名并按空格结束,可艾特全站任一用户