在将模型转化为tflite时,这两个output_arrays都可以生成.tflite,区别在哪里?

https://storage.googleapis.com/download.tensorflow.org/models/inception_v1_2016_08_28_frozen.pb.tar.gz 

从上面链接下载模型后,运行源码

import tensorflow as tf

graph_def_file = "/home/sir/project/models/i/inception_v1_2016_08_28_frozen.pb"
input_arrays = ["input"]

#output_arrays = ["InceptionV1/InceptionV1/Mixed_3b/Branch_1/Conv2d_0a_1x1/Relu","InceptionV1/InceptionV1/Mixed_3b/Branch_2/Conv2d_0a_1x1/Relu"]
output_arrays = ["InceptionV1/Logits/Predictions/Reshape_1"]
converter = tf.contrib.lite.TocoConverter.from_frozen_graph(graph_def_file, input_arrays, output_arrays)
tflite_model = converter.convert()
open("converted_model-22.tflite", "wb").write(tflite_model)

output_arrays 和注释掉的output_arrays 都可以生成模型,但tflite文件大小有明显的区别,请问这是怎么回事?

import tensorflow as tf
import os
model_dir = '/home/sir/project/models/i/'
model_name = 'inception_v1_2016_08_28_frozen.pb'
# 读取并创建一个图graph来存放Google训练好的Inception_v3模型(函数)
def create_graph():
    with tf.gfile.FastGFile(os.path.join( model_dir, model_name), 'rb') as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())
        # Imports the graph from graph_def into the current default Graph.
        tf.import_graph_def(graph_def, name='')
# 创建graph
create_graph()
tensor_name_list = [tensor.name for tensor in tf.get_default_graph().as_graph_def().node]
for tensor_name in tensor_name_list:
    with open('/home/sir/project/models/nodes-I.txt',"a") as f:
        f.write(tensor_name + '\n')
    #print(tensor_name,'\n')

查看tensor名称后,发现都有,中间为什么要截断模型图呢?高手留言或者私信

猜你喜欢

转载自blog.csdn.net/cdyx369/article/details/82425931