# -*- cooding: utf-8 -*- #h5_to_pb.py from keras.models import load_model import tensorflow as tf import os import os.path as osp from keras import backend as K #路径参数 input_path = './' weight_file = 'idcard_corner.h5' weight_file_path = osp.join(input_path,weight_file) output_graph_name = weight_file[:-3] + '.pb' #转换函数 def h5_to_pb(h5_model,output_dir,model_name,out_prefix = "output_",log_tensorboard = True): if osp.exists(output_dir) == False: os.mkdir(output_dir) out_nodes = [] for i in range(len(h5_model.outputs)): out_nodes.append(out_prefix + str(i + 1)) tf.identity(h5_model.output[i],out_prefix + str(i + 1)) sess = K.get_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.wr
h5文件转pb文件
最新推荐文章于 2024-07-21 07:15:00 发布
该博客介绍了如何将Keras的H5模型转换为TensorFlow的PB格式。通过加载H5模型,使用Keras的backend获取会话,并利用TensorFlow的graph_util工具将变量转换为常量,最后保存为PB文件。转换过程包括定义输出节点、创建目录、读写图定义等步骤。
摘要由CSDN通过智能技术生成