zoukankan      html  css  js  c++  java
  • TensorFlow 笔记03-TensoeFlow 和 TensorRT 调试的一些方法

    ▶ TensoeFlow 和 TensorRT 调试的一些方法,用于输出中间层的情况方便观察

    ● Tensorflow 中的方法

    1 sess = tf.Session()                             # 新开会话用于调试
    2 sess.run(tf.global_variables_initializer())
    3 temp = sess.run(h1,feed_dict = {'input:0':X})   # 获取指定节点,并给输入节点喂进数据
    4 16 print(i, "-shape: ", np.shape(temp))
    5 17 print(temp)
    6 18 sess.close()

    ● Keras 中的两种方法

     1 from keras.models import Model
     2 from keras import backend as K
     3 
     4 ...                                     # 建图
     5 model = Model(inputs=x, outputs=y)
     6 
     7 i = 1                                   # 指定需要输出的中间层序号(0 为 输入层)
     8 kFun = K.function([model.layers[0].input],[model.layers[i].output]) # 建立 K.function 用来提取中间层输出,后面喂上输入数据
     9 temp = kFun(X)                          # 喂进指定层输入数据,获取指定层输出
    10 print(i, "-shape: ", np.shape(temp))    # NHWC 格式
    11 print(temp)
    12 
    13 sess = tf.Session()                                                 # 另方法,用 tensorflow 的接口
    14 sess.run(tf.global_variables_initializer())
    15 temp = sess.run(model.layers[i].output,feed_dict = {'input:0':X})   # 获取指定层输出
    16 print(i, "-shape: ", np.shape(temp))
    17 print(temp)
    18 sess.close()

    ● TensorRT 中的调试方法

     1 h1 = network.add_ ...
     2 print(h1.get_output(0).shape)           # 查看该节点的一些属性
     3 
     4 # 举栗,tensorrt.tensorrt.IConvolutionLayer 对象(add_convolution 层的返回值)的属性:
     5 bias                # numpy.ndarray,偏置值(尺寸等于输出特征数)
     6 dilation            # numpy.ndarray,扩张量?
     7 get_input 
     8 get_output 
     9 get_output_type 
    10 kernel              # numpy.ndarray,卷积窗口权重
    11 kernel_size         # tensorrt.tensorrt.DimsHW,卷积窗口尺寸
    12 name                # str,节点名
    13 num_groups 
    14 num_inputs 
    15 num_output_maps 
    16 num_outputs 
    17 output_type_is_set
    18 padding             # numpy.ndarray,被卷积对象光环厚度,左右统一设置,上下统一设置
    19 padding_mode        # tensorrt.tensorrt.PaddingMode,
    20 post_padding        # numpy.ndarray,被卷积对象右下角光环厚度
    21 pre_padding         # numpy.ndarray,被卷积对象左上角光环厚度
    22 precision           # tensorrt.tensorrt.DataType,数据类型  
    23 precision_is_set    # bool,是否改变了默认数据类型?
    24 reset_output_type   # bound method PyCapsule.reset_output_type of <tensorrt.tensorrt.IConvolutionLayer>
    25 reset_precision         
    26 set_output_type
    27 stride              # tensorrt.tensorrt.DimsHW,卷积跨步
    28 type                # tensorrt.tensorrt.LayerType,节点类型
    29 
    30 
    31 network.mark_output(h1.get_output(0))    # 另方法,调整模型的输出节点,使得模型输出就是想要调试的节点
  • 相关阅读:
    Gitblit 的安装使用
    PLSQL 美化规则文件详解
    SQL Server Agent的作用
    使用C#创建Widows服务
    关于VS编译DevExpress默认产生几个多余的语言包的问题解决
    (转)查询A、B表中,A表中存在B表不存在的数据
    子类构造、析构时调用父类的构造、析构函数顺序
    ACCDB与MDB的读取区别
    vue中如何动态添加readonly属性
    windows下生成文件夹目录结构
  • 原文地址:https://www.cnblogs.com/cuancuancuanhao/p/11726400.html
Copyright © 2011-2022 走看看