简体   繁体   English

调整coremlmodel的输入

[英]Shaping input for a coremlmodel

I have a coremlmodel taking an input of shape MultiArray (Float32 67 x 256 x 320) I am having a hard time to shape the input to this model. 我有一个coremlmodel输入形状为MultiArray (Float32 67 x 256 x 320)的图形,我很难调整此模型的输入形状。 Currently, I am trying to achieve it like so, 目前,我正在努力实现这一目标,

var m = try! MLMultiArray(shape: [67,256,320], dataType: .double)
for i in 0...66{           
    var cost = rand((256,320)) // this is coming from swix [SWIX]
    memcpy(m.dataPointer+i*256*320, &cur_cost.flat.grid , 256*320)
}

I will have to replace the rand with matrices of that size later. 稍后,我将不得不用该大小的矩阵替换兰特。 I am using this for testing purposes first. 我首先将此用于测试目的。

Any pointers on how to mould input to fit the volume would be greatly appreciated.. 我们将不胜感激有关如何使输入模制以适应体积的任何指示。

[ SWIX ] [ SWIX ]

What seems to be wrong in your code is that you're copying bytes instead of doubles. 您的代码中似乎有问题的是,您正在复制字节而不是双精度。 A double is 8 bytes, so your offset should be i*256*320*MemoryLayout<Double>.stride and the amount you're copying should be 256*320*MemoryLayout<Double>.stride . 一个double是8个字节,因此偏移量应为i*256*320*MemoryLayout<Double>.stride ,复制的数量应为256*320*MemoryLayout<Double>.stride

Note that you can also use the MLMultiArray's strides property to compute the offset for a given data element in the array: 请注意,您还可以使用MLMultiArray的strides属性来计算阵列中的一个给定的数据元素的偏移量:

let offset = i0 * strides[0].intValue + i1 * strides[1].intValue + i2 * strides[2].intValue 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM