save_inference_model ValueError: var {variable_name} not in this block
Created by: linan142857
save预测模型如下: `
pad_num = 200
num_classes = args.num_classes
# prepare environment
place = fluid.CUDAPlace(0)
exe = fluid.Executor(place)
images = fluid.layers.data(name='pixel',
shape=data_reader.IMAGE_SHAPE[::-1], dtype='float32')
content = fluid.layers.data(name='word',
shape=[1], dtype='int32', lod_level=1)
adjacency = fluid.layers.data(name='adja',
shape=[pad_num, pad_num, 10], append_batch_size=False, dtype='float32')
edge_mask = fluid.layers.data(name='edge_mask',
shape=[pad_num, pad_num], append_batch_size=False, dtype='int32')
# define network
inference_program, node_out, edge_out = infer(args, pad_num, num_classes, images, content, adjacency, edge_mask)
print("define model over ...")
model_dir = os.path.dirname(args.model_path)
model_file_name = os.path.basename(args.model_path)
fluid.io.load_params(exe, dirname=model_dir, filename=model_file_name)
print("load model over ...")
fluid.io.save_inference_model(dirname=args.out_dir,
feeded_var_names=['pixel', 'word', 'adja', 'edge_mask'],
target_vars=[node_out, edge_out],
main_program=inference_program,
model_filename='model',
params_filename='params',
executor=exe)
print("save model over ...")
`
错误:
Traceback (most recent call last): File "model/save_infer_model.py", line 73, in main(args) File "model/save_infer_model.py", line 68, in main executor=exe) File "/home/liyulin/anaconda2/lib/python2.7/site-packages/paddle/fluid/io.py", line 1079, in save_inference_model prepend_feed_ops(main_program, feeded_var_names) File "/home/liyulin/anaconda2/lib/python2.7/site-packages/paddle/fluid/io.py", line 892, in prepend_feed_ops out = global_block.var(name) File "/home/liyulin/anaconda2/lib/python2.7/site-packages/paddle/fluid/framework.py", line 1559, in var raise ValueError("var %s not in this block" % name) ValueError: var word not in this block