Coder Social home page Coder Social logo

nilportugues / visual-recognition-coreml Goto Github PK

View Code? Open in Web Editor NEW

This project forked from watson-developer-cloud/visual-recognition-coreml

0.0 2.0 0.0 181.23 MB

Classify images offline using Watson Visual Recognition and Core ML

License: Apache License 2.0

Swift 100.00%

visual-recognition-coreml's Introduction

Visual Recognition with Core ML

Classify images with Watson Visual Recognition and Core ML. The images are classified offline using a deep neural network that is trained by Visual Recognition.

This project includes the QuickstartWorkspace.xcworkspace workspace with two projects:

  • Core ML Vision Simple: Classify images locally with Visual Recognition.
  • Core ML Vision Custom: Train a custom Visual Recognition model for more specialized classification.

Before you begin

Make sure that you have installed Xcode 9 or later and iOS 11.0 or later. These versions are required to support Core ML.

Getting the files

Use GitHub to clone the repository locally, or download the .zip file of the repository and extract the files.

Running Core ML Vision Simple

Identify common objects with a built-in Visual Recognition model. Images are classified with the Core ML framework.

  1. Open QuickstartWorkspace.xcworkspace in Xcode.
  2. Select the Core ML Vision Simple scheme.
  3. Run the application in the simulator or on your device.
  4. Classify an image by clicking the camera icon and selecting a photo from your photo library. To add a custom image in the simulator, drag the image from the Finder to the simulator window.

Tip: This project also includes a Core ML model to classify trees and fungi. You can switch between the two included Core ML models by uncommenting the model you would like to use in ImageClassificationViewController.

Source code for ImageClassificationViewController.

Running Core ML Vision Custom

The second part of this project builds from the first part and trains a Visual Recognition model (also called a classifier) to identify common types of cables (HDMI, USB, etc.). Use the Watson Swift SDK to download, manage, and execute the trained model. By using the Watson Swift SDK, you don't have to learn about the underlying Core ML framework.

Setting up Visual Recognition in Watson Studio

  1. Log into Watson Studio. From this link you can create an IBM Cloud account, sign up for Watson Studio, or log in.

  2. After you sign up or log in, you'll be on the Visual Recognition instance overview page in Watson Studio.

    Tip: If you lose your way in any of the following steps, click the IBM Watson logo on the top left of the page to bring you to the the Watson Studio home page. From there you can access your Visual Recognition instance by clicking the Launch tool button next to the service under "Watson services".

Training the model

  1. In Watson Studio on the Visual Recognition instance overview page, click Create Model in the Custom box.

  2. If a project is not yet associated with the Visual Recognition instance you created, a project is created. Name your project Custom Core ML and click Create.

    Tip: If no storage is defined, click refresh.

  3. Upload each .zip file of sample images from the Training Images directory onto the data pane on the right side of the page. Add the hdmi_male.zip file to your model by clicking the Browse button in the data pane. Also add the usb_male.zip, thunderbolt_male.zip, and vga_male.zip files to your model.

  4. After the files are uploaded, select Add to model from the menu next to each file, and then click Train Model.

Copy your Model ID and API Key

  1. In Watson Studio on the custom model overview page, click your Visual Recognition instance name (it's next to Associated Service).
  2. Scroll down to find the Custom Core ML classifier you just created.
  3. Copy the Model ID of the classifier.
  4. In the Visual Recognition instance overview page in Watson Studio. Click the Credentials tab, and then click View credentials. Copy the api_key of the service.

Adding the classifierId and apiKey to the project

  1. Open the project in XCode.
  2. Copy the Model ID and paste it into the classifierID property in the ImageClassificationViewController file.
  3. Copy your api_key and paste it into the apiKey property in the ImageClassificationViewController file.

Downloading the Watson Swift SDK

Use the Carthage dependency manager to download and build the Watson Swift SDK.

  1. Install Carthage.

  2. Open a terminal window and navigate to the Core ML Vision Custom directory.

  3. Run the following command to download and build the Watson Swift SDK:

    carthage bootstrap --platform iOS

Tip: Regularly download updates of the SDK so you stay in sync with any updates to this project.

Testing the custom model

  1. Open QuickstartWorkspace.xcworkspace in Xcode.

  2. Select the Core ML Vision Custom scheme.

  3. Run the application in the simulator or on a device.

  4. Classify an image by clicking the camera icon and selecting a photo from your photo library. To add a custom image in the simulator, drag the image from the Finder to the simulator window.

  5. Pull new versions of the visual recognition model with the refresh button in the bottom right.

    Tip: The classifier status must be Ready to use it. Check the classifier status in Watson Studio on the Visual Recognition instance overview page.

Source code for ImageClassificationViewController.

What to do next

Add another Watson service to the custom project with the Core ML Visual Recognition with Discovery project.

Resources

visual-recognition-coreml's People

Contributors

glennrfisher avatar iainm22 avatar mediumtaj avatar sirspidey avatar

Watchers

 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.