I have .mlmodel
file and I have to integrate it to the app. the input is 1x9x30 array. where 9 is the inputs from accel x,y,z
and gryro xyz
and yaw, pitch, roll from the device.
how can I make input array for the device motion data. I was previously using CreateML and the previous code, but now I built my own model and the input for prediction changed. what changes should I do?
let accelDataX = try! MLMultiArray(shape: [ModelConstants.predictionWindowSize] as [NSNumber], dataType: MLMultiArrayDataType.double)
let accelDataY = try! MLMultiArray(shape: [ModelConstants.predictionWindowSize] as [NSNumber], dataType: MLMultiArrayDataType.double)
let accelDataZ = try! MLMultiArray(shape: [ModelConstants.predictionWindowSize] as [NSNumber], dataType: MLMultiArrayDataType.double)
let gyroDataX = try! MLMultiArray(shape: [ModelConstants.predictionWindowSize] as [NSNumber], dataType: MLMultiArrayDataType.double)
let gyroDataY = try! MLMultiArray(shape: [ModelConstants.predictionWindowSize] as [NSNumber], dataType: MLMultiArrayDataType.double)
let gyroDataZ = try! MLMultiArray(shape: [ModelConstants.predictionWindowSize] as [NSNumber], dataType: MLMultiArrayDataType.double)
let pitch = try! MLMultiArray(shape: [ModelConstants.predictionWindowSize] as [NSNumber], dataType: MLMultiArrayDataType.double)
let roll = try! MLMultiArray(shape: [ModelConstants.predictionWindowSize] as [NSNumber], dataType: MLMultiArrayDataType.double)
let yaw = try! MLMultiArray(shape: [ModelConstants.predictionWindowSize] as [NSNumber], dataType: MLMultiArrayDataType.double)
var stateOutput = try! MLMultiArray(shape:[ModelConstants.stateInLength as NSNumber], dataType: MLMultiArrayDataType.double)
//--------Functions-------//
func addMotionSampleToDataArray (motionSample: CMDeviceMotion) {
accelDataX[[currentIndexInPredictionWindow] as [NSNumber]] = motionSample.userAcceleration.x as NSNumber
accelDataY[[currentIndexInPredictionWindow] as [NSNumber]] = motionSample.userAcceleration.y as NSNumber
accelDataZ[[currentIndexInPredictionWindow] as [NSNumber]] = motionSample.userAcceleration.z as NSNumber
gyroDataX[[currentIndexInPredictionWindow] as [NSNumber]] = motionSample.rotationRate.x as NSNumber
gyroDataY[[currentIndexInPredictionWindow] as [NSNumber]] = motionSample.rotationRate.y as NSNumber
gyroDataZ[[currentIndexInPredictionWindow] as [NSNumber]] = motionSample.rotationRate.z as NSNumber
pitch[[currentIndexInPredictionWindow] as [NSNumber]] = motionSample.attitude.pitch as NSNumber
roll[[currentIndexInPredictionWindow] as [NSNumber]] = motionSample.attitude.roll as NSNumber
yaw[[currentIndexInPredictionWindow] as [NSNumber]] = motionSample.attitude.yaw as NSNumber
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…