numpy.int64 is not supported in prediction?
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 850
- Avg merge
- 4d 5h
- Merged PRs (30d)
- 10
Description
## ❓Question
I found this code cause runtime error.
```python
import torch
import coremltools as ct
import numpy
class Net(torch.nn.Module):
def forward(self, x, y):
return x + y
torch_model = Net()
x = torch.randn(2)
traced_model = torch.jit.trace(torch_model, (x, x))
model_ct = ct.convert(traced_model,
inputs=[ct.TensorType(shape=x.shape, name='x'), ct.TensorType(shape=x.shape, name='y')])
# OK
out_dict = model_ct.predict({'x': x.detach().numpy().astype(numpy.float32),
'y': x.detach().numpy().astype(numpy.float32)})
# OK
out_dict = model_ct.predict({'x': x.detach().numpy().astype(numpy.float64),
'y': x.detach().numpy().astype(numpy.float64)})
# OK
out_dict = model_ct.predict({'x': x.detach().numpy().astype(numpy.int32),
'y': x.detach().numpy().astype(numpy.int32)})
# Runtime Error
out_dict = model_ct.predict({'x': x.detach().numpy().astype(numpy.int64),
'y': x.detach().numpy().astype(numpy.int64)})
```
```
Traceback (most recent call last):
File "/Users/ryosukefukatani/work/HMERModel/atnBTTR/d16.py", line 31, in
out_dict = model_ct.predict({'x': x.detach().numpy().astype(numpy.int64),
File "/Users/ryosukefukatani/work/HMERModel/venv/lib/python3.9/site-packages/coremltools/models/model.py", line 514, in predict
return self.__proxy__.predict(data, useCPUOnly)
RuntimeError: value type not convertible
```
`numpy.int64` is not supported?
Anyway, I think error message can be more friendly.
Contributor guide
Research direction
Start at coremltools/models/model.py around the predict call shown in the traceback and reproduce the example with numpy.int64 inputs. Trace where the input value becomes non-convertible, then verify whether the expected result is support for numpy.int64 or a clearer error message; document the completed behavior with a regression test if the existing test layout identifies one.
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