Home > Enterprise >  Cannot find 'model' in scope
Cannot find 'model' in scope

Time:03-14

@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)
   }
}

my xcode can't see my model when trying to build my project this error appear:

Cannot find 'model' in scope 

i try many solution such as :

  1. delete the content of Derived Data
  2. restart my device
  3. clear my project through pressing shift command k

CodePudding user response:

You can access the model only in the scope that's you declared. you can declare the below line outside the if condition.

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


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