OrkhanHI / pytorch_grid_sample_python

Python function of Pytorch Grid Sample with Zero Padding
18 stars 5 forks source link

Inference too slow #1

Open AlanLu0808 opened 3 years ago

AlanLu0808 commented 3 years ago

I found the grid sample in pytorch is very fast. Maybe the opearation can be done in 1ms. In contrast, this one is quiet slow, costing several mintes! Any suggestions? Tks!

OrkhanHI commented 3 years ago

Because pytorch grid sample is written in C++ and I think also it was using multi-threading. I have changed their C++ code and build only zero padding for grid sample. Below is the binary file.

https://drive.google.com/file/d/1kzUKuKMZyoHA_aFT0T2oMwvw8B2BYc3C/view?usp=sharing

You can load this binary file and use it with torch library:

import torch torch.ops.load_library("my_grid_sampler.cpython-36m-x86_64-linux-gnu.so")

Call the function

torch.ops.mynamespace.my_grid_sampler(image, grid)

zhangziwenHIT commented 3 years ago

Thank you for your work!When I use your c++ binary,an error will be reported as:

Segmentation fault (core dumped)

And my calling method is as follows(in first-order-model):

import torch torch.ops.load_library("my_grid_sampler.cpython-36m-x86_64-linux-gnu.so")

Call the function

 #sparse_deformed = F.grid_sample(source_repeat, sparse_motions)
 sparse_deformed = torch.ops.mynamespace.my_grid_sampler(source_repeat, sparse_motions)

Thank you!