Open Gianluigi121 opened 1 year ago
@Gianluigi121 - This is a lot of code. Please give us a simpler example to reproduce your issue. Also please include all the code we need in order to run it (ex: import statements).
@Gianluigi121 it's lots code but not too many lines to remove I'm afraid. What is such const error anyway, is it possible get into state you try to modify a const value in your app? Or is the val parameter somehow damaged. I'm new to Python so sorry my noobie questions :)
Hey @TobyRoseman I am facing similar issue also, will try to give simple code:
import torch
from torchvision.models import mobilenet_v2
from torchvision.transforms import functional as F
import coremltools as ct
class MyClassifier(torch.nn.Module):
def __init__(self):
super(MyClassifier, self).__init__()
self.model = mobilenet_v2()
self.model.classifier[1] = torch.nn.Linear(
in_features=1280, out_features=3, bias=True
)
def forward(self, image: torch.Tensor, bbox: torch.Tensor) -> torch.Tensor:
image = F.crop(image, bbox[1], bbox[0], bbox[3], bbox[2])
image = torch.nn.functional.interpolate(image, size=(256, 512))
return self.model(image)
torch_model = MyClassifier()
torch_model.eval()
sample_image = torch.rand(1,3,1080,1920)
sample_bbox = torch.Tensor([100,100,200,200]).to("cpu", torch.int)
traced_model = torch.jit.trace(torch_model, [sample_image, sample_bbox])
coreml_model = ct.convert(
traced_model,
source="pytorch",
inputs=[ct.ImageType(name="image", shape=sample_image.shape),
ct.TensorType(name="bbox", shape=sample_bbox.shape)],
)
Hope this will help 🙏
@ophiryaniv-ts - thanks for the concise code. I can reproduce a similar issue using your code.
I'm trying to convert my Pytorch model which takes a flexible-size image and bounding box coordinates as input to a Coreml model. However, I failed to do that. I think the main problem should be the line that I used
bbox_img = FU.interpolate(bbox_img, size=(self.resize_h - pad_top - pad_bottom, self.resize_w - pad_left - pad_right))
which istorch.nn.functional.interpolate
. (I have commented out that line with "----- Problem Line ---------")I wonder does coreml support this function?Error Msg:
Code to Reproduce:
Model Definition:
Model conversion