Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 

Interface


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.7k views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...