pytorch / vision

Datasets, Transforms and Models specific to Computer Vision
https://pytorch.org/vision
BSD 3-Clause "New" or "Revised" License
16.26k stars 6.96k forks source link

Cant find nms function in code? #8585

Closed asusdisciple closed 3 months ago

asusdisciple commented 3 months ago

🐛 Describe the bug

I am looking for a method in torch, but for the love of god I can not not find the function definition! The reason I need to find it is that I need to get rid of the torch dependency and I want to try to convert it into numpy.

I am speaking about torchvision.ops.nms() This method is located in torchvision/ops/boxes.py and returns torch.ops.torchvision.nms().

This method is generated code which can be found in torch/_ops.py where they initialize ops with ops: _Ops = _Ops().

Thats the point where I am lost, the class is located in the same file, but I cant figure out which library it calls to get the nms() method.

Please help me :frowning:

Versions

Latest

NicolasHug commented 3 months ago

The torch.ops.torchvision.nms function called here

https://github.com/pytorch/vision/blob/8f73afacb81df1fcc6e2d308c5b734b126db3426/torchvision/ops/boxes.py#L41

isn't implemented in Python. It's implemented in C++ as a custom op, and it gets automatically exposed (bound) in Python as torch.ops.torchvision.nms by the PyTorch custom op mechanism (it's a convention that these ops get exposed as torch.ops.*, read more here).

HTH