@@ -34,9 +34,9 @@ def cvat2slowfast(path_to_mini_scenes: str, path_to_new_dataset: str,
3434 with open (f"{ path_to_new_dataset } /annotation/classes.json" , "w" ) as file :
3535 json .dump (label2number , file )
3636
37- headers = { "original_vido_id" : [] , "video_id" : pd . Series ( dtype = "int" ) , "frame_id" : pd . Series ( dtype = "int" ),
38- "path" : [], "labels" : []}
39- charades_df = pd . DataFrame ( data = headers )
37+ headers = [ "original_vido_id" , "video_id" , "frame_id" , "path" , "labels" ]
38+ charades_data = []
39+
4040 video_id = 1
4141 folder_name = 1
4242
@@ -127,13 +127,11 @@ def cvat2slowfast(path_to_mini_scenes: str, path_to_new_dataset: str,
127127 if not no_images :
128128 cv2 .imwrite (f"{ output_folder } /{ adjusted_index } .jpg" , frame )
129129
130- # TODO: Major slow down here. Add to a list rather than dataframe,
131- # and create dataframe at the end.
132- charades_df .loc [len (charades_df .index )] = [f"{ folder_code } " ,
133- video_id ,
134- adjusted_index ,
135- f"{ folder_code } /{ adjusted_index } .jpg" ,
136- str (label2number [behavior ])]
130+ charades_data .append ([f"{ folder_code } " ,
131+ video_id ,
132+ adjusted_index ,
133+ f"{ folder_code } /{ adjusted_index } .jpg" ,
134+ str (label2number [behavior ])])
137135
138136 adjusted_index += 1
139137
@@ -145,9 +143,11 @@ def cvat2slowfast(path_to_mini_scenes: str, path_to_new_dataset: str,
145143 video_id += 1
146144
147145 if video_id % 10 == 0 :
146+ charades_df = pd .DataFrame (charades_data , columns = headers )
148147 charades_df .to_csv (
149148 f"{ path_to_new_dataset } /annotation/data.csv" , sep = " " , index = False )
150149
150+ charades_df = pd .DataFrame (charades_data , columns = headers )
151151 charades_df .to_csv (
152152 f"{ path_to_new_dataset } /annotation/data.csv" , sep = " " , index = False )
153153
@@ -203,4 +203,4 @@ def main() -> None:
203203
204204
205205if __name__ == "__main__" :
206- main ()
206+ main ()
0 commit comments