-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprocess_selected_bdd100k_val.py
51 lines (37 loc) · 1.38 KB
/
process_selected_bdd100k_val.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
'''
Code for processing BDD100K dataset - validation part (Yu et al. 2020, https://bdd-data.berkeley.edu/).
Based on code related to PredNet - Lotter et al. 2016 (https://arxiv.org/abs/1605.08104 https://github.com/coxlab/prednet).
Method of resizing was specified (bicubic).
'''
import os, pdb
import imageio, random
import hickle as hkl
import h5py
import numpy as np
from scipy.misc import imresize
from scipy.misc import toimage
from kitti_settings import *
desired_sz = (128, 160)
# change 30fps to 10 fps
offset = 0
shift = 3
sources_name = "sources_bdd100k_val_10K.hkl"
#use the same sequences as were used during training
sources = hkl.load(DATA_DIR+sources_name)
sel_sequences = []
for seq in sources:
if seq not in sel_sequences:
sel_sequences.append(seq)
X=[]
for sequence in sel_sequences:
vid = imageio.get_reader(DATA_DIR+"raw_bdd100k_dataset/bdd100k/videos/"+"val/"+sequence, 'ffmpeg', fps=30)
for i, im in enumerate(vid):
# change 30fps to 10 fps
if (i-offset) % shift == 0:
target_ds = float(desired_sz[0]) / im.shape[0]
im = imresize(im, (desired_sz[0], int(np.round(target_ds * im.shape[1]))), 'bicubic')
d = int((im.shape[1] - desired_sz[1]) / 2)
im = im[:, d:d + desired_sz[1]]
X.append(im)
X = np.array(X)
hkl.dump(X, os.path.join(DATA_DIR, 'X_bdd100k_val_10K' + '.hkl'))