services | platforms | author |
---|---|---|
cognitive-services,custom-vision |
Objective-C, iOS |
kojiw |
This sample application demonstrates how to take a model exported from the Custom Vision Service in the CoreML format and add it to an application for real-time image classification.
- XCode 10
- CocoaPods
- iOS device running iOS 11 or later
- An account at Custom Vision Service
- Clone the repository
- Run
pod install
- Open the xcworkspace
CVS_ClassifierSample
in Xcode - Build and run the sample on your iOS device
The model provided with the sample recognizes some fruits. To replace it with your own model exported from Custom Vision Service do the following, and then build and launch the application:
-
Create and train a classifer with the Custom Vision Service. You must choose a "compact" domain such as General (compact) to be able to export your classifier. If you have an existing classifier you want to export instead, convert the domain in "settings" by clicking on the gear icon at the top right. In setting, choose a "compact" model, Save, and Train your project.
-
Export your model by going to the Performance tab. Select an iteration trained with a compact domain, an "Export" button will appear. Click on Export then CoreML then Export. Click the Download button when it appears. A .zip file will download that contains all of these three files:
- CoreML model (
.mlmodel
) - Export manifest file (
cvexport.manifest
).
- CoreML model (
-
Drop
model.mlmodel
andcvexport.manifest
into your Xcode project's Fruit folder. -
Build and run.
This sample has been tested on iPhone devices
This latest sample application relies on the new iOS library Custom Vision inference run-time (or simply run-time) to take care of compatibility. It handles:
-
Version check: Check the version of the exported model by looking at
cvexport.manifest
(more specifically, look for ExporterVersion field) and switch logic depending on model version.-
Fowrard compatibility: It is when model version is newer than run-time's maximum supported model version.
-
Major version is greater: Throw exception (supposing model format is unknown)
-
Major version is same but minor version is greater: Still works. Run inference.
-
-
Backward compatiblity: Any newer version of the run-time should be able to handle older model versions.
-
Run-time version | Model version |
---|---|
Run-time 1.0.0 | Work with model version 1.x |
Work with model version 2.x | |
Not work with model version 3.0 or higher |
- Link to CoreML documentation
- Link Apple WWDC videos, samples, and materials for information on CoreML and Vision Framework
- Link to Custom Vision Service Documentation