【问题标题】:Error converting .Pb filte to tflite using toco(tensorflow)使用 taco(tensorflow) 将 .Py 文件转换为 tflite 时出错
【发布时间】:2019-03-15 17:23:34
【问题描述】:

我正在关注本教程 tensorflow for poets,我创建了自定义训练数据并将其转换为 .pb,但是当我尝试使用 toco 将 .pb 转换为 .tflite 时出现错误

2018-10-10 13:56:40.442130: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1233] 转换不支持的操作:DecodeJpeg 2018-10-10 13:56:40.471545: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] 在删除未使用的操作之前:706 个运算符,1102 个数组(0 量化) 2018-10-10 13:56:40.485896:我 tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] 删除未使用的操作后通过 1:607 个运算符,1003 个数组(0 量化) 2018-10-10 13:56:40.502109: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] 在一般图形转换之前:607 个运算符,1003 个数组(0 量化) 2018-10-10 13:56:40.581854: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] 一般图形转换后通过 1:129 个运算符,327 个数组(0 量化) 2018-10-10 13:56:40.584067: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] 一般图形转换通过 2: 126 个运算符后,321 个数组(0 量化) 2018-10-10 13:56:40.586222: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] 一般图形转换通过 3: 125 个运算符,319 个数组(0 量化) 2018-10-10 13:56:40.588344: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] 在去量化图转换之前:125 个运算符,319 个数组(0 个量化) 2018-10-10 13:56:40.590472:I tensorflow/contrib/lite/toco/allocate_transient_arrays.cc:311] 总瞬态数组分配大小:0 字节,理论最优值:0 字节。 2018-10-10 13:56:40.591866: F tensorflow/contrib/lite/toco/tflite/export.cc:304] 标准 TensorFlow Lite 运行时不支持模型中的某些运算符。如果您有他们的自定义实现,您可以使用 --allow_custom_ops 禁用此错误。以下是您需要自定义实现的运算符列表:DecodeJpeg、ExpandDims。 中止(核心转储)

【问题讨论】:

  • 我通过从张量流 1.7 升级到 1.11 解决了上述错误,但现在我得到一个新错误 toco:错误:参数之一 --graph_def_file --saved_model_dir --keras_model_file 是必需的跨度>
  • 请提供您正在运行的命令以供参考。您可能必须将--input_file 更改为--graph_def_file。一个示例命令行可用here
  • 我将输入文件更改为 --graph_def_file 现在它给了我一个不同的错误 错误消息 File "/home/infinity/.local/lib/python3.6/site-packages/tensorflow/contrib/lite/python/lite.py", line 271, in from_frozen_graph sess.graph, input_arrays) File "/home/infinity/.local/lib/python3.6/site-packages/tensorflow/contrib/lite/python/convert_saved_model.py", line 189, in get_tensors_from_tensor_names ",".join(invalid_tensors))) ValueError: Invalid tensors 'input' were found.
  • 解决了我猜语法错误是因为python版本混合刚刚用python3编译了所有东西并成功地将.pb文件转换为.tflite

标签: tensorflow tensorflow-lite


【解决方案1】:
toco \
  --input_format=TENSORFLOW_GRAPHDEF \
  --graph_def_file=tf_files/object_graph.pb \
  --output_format=TFLITE \
  --output_file=tf_files/qobject.lite \
  --inference_type=QUANTIZED_UINT8 \
  --inference_input_type=QUANTIZED_UINT8 \
  --input_arrays=input \
  --output_arrays=final_result \
  --input_shapes=1,224,224,3\
  --mean_values=128 \
  --std_dev_values=128 \
  --default_ranges_min=0 \
  --default_ranges_max=6

只需使用此代码将 .pb 文件转换为精简版并量化

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-17
    • 1970-01-01
    • 1970-01-01
    • 2018-07-27
    • 1970-01-01
    • 2012-11-13
    • 1970-01-01
    • 2020-09-10
    相关资源
    最近更新 更多