Cannot find fetch variab
收藏
- 参考官方的
eval.py
和infer.py
结合,想在exe.run
的fetch_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
收藏
请登录后评论
亲, 原始项目url是什么?
我fork的这个项目,https://aistudio.baidu.com/aistudio/projectDetail/189267
根据里面infer.py中用到了