0
votes

Hey i have model with format .pth, I decided to convert this model to apple .mlmodel by .pth -> .onnx -> .mlmodel

I used coremltools to convert input to image but i need to convert output to Double. now I Have something like MultiArray (Float32) MultiArray of shape (1, 1, 1, 1, 1). The first and second dimensions correspond to sequence and batch size, respectively

I try make something like this

import coremltools
from coremltools.proto import FeatureTypes_pb2 as ft


spec = coremltools.utils.load_spec("ios.mlmodel")
output = spec.description.output[0]
output.type = ft.DoubleFeatureType
model.save('testowymodel2.mlmodel')

1

1 Answers

1
votes

Define this function:

import coremltools.proto.FeatureTypes_pb2 as ft

def update_multiarray_to_double(feature):
    if feature.type.HasField("multiArrayType"):
        feature.type.multiArrayType.dataType = ft.ArrayFeatureType.DOUBLE

Then call it like so:

for feature in spec.description.output:
    update_multiarray_to_double(feature)

coremltools.utils.save_spec(spec, "woot.mlmodel")