I am using a custom CoreML model which takes a MultiArray (Float32 1 × 85 × 60 × 1) as an input. The following is the entire app. As you can see I initialize the model, create some fake data and then run model.predict(data).
import CoreML
struct ContentView: View {
let model: A_4 = try! A_4(configuration: .init())
var body: some View {
VStack {
Text("Test")
.onAppear {
print(model.model)
}
.onTapGesture {
let data = [Float](repeating: 0.3, count: 5100)
let reshapedData = try! MLMultiArray(data).reshaped(to: [1, 85, 60, 1])
let input = A_4Input(conv2d_input: reshapedData)
let prediction = try! model.prediction(input: input)
print(prediction.Identity)
}
}
}
}
On any simulator device running iOS 14.5, model.predict works as expect yielding the following array:
On any number tap: [0.0009301336,0.9990699]
On my real device running iOS 15.0, the model produces a similar result:
On any number tap: [0.0009710453,0.9990289]
Lastly, I tested the app on the following devices, iPhone 11 Pro (iOS 14.7.1), iPhone 11 (iOS 14.6), iPhone SE 2 (iOS 14.6):
On first tap: [0, 1]
On Second tap: Thread 1: EXC_BAD_ACCESS (code=1, address=0x1470b4000)
As you can see the first prediction is someone nonsense, and the second prediction crashes the app. I have attempted debugging this for quite some time and cannot determine the cause of this memory error. I have provided the ContentView and the model here: https://drive.google.com/drive/folders/11hw70kCfyeuRUepEf6cxhmuTb8oLW3jm?usp=sharing
Thanks for any insight you can provide.