在 tensorflow lite 中获取量化激活
Obtaining quantized activations in tensorflow lite
我正在尝试在 tf lite 中获取中间特征图值。
我使用解释器加载量化的 mobilenet v1 224 tflite 模型并使用示例输入数据调用调用。
网络输出似乎是正确的,但是当我查看 get_tensor 的中间输出(写为图像)的输出时,其中一些似乎已损坏,好像被后来的操作覆盖了(参见示例图像)。
有没有办法为所有层检索正确的量化输出?
我构建的是当前最新的TF 1.10.1
Conv2d_1_pointwise-Relu6_chan_3
Conv2d_2_pointwise-Relu6_chan_11
我设法通过从原始冻结转换并使所有操作都在输出列表中来解决问题。
我看到有时边框是错误的,例如下图中右侧有一列白色像素,但这是一个不同的问题。
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
从 tensorflow-2.5.0 开始,您可以选择“experimental_preserve_all_tensors”来配置您的解释器,例如
interpreter = tf.lite.Interpreter(
model_path="test.tflite",
experimental_preserve_all_tensors=True)
这将在您调用它后保留所有中间激活。
我正在尝试在 tf lite 中获取中间特征图值。
我使用解释器加载量化的 mobilenet v1 224 tflite 模型并使用示例输入数据调用调用。
网络输出似乎是正确的,但是当我查看 get_tensor 的中间输出(写为图像)的输出时,其中一些似乎已损坏,好像被后来的操作覆盖了(参见示例图像)。
有没有办法为所有层检索正确的量化输出?
我构建的是当前最新的TF 1.10.1
Conv2d_1_pointwise-Relu6_chan_3
Conv2d_2_pointwise-Relu6_chan_11
我设法通过从原始冻结转换并使所有操作都在输出列表中来解决问题。
我看到有时边框是错误的,例如下图中右侧有一列白色像素,但这是一个不同的问题。
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
从 tensorflow-2.5.0 开始,您可以选择“experimental_preserve_all_tensors”来配置您的解释器,例如
interpreter = tf.lite.Interpreter(
model_path="test.tflite",
experimental_preserve_all_tensors=True)
这将在您调用它后保留所有中间激活。