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))    # 另方法,调整模型的输出节点,使得模型输出就是想要调试的节点
  • 相关阅读:
    JSP学习
    Maven
    Android开发环境搭建
    Java Spring MVC
    you don't know js -- Scope and Closures学习笔记——第五章(闭包) 下篇
    you don't know js -- Scope and Closures学习笔记——第五章(闭包) 上篇
    you don't know js -- Scope and Closures学习笔记——第四章(声明提升 Hoisting)
    you don't know js -- Scope and Closures学习笔记——第三章(函数VS块作用域)
    you don't know js -- Scope and Closures学习笔记——第二章(词法作用域)
    you don't know js -- Scope and Closures学习笔记——第一章(什么是作用域)
  • 原文地址:https://www.cnblogs.com/cuancuancuanhao/p/11726400.html
Copyright © 2011-2022 走看看