Here's a simple implementation of bilinear interpolation on tensors using PyTorch.
I wrote this up since I ended up learning a lot about options for interpolation in both the numpy and PyTorch ecosystems. More generally than just interpolation, too, it's also a nice case study in how PyTorch magically can put very numpy-like code on the GPU (and by the way, do autodiff for you too).
For interpolation in PyTorch, this open issue calls for more interpolation features. There is now a nn.functional.grid_sample()
feature but at least at first this didn't look like what I needed (but we'll come back to this later).
In particular I wanted to take an image, W x H x C
, and sample it many times at different random locations. Note also that this is different than upsampling which exhaustively samples and also doesn't give us fle
Question: Will you use Docker in the dev environment?
Answer: Not this time, just to save time (there's a lot to cover), although I'm sharing a couple of development tricks in the end.
Question: Why is the convention ‘app’ not 'api'?
Answer: To simplify things. It might be more familiar for people coming from other frameworks. Also because you can serve things like templates rendered on the backend, so, to avoid confusion. But you can also name the object differently if that works better for you.
sudo add-apt-repository ppa:graphics-drivers/ppa | |
sudo apt update | |
sudo apt upgrade | |
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin | |
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600 | |
wget https://developer.download.nvidia.com/compute/cuda/11.1.0/local_installers/cuda-repo-ubuntu2004-11-1-local_11.1.0-455.23.05-1_amd64.deb | |
sudo dpkg -i cuda-repo-ubuntu2004-11-1-local_11.1.0-455.23.05-1_amd64.deb | |
sudo apt-key add /var/cuda-repo-ubuntu2004-11-1-local/7fa2af80.pub | |
sudo apt-get update |