Spaces:
Running on Zero
Running on Zero
Download model/warplayer.py from someone-in-the-world/HighQualityVideoGeneration: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/spaces/someone-in-the-world/HighQualityVideoGeneration/resolve/main/model/warplayer.py
- Command line
-
hf download hf://spaces/someone-in-the-world/HighQualityVideoGeneration/model/warplayer.py
-
curl -L -o warplayer.py https://huggingface.co/spaces/someone-in-the-world/HighQualityVideoGeneration/resolve/main/model/warplayer.py
1.37 kB
| """Vendored from hzwer/Practical-RIFE (MIT, see LICENSES/RIFE-LICENSE). | |
| Required as a sibling `model.warplayer` import target for the `train_log/RIFE_HDv3.py` | |
| module downloaded at runtime from thornmaze/RIFE — see postprocess/interpolation.py. | |
| """ | |
| import torch | |
| import torch.nn as nn | |
| device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | |
| backwarp_tenGrid = {} | |
| def warp(tenInput, tenFlow): | |
| k = (str(tenFlow.device), str(tenFlow.size())) | |
| if k not in backwarp_tenGrid: | |
| tenHorizontal = torch.linspace(-1.0, 1.0, tenFlow.shape[3], device=tenFlow.device).view( | |
| 1, 1, 1, tenFlow.shape[3]).expand(tenFlow.shape[0], -1, tenFlow.shape[2], -1) | |
| tenVertical = torch.linspace(-1.0, 1.0, tenFlow.shape[2], device=tenFlow.device).view( | |
| 1, 1, tenFlow.shape[2], 1).expand(tenFlow.shape[0], -1, -1, tenFlow.shape[3]) | |
| backwarp_tenGrid[k] = torch.cat( | |
| [tenHorizontal, tenVertical], 1).to(tenFlow.device) | |
| tenFlow = torch.cat([tenFlow[:, 0:1, :, :] / ((tenInput.shape[3] - 1.0) / 2.0), | |
| tenFlow[:, 1:2, :, :] / ((tenInput.shape[2] - 1.0) / 2.0)], 1) | |
| grid = backwarp_tenGrid[k].type_as(tenFlow) | |
| g = (grid + tenFlow).permute(0, 2, 3, 1) | |
| return torch.nn.functional.grid_sample(input=tenInput, grid=g, mode='bilinear', padding_mode='border', align_corners=True) |