Use of dlib models in pytorch transforms

Dear Community,

I have usecase where dlib based models need to used to perform face detection and face alignment. Is there a way to use these models to perform face detection and alignment as part of pytorch transforms?

Please suggest and possibilities or resources.

Thanks

In the common use case you would apply any transformation in the Dataset.__getitem__ method on each sample. Assuming your dlib transformation works on a single numpy array (or any other object you could transform into a PyTorch tensor) you could just apply it in the __getitem__, too.
Additionally, you could also write a custom transform class which expects to initialize internal states in the __init__ and apply the transformation in its __call__ method. Take a look at e.g torchvision.transforms.ToTensor for an example. This would allow you to add this custom transformation into e.g. torchvision.transforms.Compose, but make sure the expected dtype is used.

1 Like

Thanks for these details. These are helpful.