forked from nbei/Deep-Flow-Guided-Video-Inpainting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFlowInfer.py
55 lines (42 loc) · 1.66 KB
/
FlowInfer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import torch
import cv2
import numpy as np
import torch.utils.data
class FlowInfer(torch.utils.data.Dataset):
def __init__(self, list_file, size=None, isRGB=True, start_pos=0):
super(FlowInfer, self).__init__()
self.size = size
txt_file = open(list_file, 'r')
self.frame1_list = []
self.frame2_list = []
self.output_list = []
self.isRGB = isRGB
for line in txt_file:
line = line.strip(' ')
line = line.strip('\n')
line_split = line.split(' ')
self.frame1_list.append(line_split[0])
self.frame2_list.append(line_split[1])
self.output_list.append(line_split[2])
if start_pos > 0:
self.frame1_list = self.frame1_list[start_pos:]
self.frame2_list = self.frame2_list[start_pos:]
self.output_list = self.output_list[start_pos:]
txt_file.close()
def __len__(self):
return len(self.frame1_list)
def __getitem__(self, idx):
frame1 = cv2.imread(self.frame1_list[idx])
frame2 = cv2.imread(self.frame2_list[idx])
if self.isRGB:
frame1 = frame1[:, :, ::-1]
frame2 = frame2[:, :, ::-1]
output_path = self.output_list[idx]
frame1 = self._img_tf(frame1)
frame2 = self._img_tf(frame2)
frame1_tensor = torch.from_numpy(frame1).permute(2, 0, 1).contiguous().float()
frame2_tensor = torch.from_numpy(frame2).permute(2, 0, 1).contiguous().float()
return frame1_tensor, frame2_tensor, output_path
def _img_tf(self, img):
img = cv2.resize(img, (self.size[1], self.size[0]))
return img