Skip to content

object detection using yolov8 model for ios #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions mobile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ The example app uses object detection which is able to continuously detect the o
- [iOS Object Detection](examples/object_detection/ios)
- [Android Object Detection](examples/object_detection/android)

### Object Detection using yolov8

This example app use yolov8 model to identify objects in images and provides bounding boxes, identified class and score.

- [iOS Object Detection (yolov8)](examples/object_detection_yolov8/ios)

### Xamarin VisionSample

The [Xamarin.Forms](https://dotnet.microsoft.com/apps/xamarin/xamarin-forms) example app demonstrates the use of several vision-related models, from the ONNX Model Zoo collection.
Expand Down
21 changes: 21 additions & 0 deletions mobile/examples/object_detection_yolov8/ios/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Eumentis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
41 changes: 41 additions & 0 deletions mobile/examples/object_detection_yolov8/ios/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## ONNX Runtime Mobile object detection iOS sample application

This sample application makes use of Yolov8 object detection model to identify objects in images and provides identified class, bounding boxes and score as a result.


### Model
We use pre-trained yolov8 model in this sample app. The original yolov8n.pt model can be downloaded. [Here](https://github.com/ultralytics/assets/releases/download/v8.1.0/yolov8n.pt) <br/>
- We converted this yolov8n.pt model to yolov8n.onnx using https://docs.ultralytics.com/modes/export/#usage-examples <br/>
- Generated yolov8n.ort from yolov8n.onnx using https://onnxruntime.ai/docs/performance/model-optimizations/ort-format-models.html#convert-onnx-models-to-ort-format

### Requirements
- Install Xcode 12.5 and above (preferably latest version)

### Steps to build and run

#### Step 1: Clone the ONNX runtime mobile examples source code

Clone this repository to get the sample application. Then open the project under the folder `mobile\examples\object_detection_yolov8\ios`.


#### Step 2: Install app

1. In terminal, run pod install under onnxruntime-object-detection-yolo-ios/yolo-ios to generate the workspace file.
- At the end of this step, you should get a file called yolo-ios.xcworkspace.
2. Open onnxruntime-object-detection-yolo-ios/yolo-ios/yolo-ios.xcworkspace in Xcode and make sure to select your corresponding development team under Target-General-Signing for a proper codesign

#### Step 3: Connect IOS Device and Run the app
Connect your IOS Device to your computer or select the IOS Simulator in Xcode.

Then after running this app it will be installed on your device or simulator.

Now you can try and test the object detection IOS app by
1. Click the "+" button from top, it will open your photo album, pick any image that you want to test.
2. Your selected image will be shown on the screen. Then click the "Start Processing" button, and it will begin identifying objects in the image/photo. The loader will appear on the screen while the image is being processed.
3. After completion, you'll see an image with bounding boxes and the identified class name.

#
Here are some sample example screenshots of the app.

<img width=20% src="yolo-ios/yolo-ios/images/IMG_1139.PNG" alt="App Screenshot 1" />
<img width=20% src="yolo-ios/yolo-ios/images/IMG_1140.PNG" alt="App Screenshot 2" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/Pods/
.DS_Store
22 changes: 22 additions & 0 deletions mobile/examples/object_detection_yolov8/ios/yolo-ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'yolo-ios' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!

# Pods for yolo-ios

target 'yolo-iosTests' do
inherit! :search_paths
# Pods for testing
end

target 'yolo-iosUITests' do
# Pods for testing
end

# Pods for ORTObjectDetection
pod 'onnxruntime-objc'

end
22 changes: 22 additions & 0 deletions mobile/examples/object_detection_yolov8/ios/yolo-ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
PODS:
- onnxruntime-c (1.17.1)
- onnxruntime-objc (1.17.1):
- onnxruntime-objc/Core (= 1.17.1)
- onnxruntime-objc/Core (1.17.1):
- onnxruntime-c (= 1.17.1)

DEPENDENCIES:
- onnxruntime-objc

SPEC REPOS:
trunk:
- onnxruntime-c
- onnxruntime-objc

SPEC CHECKSUMS:
onnxruntime-c: 58803cb3fcc1fb0a7baa9b16b2bad119d6e3eb78
onnxruntime-objc: 089530244113a131305642b7e03fa6f8a9ee9ae6

PODFILE CHECKSUM: 9379fba48d706acf709a30decc58da0f9ab2b681

COCOAPODS: 1.14.3
Loading