zoukankan      html  css  js  c++  java
  • 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)

          }

        }

      }

    }

  • 相关阅读:
    原生js实现基本选择器
    javascript数组
    web中关于隐藏与显示
    CSS3 box-shadow(阴影使用)
    java中文件的I/O操作
    组件RecyclerView的应用(一)
    Android客户端与Eclipse服务器端的Socket通信
    C语言关于利用sscanf实现字符串相加减
    TabLayout和ViewPager简单实现页卡的滑动
    DrawerLayout的openDrawer()和closeDrawer()方法
  • 原文地址:https://www.cnblogs.com/dengchaojie/p/8215673.html
Copyright © 2011-2022 走看看