Repository navigation
Expand file tree
/
Copy pathutils.py
More file actions
71 lines (45 loc) · 1.65 KB
/
Copy pathutils.py
File metadata and controls
71 lines (45 loc) · 1.65 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
'''
Some useful functions
'''
from PIL import Image
import zipfile
import io
import cv2
def load_zipframe(zipdata, name, resize=False):
stream = zipdata.read(name)
data = Image.open(io.BytesIO(stream))
assert(data.size[1] == 256)
assert(data.size[0] == 340)
if resize:
data = data.resize((224, 224), Image.ANTIALIAS)
data = np.array(data)
data = data.astype(float)
data = (data * 2 / 255) - 1
assert(data.max()<=1.0)
assert(data.min()>=-1.0)
return data
def load_ziprgb_batch(rgb_zipdata, rgb_files,
frame_indices, resize=False):
if resize:
batch_data = np.zeros(frame_indices.shape + (224,224,3))
else:
batch_data = np.zeros(frame_indices.shape + (256,340,3))
for i in range(frame_indices.shape[0]):
for j in range(frame_indices.shape[1]):
batch_data[i,j,:,:,:] = load_zipframe(rgb_zipdata,
rgb_files[frame_indices[i][j]], resize)
return batch_data
def load_zipflow_batch(flow_x_zipdata, flow_y_zipdata,
flow_x_files, flow_y_files,
frame_indices, resize=False):
if resize:
batch_data = np.zeros(frame_indices.shape + (224,224,2))
else:
batch_data = np.zeros(frame_indices.shape + (256,340,2))
for i in range(frame_indices.shape[0]):
for j in range(frame_indices.shape[1]):
batch_data[i,j,:,:,0] = load_zipframe(flow_x_zipdata,
flow_x_files[frame_indices[i][j]], resize)
batch_data[i,j,:,:,1] = load_zipframe(flow_y_zipdata,
flow_y_files[frame_indices[i][j]], resize)
return batch_data