Home

Awesome

ObjectDetection-CoreML

supporting models: YOLOv8, YOLOv5, YOLOv3, MobileNetV2+SSDLite

platform-ios swift-version lisence

This project is Object Detection on iOS with Core ML.<br>If you are interested in iOS + Machine Learning, visit here you can see various DEMOs.<br>SSDMobileNetV2-DEMO

Requirements

How To Build and Run the Project

1. Clone the project

git clone https://github.com/tucan9389/ObjectDetection-CoreML

2. Prepare Core ML model

Or if you want to make and use model with custom dataset,

  1. follow roboflow tutorial from scratch or yolov5 repo's tutorial
  2. and convert the .pt model to .mlmodel model with our issue.

3. Add the model to the project

By default, the project uses the yolov8s model. If you want to use another model, you can replace the model file in the project.

<img width="1305" alt="Screen Shot 2022-09-03 at 9 48 43 AM" src="https://user-images.githubusercontent.com/37643248/188249381-391d494d-47f0-4bd7-b70b-88809a2d7f04.png"> <img width="560" alt="Screen Shot 2022-09-03 at 9 46 19 AM" src="https://user-images.githubusercontent.com/37643248/188249388-6b29075b-0d02-4421-addd-e8b830613728.png">

4. Set model name properly in ViewController.swift

<img width="640" alt="image" src="https://user-images.githubusercontent.com/37643248/188249496-20ba838c-7f0f-4457-adac-2fa11344c7de.png">

5. Build and Run

How To Run with your own model

1. Convert your model to Core ML

At this moment(23.04.08), there is error when converting yolov8 models to Core ML. Once https://github.com/ultralytics/ultralytics/pull/1791 is merged, you can use the following steps. (Or you can use this PR alternatively.)

Pre-requirements

pip install ultralytics
pip install coremltools

Option 1) With shell

yolo export model=yolov8n.pt format=coreml nms

Option 2) With python script

# mian.py
from ultralytics import YOLO

if __name__ == '__main__':
    model = YOLO("yolov8n.pt", task='detect')  # load a pretrained model
    model.overrides['nms'] = True
    success = model.export(format="coreml")  # export the model to CoreML format
# in terminal
python main.py
# then you can see the `.mlpackage` or `.mlmodel` file in your current directory
# (btw you can check your current directory with `pwd` command)

2. Follow the steps above from Step 3

Models

Model Matadata

<img width="640" alt="image" src="https://user-images.githubusercontent.com/37643248/230690729-ed084be1-f6d6-42a3-b72a-3b5987143bbc.png">

Model Size, Minimum iOS Version, Download Link

ModelSize<br>(MB)Minimum<br>iOS VersionDownload<br>LinkTrained Dataset
yolov8n.mlmodel12.7iOS14Link
yolov8s.mlmodel44.7iOS14Link
yolov8m.mlmodel52.1iOS14Link
yolov8l.mlmodel87.8iOS14Link
yolov8x.mlmodel272.9iOS14Link
yolov5n.mlmodel7.52iOS13LinkCOCO
yolov5s.mlmodel28.0iOS13LinkCOCO
yolov5m.mlmodel81.2iOS13LinkCOCO
yolov5l.mlmodel178.0iOS13LinkCOCO
yolov5x.mlmodel331.0iOS13LinkCOCO
yolov5n6.mlmodel12.8iOS13LinkCOCO
yolov5s6.mlmodel48.5iOS13LinkCOCO
yolov5m6.mlmodel137.0iOS13LinkCOCO
yolov5l6.mlmodel293.0iOS13LinkCOCO
yolov5x6.mlmodel537.0iOS13LinkCOCO
YOLOv3.mlmodel248.4iOS12LinkCOCO
YOLOv3FP16.mlmodel124.2iOS12LinkCOCO
YOLOv3Int8LUT.mlmodel62.2iOS12LinkCOCO
YOLOv3Tiny.mlmodel35.5iOS12LinkCOCO
YOLOv3TinyFP16.mlmodel17.8iOS12LinkCOCO
YOLOv3TinyInt8LUT.mlmodel8.9iOS12LinkCOCO
MobileNetV2_SSDLite.mlmodel9.3iOS12LinkCOCO
ObjectDetector.mlmodel63.7iOS12Link6 Label Dataset

Trained Dataset Infos

<details> <summary>COCO Dataset</summary> </details> <details> <summary>6 Label Dataset(Apple's DEMO) </summary> </details>

Performance

Build Setting:<br> Xcoede > Build Settings > Apple Clang - Code Generation > Optimization Level > Fastest [-O3]

<img width="560" alt="Screen Shot 2022-09-05 at 4 31 08 PM" src="https://user-images.githubusercontent.com/37643248/188393214-d2e822a6-73b2-4971-a46d-27cdbfc8c61c.png">

Infernece Time (ms)

Model vs. Device14<br>Pro13<br>Pro12<br>Pro11<br>ProXSXS<br>MaxXRX7+7
yolov8n15
yolov8s29
yolov8m37
yolov8l45
yolov8x51
yolov5n24
yolov5s29
yolov5m39
yolov5l38
yolov5x69
yolov5n624
yolov5s634
yolov5m639
yolov5l641
yolov5x657
YOLOv3458310893100356569561
YOLOv3FP16448410489101348572565
YOLOv3Int8LUT538610192100337575572
YOLOv3Tiny3644464147106165168
YOLOv3TinyFP163344514144103165167
YOLOv3TinyInt8LUT3944453939106160161
MobileNetV2_SSDLite1718313131109141134
ObjectDetector1318242623638684

Total Time (ms)

Model vs. Device14<br>Pro13<br>Pro12<br>Pro11<br>ProXSXS<br>MaxXRX7+7
yolov8n15
yolov8s31
yolov8m39
yolov8l47
yolov8x52
yolov5n26
yolov5s31
yolov5m41
yolov5l39
yolov5x72
yolov5n625
yolov5s636
yolov5m641
yolov5l642
yolov5x659
YOLOv3468410893100357569561
YOLOv3FP16458510489101348572565
YOLOv3Int8LUT548610292102338576573
YOLOv3Tiny3745464248106166169
YOLOv3TinyFP163545514144104165167
YOLOv3TinyInt8LUT4145453940107160161
MobileNetV2_SSDLite1919323132109142134
ObjectDetector1418252623648785

FPS

Model vs. Device14<br>Pro13<br>Pro12<br>Pro11<br>ProXSXS<br>MaxXRX7+7
yolov8n38
yolov8s14
yolov8m14
yolov8l14
yolov8x13
yolov5n19
yolov5s14
yolov5m13
yolov5l14
yolov5x7
yolov5n619
yolov5s614
yolov5m613
yolov5l614
yolov5x613
YOLOv31298109211
YOLOv3FP161399108211
YOLOv3Int8LUT1499109211
YOLOv3Tiny1414212220855
YOLOv3TinyFP161414192321955
YOLOv3TinyInt8LUT1114212423855
MobileNetV2_SSDLite1929232323866
ObjectDetector1729232324141011

See also