如何知道图像属于哪一类?

问题描述

我正在尝试使用Vision和CoreML。

代码

extension CaptureImageView {
    private func loadImage() {
        guard let inputimage = image else { return }
        predictimage = inputimage
        performImageClassification()
    }
    
    private func performImageClassification() {
        let image = self.predictimage
        let resizedImage = image?.resizeto(size: CGSize(width: 224,height: 224))
        let buffer = resizedImage?.toBuffer()
        let output = try? model.prediction(image: buffer!)
        if let output = output {
            breed = output.classLabel
        }
    }
}

我想:

  1. 看看照片中这是狗吗
  2. 如果是狗,请展示犬种
  3. 如果它不是狗,请显示一些警报。

问题: 目前,这种识别可以识别一切:)但是我只想识别狗。

如上所述,我正在使用Apple的Vision,CoreML,MobileNetV2.ml模型。

解决方法

此模型检测1000个类别的对象。其中约有200个是犬种。找出哪些类别是狗,并且仅在检测到的类别是狗类别之一时才显示某些内容。

如果要检测其他类型的狗,则必须训练自己的模型。