Skip to content

iamjeerge/ios-object-detection-yolov5

Repository files navigation

YoloV5 Object Detection IOS Implementation

Let's Code for Inference, Training and deploy Trained Custom Model in APP

Build Status

Clone Repo

git clone https://github.com/iamjeerge/ios-object-detection-yolov5.git
cd ios-object-detection-yolov5

1. Generate Yolo V5 Model for IOS

The Python script export.py in the models folder of the YOLOv5 repo is used to generate a TorchScript-formatted YOLOv5 model named yolov5s.torchscript.ptl for mobile apps.

Open a Mac/Linux/Windows Terminal, run the following commands:

git clone https://github.com/ultralytics/yolov5
cd yolov5
pip install -r requirements.txt wanb

Note the steps below have been tested with the commit cd35a009ba964331abccd30f6fa0614224105d39 and if there's any issue with running the script or using the model, try git reset --hard cd35a009ba964331abccd30f6fa0614224105d39.

Edit export.py to make the following two changes:

  • After f = file.with_suffix('.torchscript.pt'), add a line fl = file.with_suffix('.torchscript.ptl')

  • After (optimize_for_mobile(ts) if optimize else ts).save(f), add (optimize_for_mobile(ts) if optimize else ts)._save_for_lite_interpreter(str(fl))

Finally, run the script below to generate the optimized TorchScript Lite Interpreter model and copy the generated model file yolov5s.torchscript.ptl to the ios-demo-app/ObjectDetection/ObjectDetection folder (the original full JIT model yolov5s.torchscript.pt was also generated for comparison):

python export.py --weights yolov5s.pt --include torchscript

Note that small sized version of the YOLOv5 model, which runs faster but with less accuracy, is generated by default when running the export.py. You can also change the value of the weights parameter in the export.py to generate the medium, large, and extra large version of the model.

2. Use LibTorch-Lite

Run the commands below:

pod install
open ObjectDetection.xcworkspace/

3. Run the app

Select an iOS simulator or device on Xcode to run the app. You can go through the included example test images to see the detection results.

YOLO V5 Network Image

plot

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published