GithubHelp home page GithubHelp logo

taka-wang / yolo-coreml Goto Github PK

View Code? Open in Web Editor NEW

This project forked from progrand/yolo-coreml

0.0 2.0 0.0 204 KB

Create and use YOLOv3 Neural Network on iOS

License: MIT License

Python 32.41% Shell 1.82% Swift 65.36% Metal 0.41%

yolo-coreml's Introduction

CoreML for YOLOv3 and YOLOv4

Quick Start

I will demonstrate, how to create and use realtime object detection engine using YOLO and iOS. For network creation i use Ubuntu 19.04 with NVidia GPU. For iOS conversion and compilation i use Monterey and Xcode 13.1.

  1. Get and compile darknet, i recommend AlexeyAB fork. Enable CUDA and OpenCV support.

  2. Prepare image dataset. My network is for detection of SCRATCHES on 224x224 input. Refer to darknet docs if you need your own objects. Split images into scratch/positives and scratch/negatives. Positives must contain images with objects and txt files with boxes. Negatives must contain images without objects and empty txt files. You can use Yolo_mark.

  3. Create yolo darknet model.

YOLOv3, YOLOv4, YOLOv4-TINY

Use this method for devices with iOS >= 13. Currently script generates iOS15 MLProgram mlpackage, but can be easily modified for iOS13 and mlmodel. YOLOv4-TINY work well. Suddenly, large YOLOv4 mlpackage takes minutes to loading on every iOS example app launch. At least on iPhone12 with iOS15.0.1

  1. coremltools is very sensitive to packages versions. This is why you need dedicated python anaconda environment. Install Anaconda from: https://repo.anaconda.com/archive/Anaconda3-5.3.1-MacOSX-x86_64.pkg.

  2. In Terminal enter conda environment (assuming anaconda installed to /anaconda3):

. /anaconda3/etc/profile.d/conda.sh
conda create -n coremltools-env python=3.7
conda activate coremltools-env
pip install yolov4==3.2.0
pip install opencv-python==4.5.4.60
pip install h5py==1.5.2
pip install coremltools==5.1.0
pip install keras==2.2.4
pip install tensorflow==2.5.0
  1. Prepare yolov4-tiny.cfg file (clear unsupported learning tags like subdivisions if any). Keep original yolov4-tiny.cfg for further trainings. Example:
sh ./prepare_cfg.sh yolov4-tiny.cfg yolov4-tiny_temp.cfg 
  1. Use prepared yolov4-tiny_temp.cfg. Convert:
python ./convert_v4.py -n coco.names -c yolov4-tiny_temp.cfg -w yolov4-tiny.weights -m yolov4.mlpackage -l RGB

YOLOv3, YOLOv3-TINY, YOLOv4-Mish for iOS12

Use this method for unsupported devices with iOS < 13. Also see appropriate iOS App example.

  1. Install Anaconda from: https://repo.anaconda.com/archive/Anaconda3-5.3.1-MacOSX-x86_64.pkg

  2. yolo -> coreml:

conda create -n yolo2coreml python=3.6 anaconda
conda activate yolo2coreml
conda install tensorflow=1.14.0
conda install keras=2.3.1
conda install coremltools=4.1
python convert_v4_old.py yolov4.cfg yolov4.weights yolov4.mlmodel
  1. You can use ios project as reference. Copy yolov4.mlmodel to project folder. Check anchors in yolov4.cfg and swift code. Change classes names and count, anchors, network size if you use your owns.

Performance

  • YOLOv3-Tiny 224x224 (SCRATCH) network takes about 25 ms per detection on iPhone X.
  • YOLOv4 old method 416x416 (COCO) network takes about 5 second per detection on iPhone 6.
  • YOLOv4 608x608 (COCO) network takes about 10 seconds per detection on iPhone 12.
  • YOLOv4-TINY 416x416 (COCO) network takes about 19 ms per detection on iPhone 12.

References


license

yolo-coreml's People

Contributors

progrand avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.