我没有使用tensorflow的经验。我正在使用tensorflow 2.3.0创建一个带有自定义数据集的对象检测模型。我使用的模型是"ssd_mobilenet_v2_fpnlite_640x640_coco17_tpu-8".加载经过训练的检查点,我可以使用它来检测图像中的对象,效果很好。
现在,我使用以下命令以SavedModel格式保存了模型:python export_tflite_graph_tf2.py --trained_checkpoint_dir training --output_directory inference_graph_tflite --pipeline_config_path training/ssd_mobilenet_v2_fpnlite_640x640_coco17_tpu-8.config
然后,我使用以下代码将模型转换为TFLite格式:
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8,
tf.lite.OpsSet.TFLITE_BUILTINS]
tflite_model = converter.convert()
with open(path + 'final_detector.tflite', 'wb') as f:
f.write(tflite_model)
这段代码来自tensorflow文档。(https://www.tensorflow.org/api_docs/python/tf/lite/TFLiteConverter)
如果我试图解释这个模型,我会得到这个错误:
File "...\python\interpreter.py", line 197, in __init__
_interpreter_wrapper.CreateWrapperFromFile(
ValueError: Did not get operators, tensors, or buffers in subgraph 0.
我做错了什么?
发布于 2020-09-25 20:09:35
我终于找到了我所有问题的根源。虽然我刚刚阅读了tensorflow文档,但在使用tensorflow 2.3.0时,您需要将tflite降级到版本2.2.0。重新构建tflite模型是可行的。
发布于 2020-09-25 14:17:32
您是否可以使用netron等工具检查图表是否已正确转换
https://stackoverflow.com/questions/64050449
复制相似问题