简体   繁体   中英

TensorFlow Lite Object Detection iOS does not work with custom trained model

I've trained my ssd_mobilenet_v2_quantized_300x300_coco_2019_01_03 object detection model. Everything went well. I have also converted it to.tflite file and named it detectx.tflite .

I downloaded the official ObjectDetection Example App and it runs smoothly with the inlcuded.tflite model.

I changed the code in ModelDataHandler.swift into the following:

enum MobileNetSSD {
  static let modelInfo: FileInfo = (name: "detectx", extension: "tflite")
  static let labelsInfo: FileInfo = (name: "labelmap", extension: "txt")
}

And certainly moved my detectx.tflite into the Model folder so it can be located.

However, when I tried to run the app, it crashed and gave the following error:

Failed to load the model file with name: detectx (lldb)

This is how I export my trained model to 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

and this is how I convert it to.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

This successfully produces the detectx.tflite as I wrote up there.

I don't understand why this would not work. I've tried many different ssd mobile net models and also produced the same error. Could anyone help me on this? I'm super baffled.

Thank you very much. I really appreciate any help.

I also faced the same error message Failed to load the model file with name: detectx (lldb) from Xcode on the sample project you used.

After debugging on Xcode, I came to realize that the model was simply not loaded into the project file, and I was able to solve the issue by following the step below on Xcode:

  1. Click your project
  2. Click your target
  3. Select Build Phases
  4. Expand Copy Bundle Resources
  5. Click '+' and select your model file

When dragging the file into the Xcode project make sure the app target is checked to make sure the reference to this file is set in the Copy Bundle Resources section in the Build Phases tab.

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