-
Notifications
You must be signed in to change notification settings - Fork 61
/
data_utils.py
80 lines (58 loc) · 2.45 KB
/
data_utils.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import os
from gluoncv.torch.data.gluoncv_motion_dataset.dataset import GluonCVMotionDataset
from pycocotools.coco import COCO
from .dataset_info import dataset_maps
def load_motion_anno(dataset_folder,
anno_file,
split_file,
set=None,
):
"""
Load GluonCVMotionDataset format annotations for downstream training / testing
"""
dataset = GluonCVMotionDataset(anno_file,
root_path=dataset_folder,
split_file=split_file
)
if set == 'train':
dataset = list(dataset.train_samples)
elif set == 'val':
dataset = list(dataset.val_samples)
elif set == 'test':
dataset = list(dataset.test_samples)
return dataset
def load_coco_anno(dataset_folder,
anno_file):
dataset_anno_path = os.path.join(dataset_folder, anno_file)
dataset = COCO(dataset_anno_path)
return dataset
def load_dataset_anno(cfg, dataset_key, set=None):
dataset_folder, anno_file, split_file, modality = dataset_maps[dataset_key]
dataset_info = dict()
dataset_info['modality'] = modality
dataset_folder = os.path.join(cfg.DATASETS.ROOT_DIR, dataset_folder)
if modality == 'video':
dataset = load_motion_anno(dataset_folder,
anno_file,
split_file,
set)
elif modality == 'image':
dataset = load_coco_anno(dataset_folder,
anno_file)
image_folder = os.path.join(dataset_folder, split_file)
dataset_info['image_folder'] = image_folder
else:
raise ValueError("dataset has to be video or image.")
return dataset, dataset_info
def load_public_detection(cfg, dataset_key):
dataset_folder, _, split_file, _ = dataset_maps[dataset_key]
dataset_folder = os.path.join(cfg.DATASETS.ROOT_DIR, dataset_folder)
try:
public_detection = load_motion_anno(dataset_folder,
'anno_pub_detection.json',
split_file)
except:
print("The public detection is not ingested or provided in {}, skip public detection".
format(os.path.join(dataset_folder, 'annotation/anno_pub_detection.json')))
return None
return public_detection