def create_image_classification_test_case(**kwargs): expected_outputs_dir = os.path.join(os.path.dirname(__file__), '..', 'expected_outputs') TrainTestCase = create_test_case('image_classification', **kwargs, metric_keys=['accuracy'], expected_outputs_dir=expected_outputs_dir, batch_size=2) class ClassificationTrainTestCase(TrainTestCase): def do_finetuning(self, on_gpu): self.total_epochs = 5 log_file = os.path.join(self.output_folder, 'test_finetuning.log') initial_command = 'export CUDA_VISIBLE_DEVICES=;' if not on_gpu else '' run_through_shell( f'{initial_command}' f'cd {self.template_folder};' f'python3 train.py' f' --train-ann-files {self.ann_file}' f' --train-data-roots {os.path.join(self.img_root, "train")}' f' --val-ann-files {self.ann_file}' f' --val-data-roots {os.path.join(self.img_root, "val")}' f' --load-weights snapshot.pth' f' --save-checkpoints-to {self.output_folder}' f' --gpu-num 1' f' --batch-size {self.batch_size}' f' --epochs {self.total_epochs}' f' | tee {log_file}') self.assertTrue( os.path.exists(os.path.join(self.output_folder, 'latest.pth'))) return ClassificationTrainTestCase
def create_object_detection_test_case(**kwargs): expected_outputs_dir = os.path.join(os.path.dirname(__file__), '..', 'expected_outputs') return create_test_case('object_detection', **kwargs, metric_keys=['bbox'], expected_outputs_dir=expected_outputs_dir)
def create_image_classification_test_case(**kwargs): expected_outputs_dir = os.path.join(os.path.dirname(__file__), '..', 'expected_outputs') return create_test_case('image_classification', **kwargs, metric_keys=['accuracy'], expected_outputs_dir=expected_outputs_dir)
def create_text_spotting_test_case(**kwargs): expected_outputs_dir = os.path.join(os.path.dirname(__file__), '..', 'expected_outputs') TestCase = create_test_case('text_spotting', **kwargs, metric_keys=['f1', 'word_spotting'], expected_outputs_dir=expected_outputs_dir) return TestCase
def create_action_recognition_test_case(enable_metrics_eval=True, **kwargs): expected_outputs_dir = os.path.join(os.path.dirname(__file__), '..', 'expected_outputs') TrainTestCase = create_test_case('action_recognition', **kwargs, metric_keys=['accuracy'], expected_outputs_dir=expected_outputs_dir, batch_size=2) class ActionRecognitionTrainTestCase(TrainTestCase): def do_finetuning(self, on_gpu): self.total_epochs = 5 log_file = os.path.join(self.output_folder, 'test_finetuning.log') initial_command = 'export CUDA_VISIBLE_DEVICES=;' if not on_gpu else '' run_through_shell(f'{initial_command}' f'cd {self.template_folder};' f'python3 train.py' f' --train-ann-files {self.ann_file}' f' --train-data-roots {self.img_root}' f' --val-ann-files {self.ann_file}' f' --val-data-roots {self.img_root}' f' --load-weights snapshot.pth' f' --save-checkpoints-to {self.output_folder}' f' --gpu-num 1' f' --batch-size {self.batch_size}' f' --epochs {self.total_epochs}' f' | tee {log_file}') self.assertTrue( os.path.exists(os.path.join(self.output_folder, 'latest.pth'))) if enable_metrics_eval: return ActionRecognitionTrainTestCase class CustomActionRecognitionTrainTestCase(ActionRecognitionTrainTestCase): def do_evaluation(self, on_gpu): initial_command = 'export CUDA_VISIBLE_DEVICES=;' if not on_gpu else '' metrics_path = os.path.join(self.output_folder, "metrics.yaml") run_through_shell(f'{initial_command}' f'cd {self.template_folder};' f'python3 eval.py' f' --test-ann-files {self.ann_file}' f' --test-data-roots {self.img_root}' f' --save-metrics-to {metrics_path}' f' --load-weights snapshot.pth') self.assertTrue(os.path.exists(metrics_path)) return CustomActionRecognitionTrainTestCase
def create_instance_segmentation_test_case(**kwargs): expected_outputs_dir = os.path.join(os.path.dirname(__file__), '..', 'expected_outputs') TestCase = create_test_case('instance_segmentation_2', **kwargs, metric_keys=['bbox', 'segm'], expected_outputs_dir=expected_outputs_dir) class InstanceSegmenationTestCase(TestCase): @classmethod def setUpClass(cls): super().setUpClass() coco_dir = os.path.abspath(f'{os.path.dirname(__file__)}/../../../../data/coco') download_and_extract_coco_val2017(coco_dir) return InstanceSegmenationTestCase