• swift开发笔记28 CoreML


    {

      func detectScene(image: CIImage) {

        answerLabel.text = "detecting scene..."

        

        // Load the ML model through its generated class

        guard let model = try? VNCoreMLModel(for: GoogLeNetPlaces().model) else {

          fatalError("can't load Places ML model")

        }

        

        // Define a Vision request service with the ML model

        let request = VNCoreMLRequest(model: model) { [weak self] request, error in

          guard let results = request.results,

            let topResult = results.first as? VNClassificationObservation else {

              fatalError("unexpected result type from VNCoreMLRequest")

          }

          

          // Update UI on main queue

          let article = (["a", "e", "i", "o", "u"].contains(topResult.identifier.first!)) ? "an" : "a"

          

          DispatchQueue.main.async { [weak self] in

            self?.answerLabel.text = "(Int(topResult.confidence * 100))% it's (article) (topResult.identifier)"

          }

        }

        

        // Create a request handler with the image provided

        let handler = VNImageRequestHandler(ciImage: image)

        

        // Perform the request service with the request handler

        DispatchQueue.global(qos: .userInteractive).async {

          do {

            try handler.perform([request])

          } catch {

            print(error)

          }

        }

      }

    }

  • 相关阅读:
    B-Tree索引的学习记录
    mysql NOW,CURRENT_TIMESTAMP,SYSDATE 之间的区别
    哈希索引
    MyISAM和InnoDB的区别
    负载均衡记录一
    哈希索引
    mysql ZEROFILL属性
    redis常用命令及使用场景
    js Function()构造函数
    书写闭包的时候需注意一下情况
  • 原文地址:https://www.cnblogs.com/dengchaojie/p/8215673.html
Copyright © 2020-2023  润新知