简体   繁体   中英

Unable to convert custom trained frozen model into tflite format

I have the following script using which I was able to successfully convert deeplabv3_mnv2_pascal_train.pb model ( click here to download ) into tflite format

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

I obtained input_arrays, and output_arrays for deeplabv3_mnv2_pascal_train.pb using the following python script. I took this python script from : Obtain input_array and output_array items to convert model to tflite format

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

I planned to apply the same steps above towards my custom trained model, and convert it into tflite format.I have custom trained a model for semantic segmentation on tensorflow and exported it in form of a inference graph . I used the above python script to get the input_arrays, and output_arrays and then ran the following:

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

I am getting the following error

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

How do I resolve this error ? and get tflite model for custom trained frozen inference graph of semantic segmentation

Tflite was not properly installed, as a result the code produced strange output. I reinstalled TensorFlow on another OS and this problem was resolved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM