@@ -1032,5 +1032,65 @@ def test_not_found_or_corrupted(self):
1032
1032
self .skipTest ("Dataset currently does not handle the case of no found videos." )
1033
1033
1034
1034
1035
+ class HMDB51TestCase (datasets_utils .VideoDatasetTestCase ):
1036
+ DATASET_CLASS = datasets .HMDB51
1037
+
1038
+ CONFIGS = datasets_utils .combinations_grid (fold = (1 , 2 , 3 ), train = (True , False ))
1039
+
1040
+ _VIDEO_FOLDER = "videos"
1041
+ _SPLITS_FOLDER = "splits"
1042
+ _CLASSES = ("brush_hair" , "wave" )
1043
+
1044
+ def dataset_args (self , tmpdir , config ):
1045
+ tmpdir = pathlib .Path (tmpdir )
1046
+ root = tmpdir / self ._VIDEO_FOLDER
1047
+ annotation_path = tmpdir / self ._SPLITS_FOLDER
1048
+ return root , annotation_path
1049
+
1050
+ def inject_fake_data (self , tmpdir , config ):
1051
+ tmpdir = pathlib .Path (tmpdir )
1052
+
1053
+ video_folder = tmpdir / self ._VIDEO_FOLDER
1054
+ os .makedirs (video_folder )
1055
+ video_files = self ._create_videos (video_folder )
1056
+
1057
+ splits_folder = tmpdir / self ._SPLITS_FOLDER
1058
+ os .makedirs (splits_folder )
1059
+ num_examples = self ._create_split_files (splits_folder , video_files , config ["fold" ], config ["train" ])
1060
+
1061
+ return num_examples
1062
+
1063
+ def _create_videos (self , root , num_examples_per_class = 3 ):
1064
+ def file_name_fn (cls , idx , clips_per_group = 2 ):
1065
+ return f"{ cls } _{ (idx // clips_per_group ) + 1 :d} _{ (idx % clips_per_group ) + 1 :d} .avi"
1066
+
1067
+ return [
1068
+ (
1069
+ cls ,
1070
+ datasets_utils .create_video_folder (
1071
+ root ,
1072
+ cls ,
1073
+ lambda idx : file_name_fn (cls , idx ),
1074
+ num_examples_per_class ,
1075
+ ),
1076
+ )
1077
+ for cls in self ._CLASSES
1078
+ ]
1079
+
1080
+ def _create_split_files (self , root , video_files , fold , train ):
1081
+ num_videos = num_train_videos = 0
1082
+
1083
+ for cls , videos in video_files :
1084
+ num_videos += len (videos )
1085
+
1086
+ train_videos = set (random .sample (videos , random .randrange (1 , len (videos ) - 1 )))
1087
+ num_train_videos += len (train_videos )
1088
+
1089
+ with open (pathlib .Path (root ) / f"{ cls } _test_split{ fold } .txt" , "w" ) as fh :
1090
+ fh .writelines (f"{ file .name } { 1 if file in train_videos else 2 } \n " for file in videos )
1091
+
1092
+ return num_train_videos if train else (num_videos - num_train_videos )
1093
+
1094
+
1035
1095
if __name__ == "__main__" :
1036
1096
unittest .main ()
0 commit comments