项目作者: appoly

项目描述 :
Swift package used to easily integrate classifier coreML models into your code.
高级语言: Swift
项目地址: git://github.com/appoly/IdentifyKit.git
创建时间: 2020-03-13T09:01:01Z
项目社区:https://github.com/appoly/IdentifyKit

开源协议:MIT License

下载


IdentifyKit

Swift package used to easily integrate classifier coreML models into your code.

Installing with cocoapods

  1. pod 'IdentifyKit'

Quick start

First start by creating a IdentifyKitDelegate, this will handle the result of any identification or failed identification.

  1. extension ViewController: IdentifyKitDelegate {
  2. func failedToInitialize(error: String) {
  3. print("Failed to initialize identifier request: \(error)")
  4. }
  5. func didIdentifyObject(name: String) {
  6. print("Identified: \(name)")
  7. }
  8. func identifying() {
  9. print("Identifying")
  10. }
  11. func failedToIdentifyObject() {
  12. print("Identification Failed")
  13. }
  14. }

Once you have your delegate setup, you can initialize your IdentyKit object. The initializer takes 3 arguments:

  • The delegate which we declare above.
  • The desired accuracy, which is a float between 0 & 1, will be used to filter out any identifications that are less accurate than this value.
  • The model, which can be any image classification model. We’ve used MobileNet in this example.

let classifier = IdentifyKit(delegate: self, accuracy: Configuration.accuracy, model: MobileNet().model)

Once this is done you can make a request:

  1. func identify(image: UIImage) {
  2. func identify(image: UIImage) {
  3. let image = UIImage()
  4. guard let data = image.pngData() else { return }
  5. classifier.identify(data)
  6. }
  7. }