@@ -2275,5 +2275,87 @@ def inject_fake_data(self, tmpdir, config):
22752275 return num_samples
22762276
22772277
2278+ class GTSRBTestCase (datasets_utils .ImageDatasetTestCase ):
2279+ DATASET_CLASS = datasets .GTSRB
2280+ FEATURE_TYPES = (PIL .Image .Image , int )
2281+
2282+ ADDITIONAL_CONFIGS = datasets_utils .combinations_grid (train = (True , False ))
2283+
2284+ def inject_fake_data (self , tmpdir : str , config ):
2285+ root_folder = os .path .join (tmpdir , "GTSRB" )
2286+ os .makedirs (root_folder , exist_ok = True )
2287+
2288+ # Train data
2289+ train_folder = os .path .join (root_folder , "Training" )
2290+ os .makedirs (train_folder , exist_ok = True )
2291+
2292+ num_examples = 3
2293+ classes = ("00000" , "00042" , "00012" )
2294+ for class_idx in classes :
2295+ datasets_utils .create_image_folder (
2296+ train_folder ,
2297+ name = class_idx ,
2298+ file_name_fn = lambda image_idx : f"{ class_idx } _{ image_idx :05d} .ppm" ,
2299+ num_examples = num_examples ,
2300+ )
2301+
2302+ total_number_of_examples = num_examples * len (classes )
2303+ # Test data
2304+ test_folder = os .path .join (root_folder , "Final_Test" , "Images" )
2305+ os .makedirs (test_folder , exist_ok = True )
2306+
2307+ with open (os .path .join (root_folder , "GT-final_test.csv" ), "w" ) as csv_file :
2308+ csv_file .write ("Filename;Width;Height;Roi.X1;Roi.Y1;Roi.X2;Roi.Y2;ClassId\n " )
2309+
2310+ for _ in range (total_number_of_examples ):
2311+ image_file = datasets_utils .create_random_string (5 , string .digits ) + ".ppm"
2312+ datasets_utils .create_image_file (test_folder , image_file )
2313+ row = [
2314+ image_file ,
2315+ torch .randint (1 , 100 , size = ()).item (),
2316+ torch .randint (1 , 100 , size = ()).item (),
2317+ torch .randint (1 , 100 , size = ()).item (),
2318+ torch .randint (1 , 100 , size = ()).item (),
2319+ torch .randint (1 , 100 , size = ()).item (),
2320+ torch .randint (1 , 100 , size = ()).item (),
2321+ torch .randint (0 , 43 , size = ()).item (),
2322+ ]
2323+ csv_file .write (";" .join (map (str , row )) + "\n " )
2324+
2325+ return total_number_of_examples
2326+
2327+
2328+ class CLEVRClassificationTestCase (datasets_utils .ImageDatasetTestCase ):
2329+ DATASET_CLASS = datasets .CLEVRClassification
2330+ FEATURE_TYPES = (PIL .Image .Image , (int , type (None )))
2331+
2332+ ADDITIONAL_CONFIGS = datasets_utils .combinations_grid (split = ("train" , "val" , "test" ))
2333+
2334+ def inject_fake_data (self , tmpdir , config ):
2335+ data_folder = pathlib .Path (tmpdir ) / "clevr" / "CLEVR_v1.0"
2336+
2337+ images_folder = data_folder / "images"
2338+ image_files = datasets_utils .create_image_folder (
2339+ images_folder , config ["split" ], lambda idx : f"CLEVR_{ config ['split' ]} _{ idx :06d} .png" , num_examples = 5
2340+ )
2341+
2342+ scenes_folder = data_folder / "scenes"
2343+ scenes_folder .mkdir ()
2344+ if config ["split" ] != "test" :
2345+ with open (scenes_folder / f"CLEVR_{ config ['split' ]} _scenes.json" , "w" ) as file :
2346+ json .dump (
2347+ dict (
2348+ info = dict (),
2349+ scenes = [
2350+ dict (image_filename = image_file .name , objects = [dict ()] * int (torch .randint (10 , ())))
2351+ for image_file in image_files
2352+ ],
2353+ ),
2354+ file ,
2355+ )
2356+
2357+ return len (image_files )
2358+
2359+
22782360if __name__ == "__main__" :
22792361 unittest .main ()
0 commit comments