cafielo / Mnistkit
Programming Languages
Labels
Projects that are alternatives of or similar to Mnistkit
MNISTKit
MNISTKit makes it easy to deal with MNIST model.
MNISTKit is a library for digit detection with coreml model. The rise of A.I. is grounded in the success of deep learning. The “hello world” for deep learning is the MNIST model for handwritten digit recognition.
Long way to use CoreML
There are some works to implement MNIST with CoreML Framework
- Build a model
- Convert to mlmodel
- Make a hand writable UIView
- Convert hand writable view to image and resize it
- Get pixelbuffers from resized image
- Predict the image with mlmodel using pixelbuffer
MNISTKit makes it easy to deal with MNIST model.
Requirements
- iOS 11.0+
- Xcode 9.0+
- Swift 4.0+
Installation
CocoaPods
CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:
$ gem install cocoapods
To integrate MNISTKit into your Xcode project using CocoaPods, specify it in your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
target '<Your Target Name>' do
pod 'MNISTKit'
end
Then, run the following command:
$ pod install
Carthage
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate Windless into your Xcode project using Carthage, specify it in your Cartfile
:
github "cafielo/MNISTKit"
Run carthage update
to build the framework and drag the built MNISTKit.framework
into your Xcode project.
Manually
If you prefer not to use either of the aforementioned dependency managers, you can integrate MNISTKit into your project manually.
Usage
- Drag a UIView the desired size of your player onto your Storyboard.
- Change the UIView's class in the Identity Inspector tab to
MNISTDrawingView
. - Import
MNISTKit
in your ViewController. - Add the following property to your ViewController.
@IBOutlet weak var drawingView: MNISTDrawingView!
- Creat a
MNISTModelController
to predict later.
let mnistModelController = MNISTModelController()
- Detect hand written digit using
MNISTModelController
andMNISTDrawingView
.
@IBAction func predict(_ sender: UIButton) {
guard let image = drawingView.image else {
return
}
guard let predictedNum = mnistModelController.predictNum(image: image) else {
return
}
numLabel.text = "\(predictedNum) is predicted"
}
Example
Following code is a simple example
import UIKit
import MNISTKit
class ViewController: UIViewController {
@IBOutlet weak var drawingView: MNISTDrawingView!
@IBOutlet weak var numLabel: UILabel!
let mnistModelController = MNISTModelController()
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func predict(_ sender: UIButton) {
guard let image = drawingView.image else {
return
}
guard let predictedNum = mnistModelController.predictNum(image: image) else {
return
}
numLabel.text = "\(predictedNum) is predicted"
}
@IBAction func clear(_ sender: UIButton) {
drawingView.clear()
numLabel.text = "???"
}
}
Credits
- Joonwon Lee (@joonwonlee)
License
MNISTKit is released under the MIT license. See LICENSE for details.