An operation trying to do the opposite of F.grid_sample()
.
Assume torch
already installed.
pip install git+https://github.com/ashawkey/grid_put
# or locally
git clone https://github.com/ashawkey/grid_put
cd grid_put
pip install .
from grid_put import grid_put
# only support 2D and 3D grid, we take 2D as an example:
H, W # target grid shape
coords # [N, 2], float grid coords in [-1, 1]
values # [N, C], values to put into grid
# mode: nearest, linear, linear-mipmap (default)
out = grid_put((H, W), coords, values, mode='linear-mipmap') # [H, W, C]
# extra dependency: pip install kiui
python test.py --mode <random|grid> --ratio <float>
mode-ratio | nearest | linear | linear-mipmap |
---|---|---|---|
grid-10% | ![]() |
![]() |
![]() |
grid-90% | ![]() |
![]() |
![]() |
random-10% | ![]() |
![]() |
![]() |
random-90% | ![]() |
![]() |
![]() |