Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
znation opened this issue Jun 12, 2018 · 6 comments
Open

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

znation opened this issue Jun 12, 2018 · 6 comments
Labels
bug Unexpected behaviour that should be corrected (type) triaged Reviewed and examined, release as been assigned if applicable (status)

Comments

@znation
Copy link
Contributor

znation commented Jun 12, 2018

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).

@lauriebyrum
Copy link

I see this too. Thanks for the workaround!

@srikris srikris added bug Unexpected behaviour that should be corrected (type) Core ML Framework An issue related to the Core ML Framework labels Dec 9, 2019
@TobyRoseman TobyRoseman self-assigned this Sep 24, 2021
@TobyRoseman TobyRoseman removed the Core ML Framework An issue related to the Core ML Framework label Sep 24, 2021
@openjamoses
Copy link

Faced the same error. I was able to resolve it by using float64 numpy array
input_array.astype(np.float64)

@porterjenkins
Copy link

I'm fairly certain I read that CoreML has a max precision of 32. I had a PyTorch model that had input types of type long or torch.int64. Trying to call the predict() method on my mlmodel raised this error. My solution was to cast to type np.int32 when calling predict:

y = model.predict('one_hot': one_hot_array.astype(np.int32))

Doing so solved my issue

@TobyRoseman
Copy link
Collaborator

With coremltools 6.0, the predict call from the original code now hangs.

@TobyRoseman TobyRoseman added the triaged Reviewed and examined, release as been assigned if applicable (status) label Oct 24, 2022
@TobyRoseman TobyRoseman removed their assignment Oct 24, 2022
Birch-san pushed a commit to Birch-san/coremltools that referenced this issue Nov 27, 2022
@den-run-ai
Copy link

float arithmetic might be wrong in some cases with large integer values (e.g. time series)

@darylsew
Copy link

+1 seems like this is still an issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected behaviour that should be corrected (type) triaged Reviewed and examined, release as been assigned if applicable (status)
Projects
None yet
Development

No branches or pull requests

8 participants