apple / apple/coremltools

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

Open
#194 6 comments 2 reactions 0 assignees View on GitHub
bug triaged
Dominant language
Python
Stars
5.4k
Forks
850
Avg merge
4d 5h
Merged PRs (30d)
10

Description

Repro steps:

```python
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
```python
{'input': np.array([ 1., 2., 3.])}
```

Actual:
```python
/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).

Contributor guide

Open the contributing guide

Research direction

Start at coremltools.models.MLModel.predict, where the reported traceback reaches model.pyc, and reproduce the provided INT32 multi-array example. Trace why an integer list is rejected while a list containing a float succeeds, then add regression coverage showing that integer input is accepted for an INT32 array without the runtime error.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.