0

I have an NSArray of size (1, 5, 401) from a plist file. I want to copy that into MLMultiArray of the same shape and then pass it to a CoreML model in Swift. How can I copy the values from NSArray to MLMultiArray?

let filepath = Bundle.main.path(forResource:"testPlist", ofType: "plist")
let dict2 = NSDictionary(contentsOfFile: filepath!)

let test_input:NSArray = dict2?.object(forKey:"test_input") as! NSArray

let mlMultiArray_input = try? MLMultiArray (shape:[1,5,401],dataType : MLMultiArrayDataType.double)

plist file: enter image description here

3
  • 2
    dict2?.object(forKey:"test_input") as! NSArray Big code smell here (you should not force cast optionals, nor be using "object(forKey)"). You should use Swift native array instead of NSArray. Then you will be able to use the array content easily. Commented Mar 23, 2022 at 17:36
  • @EricAya Thank you, but I could not find any code reading a plist array into SwiftUI array. I added how I read the plist file to the main question. Do you know of a way to read it directly into SwiftUI? Commented Mar 24, 2022 at 19:03
  • Does this answer your question? How to initialize a MLMultiArray in CoreML Commented Apr 2, 2022 at 19:12

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.