apple / apple/coremltools

TypeError: object of type 'NoneType' has no len()

Open
#1,790 4 comments 0 reactions 0 assignees View on GitHub
bug PyTorch (traced)
Dominant language
Python
Stars
5.4k
Forks
850
Avg merge
4d 5h
Merged PRs (30d)
10

Description

```python
import coremltools as ct
import torch
import torchvision
import torch.nn as nn

class Wrapper(nn.Module):
def __init__(self, model_name):
super(Wrapper, self).__init__()
self.torch_model = torchvision.models.get_model(model_name, weights="DEFAULT")

def forward(self, x):
res = self.torch_model(x)
x = res[0]["labels"]
return x

torch_model = Wrapper('ssd300_vgg16')
torch_model.eval()

t = torch.rand(3, 400, 400)
example_input = t
example_input = [example_input]

preds = torch_model(example_input) # works
traced_model = torch.jit.trace(torch_model, [example_input]) # works
model = ct.convert(traced_model, inputs=[ct.TensorType(shape=t.shape)])
```

Contributor guide

Open the contributing guide

Research direction

The reproducer centers on ct.convert(traced_model, inputs=[ct.TensorType(shape=t.shape)]) after tracing a torchvision ssd300_vgg16 wrapper in Python. Start by running that conversion with the supplied example and trace where the None value reaches len(); done means the conversion completes without the reported TypeError for this reproducer.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.