How to Initialize a Mlmultiarray in Coreml

How to use CoreML model output MLMultiArray

MultiArray is not a built-in datatype. Use the variable name:

var result: MLMultiArray //Your populated array
let a = result[[z, y, x] as [NSNumber]].floatValue

Also you might want to check out Swiftier MultiArray. Follow the CoreMLHelpers install instructions.

EDIT:

MLMultiArray is part of the CoreML framework. To use it, you must import the framework like this:

import CoreML

How to create CoreML MLMultiArray for a 4D data for prediction on iOS with Swift?

If you're going to use a Float array to initialize the MLMultiArray, it needs be a 1-dimensional array. This means you need to "flatten" your 4D data into a 1D array first.

(This is why MLMultiArray has a strides property. You need to use these strides to calculate the position of each element in the flattened array.)

Dealing with MLMultiArray from MLModel

The number 1917 tells me you're most likely using MobileNet + SSD.

I wrote a number of blog posts that explain how this sort of thing works. Here is a blog post that explains how to do the decoding for MobileNetV2+SSDLite, but the same logic works for other versions of MobileNet and SSD as well: https://machinethink.net/blog/mobilenet-ssdlite-coreml/



Related Topics



Leave a reply



Submit