我已经训练了我的 ssd_mobilenet_v2_quantized_300x300_coco_2019_01_03 对象检测模型。一切顺利。我还将其转换为 .tflite 文件并将其命名为 detectx.tflite。
我下载了 official ObjectDetection Example App并且它可以与包含的 .tflite 模型一起顺利运行。
我将 ModelDataHandler.swift
中的代码更改为以下内容:
enum MobileNetSSD {
static let modelInfo: FileInfo = (name: "detectx", extension: "tflite")
static let labelsInfo: FileInfo = (name: "labelmap", extension: "txt")
}
当然,也将我的 detectorx.tflite 移至 Model
文件夹中,以便可以找到它。
但是,当我尝试运行该应用程序时,它崩溃并出现以下错误:
无法加载名称为: detectorx (lldb) 的模型文件
这就是我将训练好的模型导出到 tflite_graph.pb 的方法:
python export_tflite_ssd_graph.py \
--pipeline_config_path training/ssd_mobilenet_v2_quantized_300x300_coco.config \
--trained_checkpoint_prefix training/model.ckpt-145 \
--output_directory inference_graph_TFLITE_COBA
这就是我将其转换为 .tflite 的方法:
tflite_convert --graph_def_file=inference_graph_TFLITE_COBA/tflite_graph.pb --output_file=detectx.tflite
--input_shapes=1,300,300,3 --input_arrays=normalized_input_image_tensor
--output_arrays=TFLite_Detection_PostProcess,TFLite_Detection_PostProcess:1,TFLite_Detection_Post
Process:2,TFLite_Detection_PostProcess:3 --allow_custom_ops
这成功地生成了detectx.tflite,正如我在那里所写的。
我不明白为什么这行不通。我尝试了许多不同的 SSD 移动网络模型,也产生了相同的错误。有人能帮我解决这个问题吗?我 super 困惑。
非常感谢。我真的很感谢任何帮助。
最佳答案
我在您使用的示例项目上也遇到了相同的错误消息无法从 Xcode 加载名称为:Detectx (lldb) 的模型文件
。
在 Xcode 上调试后,我发现模型根本没有加载到项目文件中,我可以通过在 Xcode 上执行以下步骤来解决该问题:
- 点击您的项目
- 点击您的目标
- 选择构建阶段
- 扩展副本捆绑资源
- 点击“+”并选择您的模型文件
关于python - TensorFlow Lite 对象检测 iOS 不适用于自定义训练模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58171385/