【问题标题】:I am trying to do a quantized mobilenet model to tensorflow lite model, but run into an error我正在尝试对 tensorflow lite 模型进行量化的 mobilenet 模型,但遇到错误
【发布时间】:2018-08-10 09:28:37
【问题描述】:

首先我从 Mobilenet 下载了一个量化模型。它包含在 Mobilenet_v1_1.0_224 中。然后我做了以下

bazel-bin/tensorflow/contrib/lite/toco/toco \
> --input_files=Sample/mobilenet_v1_1.0_224/quantized_graph.pb \
> --input_format=TENSORFLOW_GRAPHDEF --output_format=TFLITE \
> --output_file=Sample/mobilenet_v1_1.0_224/quantized_graph.tflite --inference_type=QUANTIZED_UINT8 \
> --input_shape=1,224,224,3 \
> --input_array=input \
> --output_array=MobilenetV1/Predictions/Reshape_1 \
> --mean_value=128 \
> --std_value=127

以下是图表摘要

bazel-bin/tensorflow/tools/graph_transforms/summarize_graph --in_graph=Sample/mobilenet_v1_1.0_224/quantized_graph.pb
Found 1 possible inputs: (name=input, type=float(1), shape=[1,224,224,3]) 
No variables spotted.
Found 1 possible outputs: (name=MobilenetV1/Predictions/Reshape_1, op=Reshape) 
Found 4227041 (4.23M) const parameters, 0 (0) variable parameters, and 0 control_edges
Op types used: 91 Const, 27 Add, 27 Relu6, 15 Conv2D, 13 DepthwiseConv2dNative, 13 Mul, 10 Dequantize, 2 Reshape, 1 Identity, 1 Placeholder, 1 BiasAdd, 1 AvgPool, 1 Softmax, 1 Squeeze
To use with tensorflow/tools/benchmark:benchmark_model try these arguments:
bazel run tensorflow/tools/benchmark:benchmark_model -- --graph=Sample/mobilenet_v1_1.0_224/quantized_graph.pb --show_flops --input_layer=input --input_layer_type=float --input_layer_shape=1,224,224,3 --output_layer=MobilenetV1/Predictions/Reshape_1

所以通过转换,我遇到了以下错误

2018-03-01 23:12:03.353786: 我 tensorflow/contrib/lite/toco/import_tensorflow.cc:1172] 转换 不支持的操作:去量化 2018-03-01 23:12:03.354513: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1172] 转换 不支持的操作:去量化 2018-03-01 23:12:03.355177: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1172] 转换 不支持的操作:去量化 2018-03-01 23:12:03.355556: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1172] 转换 不支持的操作:去量化 2018-03-01 23:12:03.355921: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1172] 转换 不支持的操作:去量化 2018-03-01 23:12:03.356281: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1172] 转换 不支持的操作:去量化 2018-03-01 23:12:03.356632: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1172] 转换 不支持的操作:去量化 2018-03-01 23:12:03.357540: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1172] 转换 不支持的操作:去量化 2018-03-01 23:12:03.358776: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1172] 转换 不支持的操作:去量化 2018-03-01 23:12:03.360448: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1172] 转换 不支持的操作:去量化 2018-03-01 23:12:03.366319: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] 删除未使用的操作之前:140 个运算符,232 个数组(0 个量化) 2018-03-01 23:12:03.371405: 我 tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] 在一般图形转换之前:140 个运算符,232 个数组(0 量化)2018-03-01 23:12:03.374916:我 tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] 一般图形转换通过 1: 63 个运算符,152 个数组后 (1 量化) 2018-03-01 23:12:03.376325: 我 tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] 预量化图转换之前:63 个运算符,152 个 数组(1 个量化) 2018-03-01 23:12:03.377492: F tensorflow/contrib/lite/toco/tooling_util.cc:1272] 数组 MobilenetV1/MobilenetV1/Conv2d_0/Relu6,它是 产生输出数组的 DepthwiseConv 运算符 MobilenetV1/MobilenetV1/Conv2d_1_depthwise/Relu6,缺少最小值/最大值 数据,这是量化所必需的。要么针对 非量化输出格式,或将输入图更改为包含 最小/最大信息,或通过 --default_ranges_min= 和 --default_ranges_max= 如果您不关心结果的准确性。

感谢您的帮助

【问题讨论】:

    标签: tensorflow tensorflow-lite


    【解决方案1】:

    我认为您可能指的是旧的 TensorFlow 量化移动网络模型。

    我们更新了可用的量化移动网络模型here。您的 1.0 深度乘数和 224 图像大小的具体链接是 this

    这些 tar 文件还附带已转换的 TFLite flatbuffer 模型。

    希望对你有帮助!

    【讨论】:

    • 谢谢!我想知道应该将哪些值传递给 TensorFlow lite 转换器?和我上面的演示代码有什么区别吗?
    • 是的,您需要 --mean_value=127.5 和 --std_value=127.5。这是训练模型时用于图像的预处理的功能。如果你不想搞乱转换,你可以使用已经转换器的 FlatBuffer。谢谢!
    • 你好 Suharshs,我正在尝试使用 Mobilenet V1 进行训练后量化,但是遇到了一些问题,请你看看这里-stackoverflow.com/questions/57869149/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-11
    • 1970-01-01
    • 1970-01-01
    • 2022-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多