AI实战:查看pb模型的graph的所有层的名称

  • 代码:

查看pb模型的graph的所有层的名称,代码如下:

get_all_layernames.py:

import os, sys
from tensorflow.python.platform import gfile
import tensorflow as tf

def get_all_layernames(pb_file_path):
    #get all layers name 
    
    sess = tf.Session()
    with gfile.FastGFile(pb_file_path, 'rb') as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())
        sess.graph.as_default()
        tf.import_graph_def(graph_def, name='')

        tensor_name_list = [tensor.name for tensor in tf.get_default_graph().as_graph_def().node]
        for tensor_name in tensor_name_list:
            print(tensor_name)
            
            
if __name__ == '__main__':
    if len(sys.argv) == 2:
        get_all_layernames(sys.argv[1])
  • 测试

    1、下载训练好的pb文件:
    http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz

    2、解压得到pb文件:classify_image_graph_def.pb

    3、测试
    python get_all_layernames.py classify_image_graph_def.pb
    输出:

DecodeJpeg/contents
DecodeJpeg
Cast
ExpandDims/dim
ExpandDims
ResizeBilinear/size
ResizeBilinear
Sub/y
Sub
Mul/y
Mul
conv/conv2d_params
conv/Conv2D
......
pool_3
pool_3/_reshape/shape
pool_3/_reshape
softmax/weights
softmax/biases
softmax/logits/MatMul
softmax/logits
softmax
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

szZack

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值