Here we show a few examples of the basic building blocks that are used in this work.
Code
import syssys.path.append("../src")import warningswarnings.filterwarnings('ignore')from PIL import Imageimport numpy as npimport torch as thfrom einops import rearrange, repeatfrom transmotion.utils import make_coordinate_gridfrom transmotion.kp_detection import KPDetector, KPResultfrom transmotion.configs import TPSConfig from transmotion.dense_motion import ( DenseMotionNetwork, keypoints_to_heatmap_representation, warp_to_keypoints_with_background, DenseMotionConf,)import numpy as npimport altair as altdef make_data_source(*grids):return alt.Data(values=[{"x":xi,"y":yi, "idx": idx} for (idx, grid) inenumerate(grids) for (xi, yi) in grid])def draw_grid(grid): data = make_data_source(grid)return alt.Chart(data).mark_circle().encode(alt.X("x:Q"), alt.Y("y:Q"))
Uniform Coordinate Grid
We use coordinate grids to sample and deform images. Coordinate grids are well… grids, with each coordinates represented as [-1,1]\times[-1,1]
The coordinates are in [-1,1] range, where -1 means left/top and 1 means right/bottom. This is the same format that is used by PyTorch’s grid_sample function.