我正在使用this CoreML模型来测试草图识别,但它没有返回任何结果 . 这是我的代码:

func predict(){
    guard let image = UIImage(named: "test.png") else{
        print("Image not found")
        return
    }
    do{
        let model = try VNCoreMLModel(for: sketch2().model)
        let request = VNCoreMLRequest(model: model, completionHandler: displayPredictions)
        let handler = VNImageRequestHandler(cgImage: (image.cgImage!))
        try handler.perform([request])
    }catch{

    }
}

func displayPredictions(request: VNRequest, error: Error?) {

    if let results = request.results as? [VNClassificationObservation]{
        print(results)
    }else{
        print("some error")
    }

}

predict() 方法在 viewDidLoad() 中调用 .

results()displayPredictions() 中打印时,它返回空数组 [] . 我asked the developer of the model模型接受的图像格式是什么,他说它是128x128灰度,这可能是问题,如果是这样,我怎么能将 test.png 文件转换为128x128灰度 . 如果您对该问题有任何其他想法,可能是使用coremltools或其他任何东西转换模型的问题,请告诉我 . 谢谢你的帮助 .