在范围内找不到 'model'

Cannot find 'model' in scope

@IBAction func recognizePressed(_ sender: UIButton) {
        // Turn view into an image
        let resultImage = UIImage.init(view: CanvasView)
        let pixelBuffer = resultImage.pixelBufferGray(width: 224, height: 224)
    
    if #available(iOS 13.0, *) {
        let model: hiraganaModel2 = try! hiraganaModel2(configuration: .init())
   
    } else {}
        // Fallback on earlier versions
    
        // output a Hiragana character
        let output = try? model.prediction(Image: pixelBuffer!)
        print(output.classLabel)
   }
}

我的 xcode 在尝试构建我的项目时看不到我的模型,出现此错误:

Cannot find 'model' in scope 

我尝试了很多解决方案,例如:

  1. 删除派生数据的内容
  2. 重启我的设备
  3. 通过按 shift + command + k 清除我的项目

您只能在声明的范围内访问模型。您可以在 if 条件之外声明以下行。

let model: hiraganaModel2 = try! hiraganaModel2(configuration: .init())


let output = try? model.prediction(Image: pixelBuffer!)
        print(output.classLabel)