当前位置: 首页 > 工具软件 > Closure Lite > 使用案例 >

TensorflowLite iOS Tensor Data Type Initialisation from [[Float]]

颛孙天宇
2023-12-01

TensorflowLite Data(copyingBufferOf:) method expects a flat array of Floats. For a nested array you may need to flatten it into a simple array first.

A Swift Array is a fixed-sized structure with (opaque) pointers to the actual element storage. The withUnsafeBufferPointer() method calls the given closure with a buffer pointer to that element storage. In the case of a [Float] array, that is a pointer to the memory address of the floating point values.

If you pass a nested array (e.g. of type [[Float]]) to the withUnsafeBufferPointer() method then the closure is called with a pointer to the Array structures of the inner arrays. So the element type now is not Float but [Float]

flatten with:

let current_data: [Float] = combined_data.flatMap { $0 }

 类似资料: