【问题标题】:Obtaining quantized activations in tensorflow lite在 tensorflow lite 中获得量化的激活
【发布时间】:2018-09-17 13:39:09
【问题描述】:

我正在尝试在 tf lite 中获取中间特征图值。

我使用解释器加载量化的 mobilenet v1 224 tflite 模型,并使用示例输入数据调用调用。

网络输出看起来是正确的,但是当我查看 get_tensor 的输出以获取中间输出(写为图像)时,其中一些似乎已损坏,好像被后来的操作覆盖(参见示例图像)。

有没有办法为所有层检索正确的量化输出?

我构建了当前最新的 TF 1.10.1

Conv2d_1_pointwise-Relu6_chan_3

Conv2d_2_pointwise-Relu6_chan_11

【问题讨论】:

    标签: tensorflow-lite


    【解决方案1】:

    从 tensorflow-2.5.0 开始,您可以选择“experimental_preserve_all_tensors”来配置您的解释器,例如

    interpreter = tf.lite.Interpreter(
        model_path="test.tflite",
        experimental_preserve_all_tensors=True)
    

    这将在您调用它后保留所有中间激活。

    【讨论】:

      【解决方案2】:

      我设法通过从原始冻结转换并将所有操作都放在输出列表中来解决问题。

      我发现有时边界是错误的,例如下图中右侧有一列白色像素,但这是一个不同的问题。

      Conv2d_1_pointwise-Relu6_chan_13

      bazel run //tensorflow/contrib/lite/python:tflite_convert -- \
      --output_file=toco_mobilenet_v1_1.0_224_quant.tflite \
      --graph_def_file=mobilenet_v1_1.0_224_quant/mobilenet_v1_1.0_224_quant_frozen.pb \
      --inference_type=QUANTIZED_UINT8 \
      --mean_values=128 \
      --std_dev_values=127 \
      --input_arrays=input \
      --output_arrays=MobilenetV1/MobilenetV1/Conv2d_0/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_1_depthwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_1_pointwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_2_depthwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_2_pointwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_3_depthwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_3_pointwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_4_depthwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_4_pointwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_5_depthwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_5_pointwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_6_depthwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_6_pointwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_7_depthwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_7_pointwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_8_depthwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_8_pointwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_9_depthwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_9_pointwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_10_depthwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_10_pointwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_11_depthwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_11_pointwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_12_depthwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_12_pointwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_13_depthwise/Relu6,\
      MobilenetV1/MobilenetV1/Conv2d_13_pointwise/Relu6,\
      MobilenetV1/Logits/AvgPool_1a/AvgPool,\
      MobilenetV1/Logits/Conv2d_1c_1x1/BiasAdd,\
      MobilenetV1/Logits/SpatialSqueeze,\
      MobilenetV1/Predictions/Reshape_1
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-03-28
        • 2019-05-16
        • 1970-01-01
        • 2020-02-13
        • 2018-05-07
        • 2021-04-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多