save_inference_model ERROR!!!
env: cuda9, cudnn7, V100 code:
place = fluid.CUDAPlace(0)
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
fluid.io.save_inference_model('./debug/',
["image"],
[out],
exe,
main_program=None,
model_filename='model',
params_filename='params')
error message:
Traceback (most recent call last):
File "se_resnext.py", line 280, in <module>
layers=layers)
File "se_resnext.py", line 192, in train
params_filename='params')
File "/ssd1/yancanxiang/.jumbo/lib/python2.7/site-packages/paddle/fluid/io.py", line 347, in save_inference_model
prepend_feed_ops(inference_program, feeded_var_names)
File "/ssd1/yancanxiang/.jumbo/lib/python2.7/site-packages/paddle/fluid/io.py", line 273, in prepend_feed_ops
out = global_block.var(name)
File "/ssd1/yancanxiang/.jumbo/lib/python2.7/site-packages/paddle/fluid/framework.py", line 708, in var
raise ValueError("var %s not in this block" % name)
ValueError: var image not in this block
The error message is:
ValueError: var image not in this block
which means there is not a variable named image. How do you define the input layer?
@Xreki
image = fluid.layers.data(name='image', shape=image_shape, dtype='float32')
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
if parallel:
places = fluid.layers.get_places()
pd = fluid.layers.ParallelDo(places, use_nccl=use_nccl)
with pd.do():
image_ = pd.read_input(image)
label_ = pd.read_input(label)
out = SE_ResNeXt(input=image_, class_dim=class_dim, layers = layers)
cost = fluid.layers.cross_entropy(input=out, label=label_)
avg_cost = fluid.layers.mean(x=cost)
acc_top1 = fluid.layers.accuracy(input=out, label=label_, k=1)
acc_top5 = fluid.layers.accuracy(input=out, label=label_, k=5)
pd.write_output(avg_cost)
pd.write_output(acc_top1)
pd.write_output(acc_top5)
avg_cost, acc_top1, acc_top5 = pd()
avg_cost = fluid.layers.mean(x=avg_cost)
acc_top1 = fluid.layers.mean(x=acc_top1)
acc_top5 = fluid.layers.mean(x=acc_top5)
else:
out = SE_ResNeXt(input=image, class_dim=class_dim, layers = layers)
cost = fluid.layers.cross_entropy(input=out, label=label)
avg_cost = fluid.layers.mean(x=cost)
It seems you use multi GPUs to train. There is some bug in save_inference_model for programs with parallel_do ops. The training program cannot be correctly pruned to get an inference program. You can use save_persistables to save all parameters which can be used for inference too.
It is the same problem as #8795 . We will fix it as soon as possible.
This problem has also been met when we tried to save inference model in multi-GPU mode models/#724. Now @reyoung is working on solving this problem.