训练时使用固定大小, 方便编程实现和速度优化
部署时使用任意大小, 提高体验
但是采用固定大小输入做训练, 部署时采用任意大小, 可能效果有点差别吧....
pb文件的网络结构
import tensorflow as tfoutput_graph_def = tf.GraphDef()PB_PATH = r"./pb/feathers.pb"with open(PB_PATH, "rb") as f: output_graph_def.ParseFromString(f.read()) tf.import_graph_def( output_graph_def, name='', # 默认name为import,类似scope )with tf.Session() as sess: sess.run(tf.global_variables_initializer()) tf.summary.FileWriter('./log/', sess.graph)
tensorboard.exe --logdir .
将固定输入大小的pb文件,转化为任意输入大小的tfjs格式
import tensorflow as tffrom tensorflow.python.framework import graph_utilimport tensorflowjs as tfjssess = tf.Session()output_graph_def = tf.GraphDef()# feathers starry candyPB_PATH = r"./pb/candy.pb"TFJS_PATH = r'./tfjs/candy'in_image = tf.placeholder(tf.float32, (None, None, None, 3), name='in_x')with open(PB_PATH, "rb") as f: output_graph_def.ParseFromString(f.read()) tf.import_graph_def( output_graph_def, input_map={ 'in_x:0': in_image }, name='', # 默认name为import,类似scope # return_elements=['generator/mul:0'] )sess.run(tf.global_variables_initializer())output = sess.graph.get_tensor_by_name("generator/output:0")with tf.Session() as sess: sess.run(tf.global_variables_initializer()) constant_graph = graph_util.convert_variables_to_constants(sess, sess.graph_def, ['generator/output']) with tf.gfile.FastGFile("./pb/tmp.pb", mode='wb') as f: f.write(constant_graph.SerializeToString())tfjs.converters.tf_saved_model_conversion_pb.convert_tf_frozen_model( "./pb/tmp.pb", 'generator/output', TFJS_PATH)