5
5
from typing import Union
6
6
7
7
import cv2
8
- import json
9
8
import tqdm
10
9
11
10
@@ -16,7 +15,7 @@ def create_valid_indices(self, pairs: list):
16
15
description_prefix = "Checking validity: "
17
16
18
17
tqdm_iterator = tqdm .tqdm (pairs , desc = description_prefix )
19
- for video_index , (video_file_path , json_file_path ) in enumerate (tqdm_iterator ):
18
+ for video_index , (video_file_path , annotation_file_path ) in enumerate (tqdm_iterator ):
20
19
tqdm_iterator .set_description (description_prefix + video_file_path )
21
20
22
21
label = self .extract_label (video_file_path )
@@ -28,14 +27,13 @@ def create_valid_indices(self, pairs: list):
28
27
29
28
valid_frame_indices = []
30
29
31
- with open (json_file_path ) as file :
32
- annotations = json .load (file )
30
+ annotations = self .parse_annotation (annotation_file_path )
33
31
34
- for frame_index , annotation in enumerate (annotations ):
35
- if self .is_valid_annotation (video_width , video_height , annotation ) is False :
36
- continue
32
+ for frame_index , annotation in enumerate (annotations ):
33
+ if self .is_valid_annotation (video_width , video_height , annotation ) is False :
34
+ continue
37
35
38
- valid_frame_indices .append (frame_index )
36
+ valid_frame_indices .append (frame_index )
39
37
40
38
if len (valid_frame_indices ) == 0 :
41
39
continue
@@ -57,17 +55,17 @@ def get_train_filename(self, label: Union[int, str], index: int):
57
55
video_indices = sorted (list (self .train_valid_indices [label ].keys ()))
58
56
video_index = video_indices [index ]
59
57
60
- movie_file_path , json_file_path = self .train_pairs [video_index ]
58
+ movie_file_path , annotation_file_path = self .train_pairs [video_index ]
61
59
62
- return movie_file_path , json_file_path
60
+ return movie_file_path , annotation_file_path
63
61
64
62
def get_validation_filename (self , label : Union [int , str ], index : int ):
65
63
video_indices = sorted (list (self .validation_valid_indices [label ].keys ()))
66
64
video_index = video_indices [index ]
67
65
68
- movie_file_path , json_file_path = self .validation_pairs [video_index ]
66
+ movie_file_path , annotation_file_path = self .validation_pairs [video_index ]
69
67
70
- return movie_file_path , json_file_path
68
+ return movie_file_path , annotation_file_path
71
69
72
70
def get_train_datum (self , label , index ):
73
71
video_indices = sorted (list (self .train_valid_indices [label ].keys ()))
@@ -76,11 +74,10 @@ def get_train_datum(self, label, index):
76
74
random .seed (None )
77
75
frame_index = random .choice (self .train_valid_indices [label ][video_index ])
78
76
79
- movie_file_path , json_file_path = self .train_pairs [video_index ]
77
+ movie_file_path , annotation_file_path = self .train_pairs [video_index ]
80
78
81
- with open (json_file_path ) as json_file :
82
- annotations = json .load (json_file )
83
- annotation = annotations [frame_index ]
79
+ annotations = self .parse_annotation (annotation_file_path )
80
+ annotation = annotations [frame_index ]
84
81
85
82
video = cv2 .VideoCapture (movie_file_path )
86
83
video .set (cv2 .CAP_PROP_POS_FRAMES , frame_index )
@@ -96,11 +93,10 @@ def get_validation_datum(self, label, index):
96
93
random .seed (self .random_salt + index )
97
94
frame_index = random .choice (self .validation_valid_indices [label ][video_index ])
98
95
99
- movie_file_path , json_file_path = self .validation_pairs [video_index ]
96
+ movie_file_path , annotation_file_path = self .validation_pairs [video_index ]
100
97
101
- with open (json_file_path ) as json_file :
102
- annotations = json .load (json_file )
103
- annotation = annotations [frame_index ]
98
+ annotations = self .parse_annotation (annotation_file_path )
99
+ annotation = annotations [frame_index ]
104
100
105
101
video = cv2 .VideoCapture (movie_file_path )
106
102
video .set (cv2 .CAP_PROP_POS_FRAMES , frame_index )
0 commit comments