MLTensor not found in scope even though I have Xcode 15.1

Hello!

When trying to use MLTensor, I am getting the error that it is not found in scope even though I am using Xcode 15.1 (it says fully up to date) and set my deployment target to iOS 17.2. Is there something else I need to be doing in order to use MLTensor?

Thanks!

Michael

MLTensor is available in 2024 fall release OSes (e.g. iOS 18) and later. https://developer.apple.com/documentation/coreml/mltensor

Ok, I have set the minimum deployment target to iOS 18.3 but it is still unable to find MLTensor in scope. Do I need to create my own struct of MLTensor somehow? Here is my current code:

import CoreML

class BallTracker {
    let model: BallTrackerPreprocess
    
    init() {
        self.model = try! BallTrackerPreprocess(configuration: MLModelConfiguration())
    }
    
    func processFrame(from frames: [CVPixelBuffer]) -> MLTensor? {
        // f1 is current, f2 is prev, f3 is previous prev
        guard frames.count == 3 else { return nil }
        let width = CVPixelBufferGetWidth(frames[0])
        let height = CVPixelBufferGetHeight(frames[0])
        let shape: [Int] = [3, height, width]
        let tensor = MLTensor(concatenating: frames.map { MLTensor(pixelBuffer: $0) }, dimension: 0)
        
        do {
            let prediction = try model.prediction(input_frames: tensor)
            return prediction.var_366
        }
        catch {
            print("error: \(error)")
            return nil
        }
    }
}

If you are using Xcode 15.1, you likely do not have iOS 18 SDK, which you need to access the new MLTensor symbol.

MLTensor not found in scope even though I have Xcode 15.1
 
 
Q