tensorflow.keras中的H5模型无法转换为graphdef冻结模型
我想通过TensorRT优化h5模型,但我无法将h5模型转换为graphdef冻结模型,错误如下:tensorflow.keras中的H5模型无法转换为graphdef冻结模型,tensorflow,freeze,tensorrt,Tensorflow,Freeze,Tensorrt,我想通过TensorRT优化h5模型,但我无法将h5模型转换为graphdef冻结模型,错误如下: Traceback (most recent call last): File "h5_to_pb.py", line 38, in <module> h5_to_pb(h5_model, output_dir="./", model_name="61") File "h5_to_pb.py"
Traceback (most recent call last):
File "h5_to_pb.py", line 38, in <module>
h5_to_pb(h5_model, output_dir="./", model_name="61")
File "h5_to_pb.py", line 20, in h5_to_pb
main_graph = graph_util.convert_variables_to_constants(sess, init_graph, out_nodes)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/deprecation.py", line 324, in new_func
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/graph_util_impl.py", line 297, in convert_variables_to_constants
source_op_name = get_input_name(node)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/graph_util_impl.py", line 254, in get_input_name
raise ValueError("Tensor name '{0}' is invalid.".format(node.input[0]))
ValueError: Tensor name 'bn_conv1/cond/ReadVariableOp/Switch:1' is invalid.
请帮助………解决问题。变化
for i in range(len(h5_model.outputs)):
out_nodes.append(out_prefix + str(i))
tf.identity(h5_model.output[i], out_prefix + str(i))
print(h5_model.outputs)
sess = tf.compat.v1.Session()
from tensorflow.python.framework import graph_util, graph_io
init_graph = sess.graph.as_graph_def()
main_graph = graph_util.convert_variables_to_constants(sess, init_graph, out_nodes)
graph_io.write_graph(main_graph, output_dir, name=model_name, as_text=False)