I’ve created a CoreML model using Create ML tool and have been testing it on a physical device. As part of debugging the app I decided to hardcode the data to match a csv file that I had already ran in the Create ML preview feature.
9 times out of 10, the prediction label and prediction probability match, but 1 out 10 I get a prediction probability of NaN.
I read that initialising the input state with zeroes could impact it, which I’ve now done, but still can’t figure out what I randomly get NaNs.
Has anyone encountered probability issues with Core ML? My model is an activity classifier.
This is how I initialise the state:
func initializeState() -> MLMultiArray? {
do {
let state = try MLMultiArray(shape: [400], dataType: .double)
for i in 0..<state.count {
state[i] = 0.0
}
return state
} catch {
print("Error initializing state: (error)")
return nil
}
}
This is how state is declared:
@State var currentState = try? MLMultiArray(
shape: [(ModelConstants.hiddenInLength +
ModelConstants.hiddenCellInLength) as NSNumber],
dataType: MLMultiArrayDataType.double)
The input parameters for the model are declared like this:
let rotX = try? MLMultiArray(
shape: [ModelConstants.predictionWindowSize] as [NSNumber],
dataType: MLMultiArrayDataType.double)
and this is how I run the prediction model:
do {
let prediction = try gymModel!.prediction(motionRotationRateX_rad_s_: rotX!,
motionRotationRateY_rad_s_: rotY!,
motionRotationRateZ_rad_s_: rotZ!,
motionUserAccelerationX_G_: accX!,
motionUserAccelerationY_G_: accY!,
motionUserAccelerationZ_G_: accZ!,
stateIn: currentState!)
currentState = prediction.stateOut
if let probability = prediction.labelProbability[prediction.label]{
print("prediction is: (prediction.label) with (probability*100)")
if probability.isNaN {
print("help")
}
return "(Date()). prediction is: (prediction.label) with (probability*100)"
}
} catch {
print("Error running prediction: (error)")
}
Have been going around in circles trying to figure out why I randomly get NaN. Any suggestions/ ideas on how to debug further would be massively appreciated
cheers