Swift 多维数组

问题描述

我有 .mlmodel 文件,我必须将它集成到应用程序中。输入是 1x9x30 数组。其中 9 是来自 accel x,y,zgryro xyz 以及来自设备的偏航、俯仰、滚转的输入。

如何为设备运动数据制作输入数组。我之前使用的是 CreateML 和之前的代码,但现在我构建了自己的模型并且预测的输入发生了变化。我应该做哪些改变?

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)

//--------函数-------//

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)