If you want to use this code. You will need to update a few variables for your model. See YOLO.swift and Helpers.swift for more details.
This repo was forked and modified from syshen/YOLO-CoreML. Some changes I made:
- Updated to work with Yolo v5.
- Added comments that explain how to grab stride, anchors, and other data from an exported model.
- Updated the code to work on all output layers instead of just the first one.
This works on their model as of June 23, 2021.
A working example model can be found here. But do note that this model was trained to predict Lego pieces not the same labels as in syshen. And there have been changes in this repository that aren't compatible with syshen's models:
- Label names have been changed in Helpers.swift
- Layers are named differently (now they are _714, _727, _740) in Yolo.swift
At a minimum you will likely have to change the label names to be compatible with your model.
YOLO is an object detection network. It can detect multiple objects in an image and puts bounding boxes around these objects. Read hollance's blog post about YOLO to learn more about how it works.
In this repo you'll find:
- YOLO-CoreML: A demo app that runs the YOLO neural network on Core ML.
- Converter: The scripts needed to convert the original DarkNet YOLO model to Core ML.
To run the app:
- execute download.sh to download the pre-trained model
% sh download.sh
- open the xcodeproj file in Xcode 9 and run it on a device with iOS 11 or better installed.
The reported "elapsed" time is how long it takes the YOLO neural net to process a single image. The FPS is the actual throughput achieved by the app.
NOTE: Running these kinds of neural networks eats up a lot of battery power. The app can put a limit on the number of times per second it runs the neural net. You can change this in
setUpCamera()
by changing the linevideoCapture.fps = 50
to a smaller number.
NOTE: You don't need to convert the models yourself. Everything you need to run the demo apps is included in the Xcode projects already.
If you're interested in how the conversion was done, check the instructions.