Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios CoreML模型不返回结果_Ios_Swift_Coreml - Fatal编程技术网

Ios CoreML模型不返回结果

Ios CoreML模型不返回结果,ios,swift,coreml,Ios,Swift,Coreml,我正在使用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 reques

我正在使用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")
    }

}
viewDidLoad()
中调用
predict()
方法


当在
displayPredictions()
中打印
results()
时,它返回空数组
[]
。我知道模型接受哪种格式的图像,他说这是128x128灰度,这可能是问题所在,如果是,我如何将
test.png
文件转换为128x128灰度。如果您对这个问题有任何其他想法,可能是使用coremltools或任何其他工具转换模型的问题,请让我知道。谢谢您的帮助。

这是分类模型吗?当您在Xcode中打开.mlmodel文件时,Core ML表示期望的输出是什么?请注意,Vision目前似乎不适用于非分类器的模型。是的,我相当确定它是一个分类器,该模型需要一个
图像
作为输入,并输出一个
多数组
。因此,我猜它会输出中的一个标签。我认为它与转换/输出本身有关,而与输入无关,因为即使我尝试使用模型在其上训练的一些数据,它仍然输出空数组。如果输出是
多数组
,则它不是分类器(在Core ML中)。Core ML中的分类器返回一个
String:Double
字典。转换模型时,是否指定了
class\u labels='map.txt'
?这是我使用的脚本:
import coremltools coreml\u model=coremltools.converters.caffe.convert('sketchANet\u full\u iter\u 7500.caffemodel','deploy.prototxt'),predicted\u feature\u name='map.txt',image\u input\u name='data')coreml\u model.save('sketch2.mlmodel'))
我应该尝试用
class\u labels='map.txt'
替换
predicted\u feature\u name='map.txt'
@MatthijsHollemansYes,
predicted\u feature\u name
是文档中的一个bug。它应该是
class\u标签