Пример #1
0
    def test_yuv_color_transforms(self):
        default_cfg = Detectron2GoRunner().get_default_cfg()
        img = np.concatenate(
            [
                np.random.uniform(0, 1, size=(80, 60, 1)),
                np.random.uniform(-0.5, 0.5, size=(80, 60, 1)),
                np.random.uniform(-0.5, 0.5, size=(80, 60, 1)),
            ],
            axis=2,
        )

        default_cfg.D2GO_DATA.AUG_OPS.TRAIN = [
            'RandomContrastYUVOp::{"intensity_min": 0.3, "intensity_max": 0.5}',
        ]
        low_contrast_tfm = build_transform_gen(default_cfg, is_train=True)
        low_contrast, _ = apply_augmentations(low_contrast_tfm, img)

        default_cfg.D2GO_DATA.AUG_OPS.TRAIN = [
            'RandomSaturationYUVOp::{"intensity_min": 1.5, "intensity_max": 1.7}',
        ]
        high_saturation_tfm = build_transform_gen(default_cfg, is_train=True)
        high_saturation, _ = apply_augmentations(high_saturation_tfm, img)

        # Use pixel statistics to roughly check transformed images as expected
        # All channels have less variance
        self.assertLess(np.var(low_contrast[:, :, 0]), np.var(img[:, :, 0]))
        self.assertLess(np.var(low_contrast[:, :, 1]), np.var(img[:, :, 1]))
        self.assertLess(np.var(low_contrast[:, :, 2]), np.var(img[:, :, 2]))

        # 1st channel is unchanged (test w/ mean, var), 2nd + 3rd channels more variance
        self.assertAlmostEqual(np.mean(high_saturation[:, :, 0]), np.mean(img[:, :, 0]))
        self.assertAlmostEqual(np.var(high_saturation[:, :, 0]), np.var(img[:, :, 0]))
        self.assertGreater(np.var(high_saturation[:, :, 1]), np.var(img[:, :, 1]))
        self.assertGreater(np.var(high_saturation[:, :, 2]), np.var(img[:, :, 2]))
Пример #2
0
    def test_build_transform_gen(self):
        default_cfg = Detectron2GoRunner().get_default_cfg()
        default_cfg.INPUT.MIN_SIZE_TRAIN = (30, )
        default_cfg.INPUT.MIN_SIZE_TEST = 30

        trans_train = build_transform_gen(default_cfg, is_train=True)
        trans_test = build_transform_gen(default_cfg, is_train=False)

        img = np.zeros((80, 60, 3))
        trans_img_train, tl_train = apply_transform_gens(trans_train, img)
        trans_img_test, tl_test = apply_transform_gens(trans_test, img)

        self.assertEqual(trans_img_train.shape, (40, 30, 3))
        self.assertEqual(trans_img_test.shape, (40, 30, 3))
Пример #3
0
    def test_build_transform_gen_resize_square(self):
        default_cfg = Detectron2GoRunner().get_default_cfg()
        default_cfg.INPUT.MIN_SIZE_TRAIN = (30, )
        default_cfg.INPUT.MIN_SIZE_TEST = 40
        default_cfg.D2GO_DATA.AUG_OPS.TRAIN = ["ResizeShortestEdgeSquareOp"]
        default_cfg.D2GO_DATA.AUG_OPS.TEST = ["ResizeShortestEdgeSquareOp"]

        trans_train = build_transform_gen(default_cfg, is_train=True)
        trans_test = build_transform_gen(default_cfg, is_train=False)

        img = np.zeros((80, 60, 3))
        trans_img_train, tl_train = apply_transform_gens(trans_train, img)
        trans_img_test, tl_test = apply_transform_gens(trans_test, img)

        self.assertEqual(trans_img_train.shape, (30, 30, 3))
        self.assertEqual(trans_img_test.shape, (40, 40, 3))
Пример #4
0
    def test_enlarge_bounding_box(self):
        default_cfg = get_default_config()

        default_cfg.D2GO_DATA.AUG_OPS.TRAIN = [
            'EnlargeBoundingBoxOp::{"fixed_pad": 20}',
            'EnlargeBoundingBoxOp::{"percentage": 0.2}',
        ]
        enlarge_box_tfm = build_transform_gen(default_cfg, is_train=True)

        boxes = np.array(
            [[91, 46, 144, 111]],
            dtype=np.float64,
        )
        transformed_bboxs = enlarge_box_tfm[0].apply_box(boxes)
        expected_bboxs = np.array(
            [[71, 26, 164, 131]],
            dtype=np.float64,
        )
        err_msg = "transformed_bbox = {}, expected {}".format(
            transformed_bboxs, expected_bboxs)
        self.assertTrue(np.allclose(transformed_bboxs, expected_bboxs),
                        err_msg)

        boxes = np.array(
            [[91, 46, 144, 111]],
            dtype=np.float64,
        )
        transformed_bboxs = enlarge_box_tfm[1].apply_box(boxes)
        expected_bboxs = np.array(
            [[85.7, 39.5, 149.3, 117.5]],
            dtype=np.float64,
        )
        err_msg = "transformed_bbox = {}, expected {}".format(
            transformed_bboxs, expected_bboxs)
        self.assertTrue(np.allclose(transformed_bboxs, expected_bboxs),
                        err_msg)

        dummy_data = np.array(
            [[91, 46, 144, 111]],
            dtype=np.float64,
        )
        dummy_data_out = enlarge_box_tfm[1].apply_image(dummy_data)
        expected_out = np.array(
            [[91, 46, 144, 111]],
            dtype=np.float64,
        )
        err_msg = "Apply image failed"
        self.assertTrue(np.allclose(dummy_data_out, expected_out), err_msg)
Пример #5
0
 def get_mapper(cfg, is_train):
     tfm_gens = build_transform_gen(cfg, is_train)
     mapper = build_dataset_mapper(cfg, is_train, tfm_gens=tfm_gens)
     return mapper