coremltools icon indicating copy to clipboard operation
coremltools copied to clipboard

Array input with integers results in "value type not convertible"

Open znation opened this issue 6 years ago • 6 comments

Repro steps:

import coremltools
import numpy as np

spec = coremltools.proto.Model_pb2.Model()
spec.specificationVersion = 1
spec.identity.MergeFromString(b'')
input = spec.description.input.add()
input.type.multiArrayType.shape.append(3)
input.type.multiArrayType.dataType = coremltools.proto.FeatureTypes_pb2.ArrayFeatureType.INT32
input.name = "input"
output = spec.description.output.add()
output.type.multiArrayType.shape.append(3)
output.type.multiArrayType.dataType = coremltools.proto.FeatureTypes_pb2.ArrayFeatureType.INT32
output.name = "output"
model = coremltools.models.MLModel(spec)
model.predict({'input': [1,2,3]})

Expected: something like

{'input': np.array([ 1.,  2.,  3.])}

Actual:

/Users/zach/venv/lib/python2.7/site-packages/coremltools/models/model.pyc in predict(self, data, useCPUOnly, **kwargs)
    318 
    319         if self.__proxy__:
--> 320             return self.__proxy__.predict(data,useCPUOnly)
    321         else:
    322             if _macos_version() < (10, 13):

RuntimeError: value type not convertible

Note that changing the input to [1.0, 2, 3] seems to fix the issue; so despite the multiArrayType being INT32, it only seems to allow float input (at least in some cases).

znation avatar Jun 12 '18 00:06 znation