转换ssd_mobilenet_v2_coco为TensorflowLite

时间:2019-11-13 12:07:18

标签: tensorflow quantization

我需要.tflite作为ssd_mobilenet_v2_coco。与tensorflow model_zoo存储库一样,ssd_mobilenet_v2_coco
它不在那里。我尝试使用以下代码转换模型,但由于以下错误而失败:

import tensorflow as tf
graph_def_file = "./frozen_inference_graph.pb"
input_arrays = ["image_tensor"]
output_arrays = ["detection_boxes","detection_classes","detection_scores","num_detections"]
input_shapes={"image_tensor":[1,300,300,3]}
converter = tf.contrib.lite.TocoConverter.from_frozen_graph(graph_def_file, input_arrays, output_arrays,input_shapes)
# converter.allow_custom_ops=True
tflite_model = converter.convert()
open("converted_model2.tflite", "wb").write(tflite_model)

但是我收到以下错误消息:

2019-11-13 16:45:12.164430: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 25159680 exceeds 10% of system memory.

The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
  * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
  * https://github.com/tensorflow/addons
  * https://github.com/tensorflow/io (for I/O related ops)
If you depend on functionality not listed there, please file an issue.

Traceback (most recent call last):
  File "temp1.py", line 11, in <module>
    converter = tf.contrib.lite.TocoConverter.from_frozen_graph(graph_def_file, input_arrays, output_arrays,input_shapes)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/util/lazy_loader.py", line 63, in __getattr__
    return getattr(module, item)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/__init__.py", line 51, in __getattr__
    return getattr(module, item)
AttributeError: module 'tensorflow_core.contrib' has no attribute 'lite'
(mavii)  ✘ ⚙ saurav@concave  ~/Music/Backup MAvi TFlite/examples/lite/examples/object_detection/raspberry_pi/ssd_v2   master  sudo python3 temp1.py
WARNING:tensorflow:From temp1.py:11: The name tf.lite.TocoConverter is deprecated. Please use tf.compat.v1.lite.TocoConverter instead.

2019-11-13 16:45:17.327502: I tensorflow/lite/toco/import_tensorflow.cc:659] Converting unsupported operation: TensorArrayV3
2019-11-13 16:45:17.327515: I tensorflow/lite/toco/import_tensorflow.cc:193] Unsupported data type in placeholder op: 20
2019-11-13 16:45:17.327525: I tensorflow/lite/toco/import_tensorflow.cc:659] Converting unsupported operation: TensorArrayV3

019-11-13 16:45:17.327790: I tensorflow/lite/toco/import_tensorflow.cc:659] Converting unsupported operation: TensorArrayWriteV3
2019-11-13 16:45:17.327826: I tensorflow/lite/toco/import_tensorflow.cc:659] Converting unsupported operation: TensorArrayGatherV3
2019-11-13 16:45:17.327839: I tensorflow/lite/toco/import_tensorflow.cc:659] Converting unsupported operation: TensorArrayGatherV3
2019-11-13 16:45:17.327857: I tensorflow/lite/toco/import_tensorflow.cc:659] Converting unsupported operation: TensorArrayWriteV3
2019-11-13 16:45:17.536546: I tensorflow/lite/toco/import_tensorflow.cc:659] Converting unsupported operation: NonMaxSuppressionV2

2019-11-13 16:45:18.604824: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After Removing unused ops pass 1: 4227 operators, 6921 arrays (0 quantized)
2019-11-13 16:45:19.305778: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 4227 operators, 6921 arrays (0 quantized)
2019-11-13 16:45:19.881638: F ./tensorflow/lite/toco/toco_tooling.h:38] Check failed: s.ok() Found StridedSlice as non-selected output from Switch, but only Merge supported. Control flow ops like Switch and Merge are not generally supported. We are working on fixing this, please see the Github issue at https://github.com/tensorflow/tensorflow/issues/28485.
Fatal Python error: Aborted

Current thread 0x00007f152ede6740 (most recent call first):
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/lite/toco/python/toco_from_protos.py", line 52 in execute
  File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 250 in _run_main
  File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 299 in run
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/platform/app.py", line 40 in run
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/lite/toco/python/toco_from_protos.py", line 89 in main
  File "/usr/local/bin/toco_from_protos", line 10 in <module>

请帮助我。我是tensorflowlite的新手。

0 个答案:

没有答案