MLMultiArray 是模型输出矩阵的展平数组吗?
Is MLMultiArray a flatten array of the model output matrix?
CoreML 新手,试图理解一些基本概念。
我正在开发一个输出为:
的模型
float32 [1,896,16]
使用模型时,输出为 MLMultiArray
我得到以下信息:
let output = prediction.regressors // MLMultiArray
print(output.debugDescription) // Float32 1 x 896 x 16 array
print(output.count) // 14336, which is 896x16
而且我可以简单地使用 output[0]..output[1]..
访问每个元素
对于将存储在 MLMultiArray
中的任何数据类型来说都是如此吗? Swift 给我们提供“方便”吗?
如果是flatten array,会按照矩阵的顺序排序吗?
MLMultiArray
是模型输出矩阵的展平数组吗?
No it's not it's a multidimensional array of the given dimensions
您可以将其转换为数组,如下所示,它应该与矩阵的顺序相同。
let length = output.count
let doublePtr = output.dataPointer.bindMemory(to: Double.self, capacity: length)
let doubleBuffer = UnsafeBufferPointer(start: doublePtr, count: length)
let outputArray = Array(doubleBuffer)
对于数据类型,Apple 文档仅显示 3 种类型:Here
case int32
Represents the integer type for multidimensional arrays and is
commonly used for text encoding.
case float32
Represents the float type in multidimensional arrays.
case double
Represents the double type for multidimensional arrays.
CoreML 新手,试图理解一些基本概念。
我正在开发一个输出为:
的模型float32 [1,896,16]
使用模型时,输出为 MLMultiArray
我得到以下信息:
let output = prediction.regressors // MLMultiArray
print(output.debugDescription) // Float32 1 x 896 x 16 array
print(output.count) // 14336, which is 896x16
而且我可以简单地使用 output[0]..output[1]..
对于将存储在 MLMultiArray
中的任何数据类型来说都是如此吗? Swift 给我们提供“方便”吗?
如果是flatten array,会按照矩阵的顺序排序吗?
MLMultiArray
是模型输出矩阵的展平数组吗?
No it's not it's a multidimensional array of the given dimensions
您可以将其转换为数组,如下所示,它应该与矩阵的顺序相同。
let length = output.count
let doublePtr = output.dataPointer.bindMemory(to: Double.self, capacity: length)
let doubleBuffer = UnsafeBufferPointer(start: doublePtr, count: length)
let outputArray = Array(doubleBuffer)
对于数据类型,Apple 文档仅显示 3 种类型:Here
case int32
Represents the integer type for multidimensional arrays and is commonly used for text encoding.
case float32
Represents the float type in multidimensional arrays.
case double
Represents the double type for multidimensional arrays.