From ab2a0fc660eb37a395fef08ec5f7f0f3533c6ca8 Mon Sep 17 00:00:00 2001 From: zhangmozhe Date: Mon, 21 Dec 2020 23:23:21 +0800 Subject: [PATCH] update readme --- warping.py | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 warping.py diff --git a/warping.py b/warping.py deleted file mode 100644 index 8cdda79..0000000 --- a/warping.py +++ /dev/null @@ -1,30 +0,0 @@ -import torch -import torch.nn as nn -import torch.nn.functional as F - - -def get_grid(x): - torchHorizontal = ( - torch.linspace(-1.0, 1.0, x.size(3)).view(1, 1, 1, x.size(3)).expand(x.size(0), 1, x.size(2), x.size(3)) - ) - torchVertical = ( - torch.linspace(-1.0, 1.0, x.size(2)).view(1, 1, x.size(2), 1).expand(x.size(0), 1, x.size(2), x.size(3)) - ) - return torch.cat([torchHorizontal, torchVertical], 1).cuda() - - -class WarpingLayer(nn.Module): - def __init__(self, device): - super(WarpingLayer, self).__init__() - self.device = device - - def forward(self, x, flow): - # WarpingLayer uses F.VGG19_pytorch, which expects normalized grid - # we still output unnormalized flow for the convenience of comparing EPEs with FlowNet2 and original code - # so here we need to denormalize the flow - flow_for_grip = torch.zeros_like(flow).cuda() - flow_for_grip[:, 0, :, :] = flow[:, 0, :, :] / ((flow.size(3) - 1.0) / 2.0) - flow_for_grip[:, 1, :, :] = flow[:, 1, :, :] / ((flow.size(2) - 1.0) / 2.0) - - grid = (get_grid(x) + flow_for_grip).permute(0, 2, 3, 1) - return F.VGG19_pytorch(x, grid, align_corners=True)