无法将类型'()-> _'的值转换为指定的类型'VNCoreMLRequest'

时间:2018-12-18 15:10:04

标签: ios swift coreml

努力解决此错误,无法弄清楚代码出了什么问题 screenshot

lazy var classificationRequest : VNCoreMLRequest = {

    do {
        let model = try VNCoreMLModel(for: AnimalClassifier().model)

        let request = VNCoreMLRequest(model: model, completionHandler: { (req, err) in

            self.processClassifications(for : req, error : err )
        })

        request.imageCropAndScaleOption = .centerCrop
        return request

    } catch {
        fatalError("Failed to load Vision ML model!\(error)")
    }
}

func processClassifications(for request : VNRequest, error : Error?){

    guard let classifications = request.results as? [VNClassificationObservation] else {
        self.classificationLabel.text = "Unable to classify image.\n\(error?.localizedDescription ?? "Error")"
        return
    }

    if classifications.isEmpty {
        self.classificationLabel.text = "Nothing recognized."
    } else {
        let topClassification = classifications.prefix(2)
        let descriptions = topClassification.map { classification in
            return String(format: "%.2f", classification.confidence * 100) + "% - " + classification.identifier
        }
        self.classificationLabel.text = "Classifications:\n" + descriptions.joined(separator: "\n")
    }

}

自动补全功能无法正常运行,因此我认为某些参数存在问题,但我不知道如何解决。

0 个答案:

没有答案