我坚持使用TensorFlow的saved_model.builder.SavedModelBuilder
保存经过训练的模型会话。
当我跑步时:
builder = tf.saved_model.builder.SavedModelBuilder(model_path)
builder.add_meta_graph_and_variables(
model._sess, [tf.saved_model.SERVING],
signature_def_map={
'predict_images':
tf.saved_model.signature_def_utils.build_signature_def(
inputs={'total': tf.saved_model.utils.build_tensor_info(model.x)},
outputs={'target': tf.saved_model.utils.build_tensor_info(model.y)},
method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME) ,
},
main_op=tf.tables_initializer(),
strip_default_attrs=True)
builder.save()
我收到错误消息:
File "lib/python3.7/site-packages/tensorflow/python/saved_model/builder_impl.py", line 585, in add_meta_graph_and_variables
saver = self._maybe_create_saver(saver)
..blahblah..
ValueError: At least two variables have the same name: first_compression_layer/dense/bias
当我同时使用 tf.saved_model.simple_save()时,也会遇到相同的错误。
关于此错误的更有趣的事情是,当我尝试列出图表中的所有变量时:
for variable in [n.name for n in tf.get_default_graph().as_graph_def().node if n.name.startswith("first_compression_layer/dense/bias")]:
print(variable)
我得到了唯一的变量名。
first_compression_layer/dense/bias/Initializer/zeros
first_compression_layer/dense/bias
first_compression_layer/dense/bias/Assign
first_compression_layer/dense/bias/read
first_compression_layer/dense/bias/Initializer/zeros_1
first_compression_layer/dense/bias_1
first_compression_layer/dense/bias/Assign_1
first_compression_layer/dense/bias/read_1
我正在使用tensorflow 1.14.0