mirror of
https://github.com/hzwer/ECCV2022-RIFE.git
synced 2025-12-16 08:27:45 +01:00
Update UHD mode
This commit is contained in:
@@ -91,12 +91,9 @@ class IFNet(nn.Module):
|
||||
self.block2 = IFBlock(8, scale=2, c=96)
|
||||
self.block3 = IFBlock(8, scale=1, c=48)
|
||||
|
||||
def forward(self, x, UHD=False):
|
||||
if UHD:
|
||||
x = F.interpolate(x, scale_factor=0.25, mode="bilinear", align_corners=False)
|
||||
else:
|
||||
x = F.interpolate(x, scale_factor=0.5, mode="bilinear",
|
||||
align_corners=False)
|
||||
def forward(self, x, scale=1.0):
|
||||
x = F.interpolate(x, scale_factor=0.5 * scale, mode="bilinear",
|
||||
align_corners=False)
|
||||
flow0 = self.block0(x)
|
||||
F1 = flow0
|
||||
warped_img0 = warp(x[:, :3], F1)
|
||||
@@ -111,6 +108,8 @@ class IFNet(nn.Module):
|
||||
warped_img1 = warp(x[:, 3:], -F3)
|
||||
flow3 = self.block3(torch.cat((warped_img0, warped_img1, F3), 1))
|
||||
F4 = (flow0 + flow1 + flow2 + flow3)
|
||||
F4 = F.interpolate(F4, scale_factor=1 / scale, mode="bilinear",
|
||||
align_corners=False) / scale
|
||||
return F4, [F1, F2, F3, F4]
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -188,11 +188,9 @@ class Model:
|
||||
torch.save(self.contextnet.state_dict(), '{}/contextnet.pkl'.format(path))
|
||||
torch.save(self.fusionnet.state_dict(), '{}/unet.pkl'.format(path))
|
||||
|
||||
def predict(self, imgs, flow, training=True, flow_gt=None, UHD=False):
|
||||
def predict(self, imgs, flow, training=True, flow_gt=None):
|
||||
img0 = imgs[:, :3]
|
||||
img1 = imgs[:, 3:]
|
||||
if UHD:
|
||||
flow = F.interpolate(flow, scale_factor=2.0, mode="bilinear", align_corners=False) * 2.0
|
||||
c0 = self.contextnet(img0, flow)
|
||||
c1 = self.contextnet(img1, -flow)
|
||||
flow = F.interpolate(flow, scale_factor=2.0, mode="bilinear",
|
||||
@@ -209,10 +207,10 @@ class Model:
|
||||
else:
|
||||
return pred
|
||||
|
||||
def inference(self, img0, img1, UHD=False):
|
||||
def inference(self, img0, img1, scale=1.0):
|
||||
imgs = torch.cat((img0, img1), 1)
|
||||
flow, _ = self.flownet(imgs, UHD)
|
||||
return self.predict(imgs, flow, training=False, UHD=UHD)
|
||||
flow, _ = self.flownet(imgs, scale)
|
||||
return self.predict(imgs, flow, training=False)
|
||||
|
||||
def update(self, imgs, gt, learning_rate=0, mul=1, training=True, flow_gt=None):
|
||||
for param_group in self.optimG.param_groups:
|
||||
|
||||
@@ -173,11 +173,9 @@ class Model:
|
||||
torch.save(self.contextnet.state_dict(), '{}/contextnet.pkl'.format(path))
|
||||
torch.save(self.fusionnet.state_dict(), '{}/unet.pkl'.format(path))
|
||||
|
||||
def predict(self, imgs, flow, training=True, flow_gt=None, UHD=False):
|
||||
def predict(self, imgs, flow, training=True, flow_gt=None):
|
||||
img0 = imgs[:, :3]
|
||||
img1 = imgs[:, 3:]
|
||||
if UHD:
|
||||
flow = F.interpolate(flow, scale_factor=2.0, mode="bilinear", align_corners=False) * 2.0
|
||||
c0 = self.contextnet(img0, flow[:, :2])
|
||||
c1 = self.contextnet(img1, flow[:, 2:4])
|
||||
flow = F.interpolate(flow, scale_factor=2.0, mode="bilinear",
|
||||
@@ -194,10 +192,10 @@ class Model:
|
||||
else:
|
||||
return pred
|
||||
|
||||
def inference(self, img0, img1, UHD=False):
|
||||
def inference(self, img0, img1, scale=1.0):
|
||||
imgs = torch.cat((img0, img1), 1)
|
||||
flow, _ = self.flownet(imgs, UHD)
|
||||
return self.predict(imgs, flow, training=False, UHD=UHD)
|
||||
flow, _ = self.flownet(imgs, scale)
|
||||
return self.predict(imgs, flow, training=False)
|
||||
|
||||
def update(self, imgs, gt, learning_rate=0, mul=1, training=True, flow_gt=None):
|
||||
for param_group in self.optimG.param_groups:
|
||||
|
||||
Reference in New Issue
Block a user