不训练的情况下保存模型报错
Created by: snowsteper
RT,希望在不训练的情况下存储模型,遇到报错 paddle.fluid.core.EnforceNotMet: holder_ should not be null Tensor not initialized yet when Tensor::type() is called. at [/paddle/paddle/fluid/framework/tensor.h:141]
代码如下:
score = network(char_dict_dim=char_dict_num, word_dict_dim=word_dict_num, class_dim=class_num)
score.persistable = True
# Program
main_program = fluid.default_main_program()
start_program = fluid.default_startup_program()
# Executor
exe = fluid.Executor(place)
exe.run(start_program)
# model_name = model_name_prefix + "_pass_%04d" % pass_num
# model_path = os.path.join(model_dir, model_name)
# fluid.io.load_params(exe, model_path, main_program=main_program, filename=None)
feeded_var_names = ["query_char_data", "query_basic_data", "query_phrase_data",
"title_char_data", "title_basic_data", "title_phrase_data"]
target_vars = [score]
fluid.io.save_inference_model(dirname=save_model_dir,
model_filename=save_model_name,
feeded_var_names=feeded_var_names,
target_vars=target_vars,
executor=exe,
main_program=main_program)
更新一下: 我的实际需求是这样, 有一个训好的网络A,结构是 data_layer -> nets_A 我想加一路数据输入,但是对于两路输入中间nets的参数是共享的,都用训好网络A的参数,也就是网络B的结构是: data_layer_1 -> nets_A(用网络A的参数) data_layer_2 -> nets_A(用网络A的参数) 也就是说,除了输入以外,中间计算的所有需要训练的参数都复用A的参数
最终,我想通过先加载再保存的方式得到model.conf以及对应的正确的参数