簡體   English   中英

無法將自定義訓練的凍結模型轉換為tflite格式

[英]Unable to convert custom trained frozen model into tflite format

我有以下腳本使用,我能夠成功地將deeplabv3_mnv2_pascal_train.pb模型( 點擊此處下載 )轉換為tflite格式

tflite_convert \
  --output_file=test.lite \
  --graph_def_file=deeplabv3_mnv2_pascal_tain.pb \
  --input_arrays=ImageTensor \
  --output_arrays=SemanticPredictions \
  --input_shapes=1,513,513,3 \
  --inference_input_type=QUANTIZED_UINT8 \
  --inference_type=FLOAT \
  --mean_values=128 \
  --std_dev_values=128

我使用以下python腳本為deeplabv3_mnv2_pascal_train.pb獲取了input_arrays和output_arrays。 我從這里獲取了這個python腳本: 獲取input_array和output_array項目以將模型轉換為tflite格式

import tensorflow as tf
gf = tf.GraphDef()   
m_file = open('deeplabv3_mnv2_pascal_tain.pb','rb')
gf.ParseFromString(m_file.read())

#We get the names of the nodes
for n in gf.node:
    print( n.name )

#To get the tensor
tensor = n.op

我計划對我的自定義訓練模型應用相同的步驟,並將其轉換為tflite格式。我已經定制訓練了張量流上語義分割的模型,並以推理圖的形式導出。 我使用上面的python腳本來獲取input_arrays和output_arrays,然后運行以下命令:

tflite_convert \
  --output_file=test.lite \
  --graph_def_file=my_graph.pb \
  --input_arrays=Const \
  --output_arrays=detection_masks \
  --input_shapes=1,513,513,3 \
  --inference_input_type=QUANTIZED_UINT8 \
  --inference_type=FLOAT \
  --mean_values=128 \
  --std_dev_values=128

我收到以下錯誤

2019-03-25 12:54:10.156375: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
Traceback (most recent call last):
  File "/home/ajinkya/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 558, in set_shape
    unknown_shape)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Shapes must be equal rank, but are 1 and 4

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ajinkya/.local/bin/tflite_convert", line 11, in <module>
    sys.exit(main())
  File "/home/ajinkya/.local/lib/python3.5/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 412, in main
    app.run(main=run_main, argv=sys.argv[:1])
  File "/home/ajinkya/.local/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 125, in run
    _sys.exit(main(argv))
  File "/home/ajinkya/.local/lib/python3.5/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 408, in run_main
    _convert_model(tflite_flags)
  File "/home/ajinkya/.local/lib/python3.5/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 100, in _convert_model
    converter = _get_toco_converter(flags)
  File "/home/ajinkya/.local/lib/python3.5/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 87, in _get_toco_converter
    return converter_fn(**converter_kwargs)
  File "/home/ajinkya/.local/lib/python3.5/site-packages/tensorflow/contrib/lite/python/lite.py", line 286, in from_frozen_graph
    _set_tensor_shapes(input_tensors, input_shapes)
  File "/home/ajinkya/.local/lib/python3.5/site-packages/tensorflow/contrib/lite/python/convert_saved_model.py", line 205, in set_tensor_shapes
    tensor.set_shape(shape)
  File "/home/ajinkya/.local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 561, in set_shape
    raise ValueError(str(e))
ValueError: Shapes must be equal rank, but are 1 and 4

我該如何解決這個錯誤? 並獲得自定義訓練的語義分割凍結推理圖的tflite模型

Tflite沒有正確安裝,因此代碼產生了奇怪的輸出。 我在另一個操作系統上重新安裝了TensorFlow,這個問題得到了解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM