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

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

ios - Swift multidimentional array

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...