facebookresearch / dino

PyTorch code for Vision Transformers training with the Self-Supervised learning method DINO
Apache License 2.0
6.23k stars 905 forks source link

How to convert model to ONNX #168

Open nghiapq77 opened 2 years ago

nghiapq77 commented 2 years ago

I tried converting pretrained PyTorch model to ONNX using native torch support via torch.onnx.export but it seems like it does not support bicubic interpolation used in ViT architecture. I see that you are providing pretrained ONNX, how do you convert your model to ONNX?

Many thanks! image

woctezuma commented 2 years ago

Maybe related:

Rusteam commented 2 years ago

I tried converting pretrained PyTorch model to ONNX using native torch support via torch.onnx.export but it seems like it does not support bicubic interpolation used in ViT architecture. I see that you are providing pretrained ONNX, how do you convert your model to ONNX?

Many thanks! image

I just had the same issue. Apparently when i set model inputs to have size (224,224) it's fine.

woctezuma commented 2 years ago

Using (224, 224) image size would allow to skip the interpolation step, thanks to:

https://github.com/facebookresearch/dino/blob/3247a0cacb4c0642270469e06facf96e895f56de/vision_transformer.py#L177-L178

in:

https://github.com/facebookresearch/dino/blob/3247a0cacb4c0642270469e06facf96e895f56de/vision_transformer.py#L174-L194