tensorflow lite:量化graphdef的转换错误
我按照教程()生成量化graphdef文件:tensorflow lite:量化graphdef的转换错误,tensorflow,tensorflow-lite,Tensorflow,Tensorflow Lite,我按照教程()生成量化graphdef文件: curl -L "https://storage.googleapis.com/download.tensorflow.org/models/inception_v3_2016_08_28_frozen.pb.tar.gz" | tar -C tensorflow/examples/label_image/data -xz bazel build tensorflow/tools/graph_transforms:transform_graph ba
curl -L "https://storage.googleapis.com/download.tensorflow.org/models/inception_v3_2016_08_28_frozen.pb.tar.gz" | tar -C tensorflow/examples/label_image/data -xz
bazel build tensorflow/tools/graph_transforms:transform_graph
bazel-bin/tensorflow/tools/graph_transforms/transform_graph \
--in_graph=tensorflow/examples/label_image/data/inception_v3_2016_08_28_frozen.pb \
--out_graph=/tmp/inception_v3_quantized_graph.pb \
--inputs=input \
--outputs=InceptionV3/Predictions/Reshape_1 \
--transforms='add_default_attributes strip_unused_nodes(type=float, shape="1,299,299,3")
remove_nodes(op=Identity, op=CheckNumerics) fold_constants(ignore_errors=true)
fold_batch_norms fold_old_batch_norms quantize_weights quantize_nodes
strip_unused_nodes sort_by_execution_order'
然后将量化graphdef转换为tflite文件:
bazel-bin/tensorflow/contrib/lite/toco/toco \
--input_file=/tmp/inception_v3_quantized_graph.pb\
--output_file=/tmp/inception_v3_quantized_graph.lite \
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TFLITE \
--inference_type=QUANTIZED_UINT8 --input_type=QUANTIZED_UINT8\
--input_shape=1,299,299,3 \
--input_array=input \
--output_array=InceptionV3/Predictions/Reshape_1 \
--mean_value=128 \
--std_value=127
失败,错误为:
2017-11-23 12:36:40.637143: F tensorflow/contrib/lite/toco/tooling_util.cc:549] Check failed: model.arrays.count(input_array.name()) Input array not found: input
Aborted (core dumped)
运行总结图工具
bazel-bin/tensorflow/tools/graph_transforms/summarize_graph \
--in_graph=/tmp/inception_v3_quantized_graph.pb
输入节点已存在
Found 1 possible inputs: (name=input, type=float(1), shape=[1,299,299,3])
No variables spotted.
Found 1 possible outputs: (name=InceptionV3/Predictions/Reshape_1,
op=Dequantize)
Found 23824934 (23.82M) const parameters, 0 (0) variable parameters, and 268
control_edges
Op types used: 673 Const, 214 Requantize, 214 RequantizationRange, 134 Reshape, 134 Max, 134 Min, 134 QuantizeV2, 95 QuantizedConv2D, 94 QuantizedRelu, 94 QuantizedAdd, 49 Dequantize, 24 QuantizedMul, 15 ConcatV2, 10 QuantizedAvgPool, 4 QuantizedMaxPool, 2 QuantizedReshape, 1 QuantizedBiasAdd, 1 Placeholder, 1 Softmax, 1 Squeeze
我错过什么了吗?将量化graphdef文件转换为tflite文件的正确方法是什么
谢谢 我用TF()的干净签出复制了您的命令行 我确实遇到了Toco错误,但与您不同:
F tensorflow/contrib/lite/toco/tooling_util.cc:1155]Array InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/BatchNorm/mul_eightbit/input_端口__0/min,它是(不支持的tensorflow op:QuantizeV2)的输入生成输出数组InceptionV3/InceptionV3/Conv2d_1a_3x3/BatchNorm/BatchNorm/mul_eightbit/input__端口__0/quantize的运算符缺少量化所需的最小/最大数据。以非量化输出格式为目标,或者更改输入图形以包含最小/最大信息,或者传递--default\u ranges\u min=和--default\u ranges\u max=如果您不关心结果的准确性。
这不是toco错误,而是toco抱怨文件中的两个问题,inception\u v3\u quantized\u graph.pb
:
QuantizeV2
。Toco不知道这种类型的操作员。这不是此错误消息的直接主题,但如果您超过此点,您将在以后遇到真正的问题李>
TensorFlow Lite带来了一种新的量化方法,它与您提到的现有TensorFlow文档和工具中以前所做的不同。这里出现的错误可以归结为尝试使用TensorFlow Lite转换器,该转换器要求使用新方法量化的图形,使用旧方法量化的图形
我们正在记录新的量化方法
同时,您可能已经能够通过以下几点提示进行实验。
新的量化方法需要在浮点训练图中插入“伪量化”节点,如下所述:
这些节点的目的是在训练期间准确模拟8位量化的精度影响,并记录用于该量化的精确最小-最大范围。
必须将这些节点放置在正确的位置,因为量化训练的重点是允许在推理中再现完全相同的算法,并且量化推理需要将整个融合层(Conv+biasad+ReLU),(完全连接+biasad+ReLU)作为单个融合操作来实现。因此,应放置伪数量节点:
- 在激活功能(例如,在ReLU的输出)之后,在每个(熔合)层(例如,Conv+BiasAdd+ReLU)的输出激活上。不在之前(不在比亚萨德附近)
- 在Conv/fully connected上,在Conv/fully connected op消耗重量之前,重量
- 不要在偏移向量上放置伪_量化节点