[SWIFT] [Machine learning] I tried Object Detection with Create ML [Object detection]

What I implemented this time

ダウンロード.gif

Preparation

This time, I tried the one that detects and identifies Coin as Gif at the beginning. What to prepare --About 100 data (Jpeg photos)

A rough type of machine learning

For machine learning ・ Image Classification ・ Sound Classification ・ Action Classification ・ Object Detection However, this time we will implement Object Detection, that is, detect objects.

What is Objet Detection?

Since Object Detection refers to detecting an object, it is necessary to judge "what is in the image". Therefore, "photograph" and "position information" are required. Take photos in advance and store them in folders. (Folder name = classification name) This time, we want to detect and identify coins, so we need a folder of 500 yen to 1 yen and the location information of each image. → Click here to find out more about Object Detection. Training Object Discovery Model in Create ML

procedure

--Collect data. (Take the photo you want to detect) --Classify the data collected using IBM Cloud Annotations (hereinafter referred to as IBMCA), specify the location information, and create a dataset. --Create Model by putting the file created by IBM CA in Create ML --Try Test on Create ML --Try it in an Apple sample

Take a photo (prepare data)

As for the photos, I prepared about 100 photos showing Coin this time. スクリーンショット 2020-09-26 19.10.21.jpg

Photo ・ Photos from various angles ・ Around 30 sheets are available for each of the three patterns of large, medium, and small sizes. ・ The background is unified and white

Create a dataset (JSON file)

Object Detection requires not only photos but also JSON files (because location information is required), so this time I used IBM Cloud Annotations account (free). Created. How to make it is as follows.

· Click Continue IBM Cloud

・ Click on a new project

・ Click localization

・ Enter the file name, and when the project starts, you will be able to D & D the photo, so enter it.

・ Drag to object (coin this time) and enclose it ・ Label name can be entered on the right side.

-The Label name once described can be selected from the down list on the upper left, so it is efficient to attach a Label to the Coin

・ After attaching Label to all photos, export from File so that it can be used in Create ML.

・ Success if this file is generated

-Check if there is a JSON file in the folder

Create Model with Create ML

Once the dataset is created, right click on Xcode and launch Create ML

Select object Detection and D & D the folder of the dataset file you created earlier. It seems that it is not good if the number of repetitions of learning training (I think) is large, but even if it is extremely small, the accuracy will not be obtained, so if it is sweet, try raising it a little and adjusting it. (I tried 300, 600, 1000 this time, but it didn't change.)

After learning, test it, and if there is no problem, take out the Model. (Can be taken out by D & D)

Try it out with Recognizing Objects in Live Capture

After that, download and open RecognizingObjectsInLiveCapture provided by Apple.

D & D the Model created by Create ML here

The code originally reads a model called Object Detector and is it a croissant or banana? Because there is something to detect and identify

guard let modelURL = Bundle.main.url(forResource: "ObjectDetector", withExtension: "mlmodelc")

To

guard let modelURL = Bundle.main.url(forResource: "coindetection", withExtension: "mlmodelc")

Implemented by rewriting to the model name generated this time

Is it generally successful? You can do everything from dataset to implementation in about 2 hours, so give it a try!

Finally

I used a sample this time, but since it's a big deal, I would like to challenge to make it with Swift UI in the future! In addition, I would like to take on the challenge of creating and implementing data sets related to machine learning, so if you are interested, please check this out as well!

Twitter https://twitter.com/oka_yuuji note https://note.com/oka_yuuji

I'm also a high school faculty member, but I love learning skills and researching! If you have a technical request or research, please contact us by DM below. https://twitter.com/oka_yuuji

Recommended Posts

[Machine learning] I tried Object Detection with Create ML [Object detection]
I tried Oracle's machine learning OSS "Tribuo"
I tried time-saving management learning with Studyplus.
I tried to make a machine learning application with Dash (+ Docker) part3 ~ Practice ~
I tried DI with Ruby
I tried Spring State machine
I tried UPSERT with PostgreSQL.
I tried BIND with Docker
I tried to create a java8 development environment with Chocolatey
[Rails] I tried to create a mini app with FullCalendar
I tried to create a padrino development environment with Docker
I tried using JOOQ with Gradle
I tried morphological analysis with MeCab
I tried to interact with Java
I tried UDP communication with Java
I tried to make a machine learning application with Dash (+ Docker) part2 ~ Basic way of writing Dash ~
I tried GraphQL with Spring Boot
I tried to summarize Java learning (1)
I tried Flyway with Spring Boot
I tried customizing slim with Scaffold
I tried learning Java with a series that beginners can understand clearly
[After learning Progate] I tried to summarize form_with while comparing with form_tag
I tried using Realm with Swift UI
I tried Cassandra's Object Mapper for Java
I tried to get started with WebAssembly
I tried using Scalar DL with Docker
I tried using OnlineConverter with SpringBoot + JODConverter
I tried playing with BottomNavigationView a little ①
Create a temporary class with new Object () {}
I tried using OpenCV with Java + Tomcat
I tried Lazy Initialization with Spring Boot 2.2.0
I tried to implement ModanShogi with Kinx
I tried to create a portfolio with AWS, Docker, CircleCI, Laravel [with reference link]
I tried to verify AdoptOpenJDK 11 (11.0.2) with Docker image
I tried to make Basic authentication with Java
I tried to manage struts configuration with Coggle
I tried to manage login information with JMX
I tried writing CRUD with Rails + Vue + devise_token_auth
I also tried WebAssembly with Nim and C
I tried to implement deep learning in Java
[Must see !!!] I tried to summarize object orientation!
I tried to create a LINE clone app
I tried Eclipse MicroProfile OpenAPI with WildFly Swarm
I tried to create Alexa skill in Java
I tried to break a block with java (1)
I tried Getting Started with Gradle on Heroku
I tried to create a shopping site administrator function / screen with Java and Spring
I tried text extraction (OCR) in Ruby using Vision API (Trained Machine Learning Model)
[Azure] I tried to create a Java application for free ~ Connect with FTP ~ [Beginner]