1adrianb / face-alignment

:fire: 2D and 3D Face alignment library build using pytorch
https://www.adrianbulat.com
BSD 3-Clause "New" or "Revised" License
7.11k stars 1.35k forks source link

Unable to Convert to OpenVINO with JIT Trace #365

Closed fdavidsen closed 1 week ago

fdavidsen commented 1 week ago

I want to convert this model to OpenVINO, so I start by doing jit trace with the following code.

import torch
from face_alignment import FaceAlignment, LandmarksType

class FaceAlignmentWrapper(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.model = FaceAlignment(LandmarksType.TWO_D, device='cpu')

    def forward(self, image):
        landmarks = self.model.get_landmarks_from_image(image)
        if landmarks:
            return torch.tensor(landmarks[0])
        return torch.zeros((68, 2))

model = FaceAlignmentWrapper()
scripted_model = torch.jit.trace(model, torch.randn(256, 256, 3))
scripted_model.save("face_alignment_scripted.pt")

However it gives me this error

RuntimeError: Cannot insert a Tensor that requires grad as a constant. Consider making it a parameter or input, or detaching the gradient

Is there any way to convert this model to OpenVINO?