Swift 无法使用coreML对手绘图像进行分类

Swift 无法使用coreML对手绘图像进行分类,swift,core-image,coreml,Swift,Core Image,Coreml,我正在尝试使用coreML对手绘图像进行分类。我的模型能够对从画廊拍摄的图像进行分类。但是当我传递使用“UIGraphicsGetImageFromCurrentImageContext”拍摄的手绘图像时,我的模型无法分类。有人能帮我找到错误吗 UIGraphicsBeginImageContext(bottomImageView.frame.size) bottomImageView.image?.draw(in: view.bounds, blendMode: .normal, alph

我正在尝试使用coreML对手绘图像进行分类。我的模型能够对从画廊拍摄的图像进行分类。但是当我传递使用“UIGraphicsGetImageFromCurrentImageContext”拍摄的手绘图像时,我的模型无法分类。有人能帮我找到错误吗

 UIGraphicsBeginImageContext(bottomImageView.frame.size)
 bottomImageView.image?.draw(in: view.bounds, blendMode: .normal, alpha: 1.0)
 bottomImageView.image = UIGraphicsGetImageFromCurrentImageContext()
 UIGraphicsEndImageContext()
   
我使用上面的代码在当前上下文中绘制图像

let image = bottomImageView.image 
   if  let reqImage = image.cgImage {
        do {
            let model1 = try VNCoreMLModel(for: ImageClassifier().model)
            let request = VNCoreMLRequest(model: model1, completionHandler: myResultsMethod)
            let handler = VNImageRequestHandler(cgImage: reqImage)
            try handler.perform([request])
            
        } catch {
            print("error")
        }
    }
 func myResultsMethod(request: VNRequest, error: Error?) {
        guard let results = request.results as? [VNClassificationObservation]
            else { fatalError("vision is not able to process the image") }
        for classification in results {
            if classification.confidence > 0.9 {
                classifier.text = "I think this is a \(classification.identifier)."
                break
            }
            else {
                classifier.text = "I am sorry, I can't predict. train me more."
            }
        }
        
    }

我使用此代码通过视觉获得分类器结果。

我猜您的手绘图像与成功工作的图像在某种程度上看起来有所不同


在这种情况下,查看发送到Core ML的实际图像非常有用。您可以使用中的CheckInputImage代码来执行此操作。

我的猜测是,您的手绘图像与成功工作的图像在某种程度上有所不同


在这种情况下,查看发送到Core ML的实际图像非常有用。您可以使用中的CheckInputImage代码进行此操作。

感谢您的回复。但是,当我将我的手绘图像保存到iPhone gallery并从gallery中选择它作为分类器的输入图像时,它绝对可以进行分类。我看不出这与此有什么关系。这仅仅意味着iPhone gallery能够读取您的图像,并可能将其转换为兼容格式。这并不意味着Core ML将能够做同样的事情。感谢您的回复。但是,当我将我的手绘图像保存到iPhone gallery并从gallery中选择它作为分类器的输入图像时,它绝对可以进行分类。我看不出这与此有什么关系。这仅仅意味着iPhone gallery能够读取您的图像,并可能将其转换为兼容格式。这并不意味着CoreML能够做同样的事情。