-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
I've trained mobilevitv2_200_384_in22ft1k on custom dataset. Now trying to convert it to CoreML via coremltools. Get an error Encountered an error while compiling a neural network model: in operation of type reshape: Rank of the shape parameter must be between 0 and 5 (inclusive) in reshape
Versions
torch: 1.12.1
python: 3.8.8
coremltools: 5.2.0
To Reproduce
Steps to reproduce the behavior:
- Load model weights
model = (
torch.load("mobile_vit_last.pth",map_location=torch.device('cpu'))
)
model.eval()
- Gather Jit trace
import timm
import torch
from torchvision.transforms import functional as F
from PIL import Image
img = Image.open("sample_image.jpg").convert('RGB')
img = F.resize(
img=img, size=384, interpolation=F.InterpolationMode.BILINEAR
)
input_tensor = F.pil_to_tensor(img).float()
input_tensor.div_(255.0)
input_tensor = input_tensor.unsqueeze(0)
with torch.no_grad():
jit_model = torch.jit.trace(model, input_tensor)
- Convert to CoreML
coreml_model = ct.convert(
model=jit_model,
inputs=[
ct.ImageType(name="input", shape=input_tensor.shape, scale=1.0 / 255.0)
],
convert_to="mlprogram",
)
- Try on sample image
img = Image.open("sample_image.jpg").convert('RGB').resize((384,384))
# Make a prediction using Core ML
out_dict = coreml_model.predict(tensor)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
