Exemplo n.º 1
0
    def __init__(self, cfg, is_train=True):
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE,
                                         cfg.INPUT.CROP.SIZE)
            logging.getLogger(__name__).info("CropGen used in training: " +
                                             str(self.crop_gen))
        else:
            self.crop_gen = None

        self.tfm_gens = utils.build_transform_gen(cfg, is_train)

        if cfg.INPUT.COLOR_AUG_SSD:
            self.tfm_gens.append(
                ColorAugSSDTransform(img_format=cfg.INPUT.FORMAT))
            logging.getLogger(
                __name__).info("Color augmnetation used in training: " +
                               str(self.tfm_gens[-1]))

        # fmt: off
        self.img_format = cfg.INPUT.FORMAT
        self.single_category_max_area = cfg.INPUT.CROP.SINGLE_CATEGORY_MAX_AREA
        self.ignore_value = cfg.MODEL.SEM_SEG_HEAD.IGNORE_VALUE
        # fmt: on

        self.is_train = is_train
    def __init__(self, cfg, is_train=True):
        if cfg.INPUT.CROP.ENABLED:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE)
            logging.getLogger(__name__).info("CropGen used in training: " + str(self.crop_gen))
        else:
            self.crop_gen = None

        self.tfm_gens = utils.build_transform_gen(cfg, is_train)

        # fmt: off
        self.img_format = cfg.INPUT.FORMAT
        self.mask_on = cfg.MODEL.MASK_ON
        self.mask_format = cfg.INPUT.MASK_FORMAT
        self.keypoint_on = cfg.MODEL.KEYPOINT_ON
        self.load_proposals = cfg.MODEL.LOAD_PROPOSALS
        # fmt: on
        if self.keypoint_on and is_train:
            # Flip only makes sense in training
            self.keypoint_hflip_indices = utils.create_keypoint_hflip_indices(cfg.DATASETS.TRAIN)
        else:
            self.keypoint_hflip_indices = None

        if self.load_proposals:
            self.min_box_side_len = cfg.MODEL.PROPOSAL_GENERATOR.MIN_SIZE
            self.proposal_topk = (
                cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TRAIN
                if is_train
                else cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TEST
            )
        self.is_train = is_train
Exemplo n.º 3
0
    def __init__(self, cfg, is_train=True):
        self.tfm_gens = utils.build_transform_gen(cfg, is_train)

        # fmt: off
        self.img_format = cfg.INPUT.FORMAT
        self.mask_on = cfg.MODEL.MASK_ON
        self.keypoint_on = cfg.MODEL.KEYPOINT_ON
        self.densepose_on = cfg.MODEL.DENSEPOSE_ON
        assert not cfg.MODEL.LOAD_PROPOSALS, "not supported yet"
        # fmt: on
        if self.keypoint_on and is_train:
            # Flip only makes sense in training
            self.keypoint_hflip_indices = utils.create_keypoint_hflip_indices(
                cfg.DATASETS.TRAIN)
        else:
            self.keypoint_hflip_indices = None

        if self.densepose_on:
            densepose_transform_srcs = [
                MetadataCatalog.get(ds).densepose_transform_src
                for ds in cfg.DATASETS.TRAIN + cfg.DATASETS.TEST
            ]
            assert len(densepose_transform_srcs) > 0
            # TODO: check that DensePose transformation data is the same for
            # all the datasets. Otherwise one would have to pass DB ID with
            # each entry to select proper transformation data. For now, since
            # all DensePose annotated data uses the same data semantics, we
            # omit this check.
            densepose_transform_data_fpath = PathManager.get_local_path(
                densepose_transform_srcs[0])
            self.densepose_transform_data = DensePoseTransformData.load(
                densepose_transform_data_fpath)

        self.is_train = is_train
Exemplo n.º 4
0
    def __init__(self, cfg, is_train=True, dataset_names=None):
        self.tfm_gens = utils.build_transform_gen(cfg, is_train)

        # fmt: off
        self.img_format     = cfg.INPUT.FORMAT
        self.mask_on        = cfg.MODEL.MASK_ON
        self.voxel_on       = cfg.MODEL.VOXEL_ON
        self.mesh_on        = cfg.MODEL.MESH_ON
        self.zpred_on       = cfg.MODEL.ZPRED_ON
        # fmt: on

        if cfg.MODEL.LOAD_PROPOSALS:
            raise ValueError("Loading pre-computed proposals is not supported.")

        self.is_train = is_train

        assert dataset_names is not None
        # load unique obj meshes
        # Pix3D models are few in number (= 735) thus it's more efficient
        # to load them in memory rather than read them at every iteration
        all_mesh_models = {}
        for dataset_name in dataset_names:
            json_file = MetadataCatalog.get(dataset_name).json_file
            model_root = MetadataCatalog.get(dataset_name).image_root
            logger.info("Loading models from {}...".format(dataset_name))
            dataset_mesh_models = load_unique_meshes(json_file, model_root)
            all_mesh_models.update(dataset_mesh_models)
            logger.info("Unique objects loaded: {}".format(len(dataset_mesh_models)))

        self._all_mesh_models = all_mesh_models
Exemplo n.º 5
0
 def __init__(self, cfg, is_train=True):
     self.aug = self._get_aug(cfg.INPUT.ALBUMENTATIONS)
     self.img_format = cfg.INPUT.FORMAT
     self.resize_gen = utils.build_transform_gen(cfg, is_train)
     if cfg.INPUT.CROP.ENABLED and is_train:
         self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE)
     else:
         self.crop_gen = None
Exemplo n.º 6
0
    def __init__(self, cfg, is_train=True):
        self.tfm_gens = utils.build_transform_gen(cfg, is_train)


        # fmt: off
        self.img_format     = cfg.INPUT.FORMAT
        self.rota_aug_on    = cfg.MODEL.AVOD.ROTA_AUG_ON
        self.is_train = is_train
    def __init__(self, cfg, is_train=True):
        assert cfg.MODEL.MASK_ON, '今回はセグメンテーションのみを対象にする'
        assert not cfg.MODEL.KEYPOINT_ON, 'キーポイントは扱わない'
        assert not cfg.MODEL.LOAD_PROPOSALS, 'pre-computed proposals っていうのがよくわからん・・・・とりあえず無効前提で'

        self.cont_gen = None
        self.bright_gen = None
        self.sat_gen = None
        self.cutout_gen = None
        self.extent_gen = None
        self.crop_gen = None
        self.rotate_gen = None
        self.shear_gen = None

        if is_train:
            if cfg.INPUT.CONTRAST.ENABLED:
                self.cont_gen = T.RandomContrast(cfg.INPUT.CONTRAST.RANGE[0],
                                                 cfg.INPUT.CONTRAST.RANGE[1])
                logging.getLogger(__name__).info('ContGen used in training.')
            if cfg.INPUT.BRIGHTNESS.ENABLED:
                self.bright_gen = T.RandomBrightness(
                    cfg.INPUT.BRIGHTNESS.RANGE[0],
                    cfg.INPUT.BRIGHTNESS.RANGE[1])
                logging.getLogger(__name__).info('BrightGen used in training.')
            if cfg.INPUT.SATURATION.ENABLED:
                self.sat_gen = T.RandomSaturation(
                    cfg.INPUT.SATURATION.RANGE[0],
                    cfg.INPUT.SATURATION.RANGE[1])
                logging.getLogger(__name__).info('SatGen used in training.')
            if cfg.INPUT.CUTOUT.ENABLED:
                self.cutout_gen = RandomCutout(cfg.INPUT.CUTOUT.NUM_HOLE_RANGE,
                                               cfg.INPUT.CUTOUT.RADIUS_RANGE,
                                               cfg.INPUT.CUTOUT.COLOR_RANGE)
                logging.getLogger(__name__).info('CutoutGen used in training.')
            if cfg.INPUT.EXTENT.ENABLED:
                self.extent_gen = T.RandomExtent(
                    scale_range=(1, 1),
                    shift_range=cfg.INPUT.EXTENT.SHIFT_RANGE)
                logging.getLogger(__name__).info('ExtentGen used in training.')
            if cfg.INPUT.CROP.ENABLED:
                self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE,
                                             cfg.INPUT.CROP.SIZE)
                logging.getLogger(__name__).info('CropGen used in training: ' +
                                                 str(self.crop_gen))
            if cfg.INPUT.ROTATE.ENABLED:
                self.rotate_gen = T.RandomRotation(cfg.INPUT.ROTATE.ANGLE,
                                                   expand=False)
                logging.getLogger(__name__).info('RotateGen used in training.')
            if cfg.INPUT.SHEAR.ENABLED:
                self.shear_gen = RandomShear(cfg.INPUT.SHEAR.ANGLE_H_RANGE,
                                             cfg.INPUT.SHEAR.ANGLE_V_RANGE)
                logging.getLogger(__name__).info('ShearGen used in training.')

        self.tfm_gens = utils.build_transform_gen(cfg, is_train)

        self.img_format = cfg.INPUT.FORMAT
        self.mask_format = cfg.INPUT.MASK_FORMAT
        self.is_train = is_train
Exemplo n.º 8
0
def build_transform_gen(cfg, is_train):
    logger = logging.getLogger(__name__)
    result = utils.build_transform_gen(cfg, is_train)
    if is_train:
        random_rotation = T.RandomRotation(cfg.INPUT.ROTATION_ANGLES,
                                           expand=False,
                                           sample_style="choice")
        result.append(random_rotation)
        logger.info("DensePose-specific TransformGens used in training: " +
                    str(random_rotation))
    return result
Exemplo n.º 9
0
    def __init__(self, cfg, is_train=True):
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = d2_transforms.RandomCrop(
                    cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE)
            logging.getLogger(__name__).info(
                    "CropGen used in training: " + str(self.crop_gen))
        else:
            self.crop_gen = None

        self.tfm_gens = d2_dutils.build_transform_gen(cfg, is_train)
        self.is_train = is_train
Exemplo n.º 10
0
    def __init__(self, cfg, is_train=True):
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE,
                                         cfg.INPUT.CROP.SIZE)
            logging.getLogger(__name__).info("CropGen used in training: " +
                                             str(self.crop_gen))
        else:
            self.crop_gen = None

        self.tfm_gens = utils.build_transform_gen(cfg, is_train)

        # fmt: off
        self.img_format = cfg.INPUT.FORMAT
        self.mask_on = cfg.MODEL.MASK_ON
        self.mask_format = cfg.INPUT.MASK_FORMAT
        self.keypoint_on = cfg.MODEL.KEYPOINT_ON
        self.load_proposals = cfg.MODEL.LOAD_PROPOSALS

        self.few_shot = cfg.INPUT.FS.FEW_SHOT
        self.support_way = cfg.INPUT.FS.SUPPORT_WAY
        self.support_shot = cfg.INPUT.FS.SUPPORT_SHOT
        # fmt: on
        if self.keypoint_on and is_train:
            # Flip only makes sense in training
            self.keypoint_hflip_indices = utils.create_keypoint_hflip_indices(
                cfg.DATASETS.TRAIN)
        else:
            self.keypoint_hflip_indices = None

        if self.load_proposals:
            self.proposal_min_box_size = cfg.MODEL.PROPOSAL_GENERATOR.MIN_SIZE
            self.proposal_topk = (cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TRAIN
                                  if is_train else
                                  cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TEST)
        self.is_train = is_train

        if self.is_train:
            # support_df
            self.support_on = True
            if self.few_shot:
                self.support_df = pd.read_pickle(
                    "./datasets/coco/10_shot_support_df.pkl")
            else:
                self.support_df = pd.read_pickle(
                    "./datasets/coco/train_support_df.pkl")

            metadata = MetadataCatalog.get('coco_2017_train')
            # unmap the category mapping ids for COCO
            reverse_id_mapper = lambda dataset_id: metadata.thing_dataset_id_to_contiguous_id[
                dataset_id]  # noqa
            self.support_df['category_id'] = self.support_df[
                'category_id'].map(reverse_id_mapper)
Exemplo n.º 11
0
    def __init__(self, cfg, is_train=True, image_loader=None, tfm_gens=None):
        self.tfm_gens = (tfm_gens if tfm_gens is not None else
                         utils.build_transform_gen(cfg, is_train))

        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE,
                                         cfg.INPUT.CROP.SIZE)
            # D2GO NOTE: when INPUT.CROP.ENABLED, don't allow using RandomCropOp
            assert all(not isinstance(gen, T.RandomCrop)
                       for gen in self.tfm_gens)
        else:
            self.crop_gen = None

        # fmt: off
        self.img_format = cfg.INPUT.FORMAT  # noqa
        self.mask_on = cfg.MODEL.MASK_ON  # noqa
        self.mask_format = cfg.INPUT.MASK_FORMAT  # noqa
        self.keypoint_on = cfg.MODEL.KEYPOINT_ON  # noqa
        # fmt: on
        if self.keypoint_on and is_train:
            # Flip only makes sense in training
            self.keypoint_hflip_indices = utils.create_keypoint_hflip_indices(
                cfg.DATASETS.TRAIN)
        else:
            self.keypoint_hflip_indices = None

        self.load_proposals = cfg.MODEL.LOAD_PROPOSALS
        if self.load_proposals:
            self.proposal_min_box_size = cfg.MODEL.PROPOSAL_GENERATOR.MIN_SIZE
            self.proposal_topk = (cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TRAIN
                                  if is_train else
                                  cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TEST)

        self.is_train = is_train

        # Setup image loader:
        self.image_loader = image_loader
        self.backfill_size = cfg.D2GO_DATA.MAPPER.BACKFILL_SIZE
        self.retry = cfg.D2GO_DATA.MAPPER.RETRY
        self.catch_exception = cfg.D2GO_DATA.MAPPER.CATCH_EXCEPTION

        if self.backfill_size:
            if cfg.DATALOADER.ASPECT_RATIO_GROUPING:
                logger.warning(
                    "ASPECT_RATIO_GROUPING may not work if image's width & height"
                    " are not given in json dataset when calling extended_coco_load,"
                    " if you encounter issue, consider disable ASPECT_RATIO_GROUPING."
                )

        self._error_count = 0
        self._total_counts = 0
        self._error_types = {}
Exemplo n.º 12
0
    def test_apply_rotated_boxes(self):
        np.random.seed(125)
        cfg = get_cfg()
        is_train = True
        transform_gen = detection_utils.build_transform_gen(cfg, is_train)
        image = np.random.rand(200, 300)
        image, transforms = T.apply_transform_gens(transform_gen, image)
        image_shape = image.shape[:2]  # h, w
        assert image_shape == (800, 1200)
        annotation = {"bbox": [179, 97, 62, 40, -56]}

        boxes = np.array([annotation["bbox"]], dtype=np.float64)  # boxes.shape = (1, 5)
        transformed_bbox = transforms.apply_rotated_box(boxes)[0]

        expected_bbox = np.array([484, 388, 248, 160, 56], dtype=np.float64)
        err_msg = "transformed_bbox = {}, expected {}".format(transformed_bbox, expected_bbox)
        assert np.allclose(transformed_bbox, expected_bbox), err_msg
def packData(input_csv_file, cfg):
    transform = utils.build_transform_gen(cfg, is_train=False)
    dataset = ForeignObjectTestDataset('', input_csv_file, transform=transform)
    sampler = samplers.InferenceSampler(len(dataset))
    # Always use 1 image per worker during inference since this is the
    # standard when reporting inference time in papers.
    batch_sampler = torch.utils.data.sampler.BatchSampler(sampler,
                                                          1,
                                                          drop_last=False)

    data_loader = torch.utils.data.DataLoader(
        dataset,
        num_workers=cfg.DATALOADER.NUM_WORKERS,
        batch_sampler=batch_sampler,
        collate_fn=trivial_batch_collator,
    )
    return data_loader
Exemplo n.º 14
0
    def __init__(self, cfg, is_train=True):
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE,
                                         cfg.INPUT.CROP.SIZE)
            logging.getLogger(__name__).info("CropGen used in training: " +
                                             str(self.crop_gen))
        else:
            self.crop_gen = None

        self.tfm_gens = utils.build_transform_gen(cfg, is_train)

        # fmt: off
        self.img_format = cfg.INPUT.FORMAT
        self.hoi_on = cfg.MODEL.MASK_ON
        self.load_proposals = cfg.MODEL.LOAD_PROPOSALS
        # fmt: on

        self.is_train = is_train
Exemplo n.º 15
0
    def __init__(self, cfg, is_train=True):
        super().__init__(cfg, is_train)

        # fmt: off
        self.attribute_on      = cfg.MODEL.BUA.ATTRIBUTE_ON
        self.max_attr_per_ins  = cfg.INPUT.MAX_ATTR_PER_INS
        # fmt: on
        # NOTE Added to fit d202
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE)
        else:
            self.crop_gen = None

        self.tfm_gens = utils.build_transform_gen(cfg, is_train)
        self.load_proposals = cfg.MODEL.LOAD_PROPOSALS
        self.mask_on        = cfg.MODEL.MASK_ON
        self.keypoint_on    = cfg.MODEL.KEYPOINT_ON
        self.mask_format    = cfg.INPUT.MASK_FORMAT
Exemplo n.º 16
0
    def __init__(self, cfg, is_train=True):
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE,
                                         cfg.INPUT.CROP.SIZE)
            logging.getLogger(__name__).info("CropGen used in training: " +
                                             str(self.crop_gen))
        else:
            self.crop_gen = None

        self.tfm_gens = utils.build_transform_gen(cfg, is_train)

        # fmt: off
        self.img_format = cfg.INPUT.FORMAT
        self.mask_on = cfg.MODEL.MASK_ON
        self.mask_format = cfg.INPUT.MASK_FORMAT
        self.keypoint_on = cfg.MODEL.KEYPOINT_ON
        self.load_proposals = cfg.MODEL.LOAD_PROPOSALS
        # fmt: on
        if self.keypoint_on and is_train:
            # Flip only makes sense in training
            self.keypoint_hflip_indices = utils.create_keypoint_hflip_indices(
                cfg.DATASETS.TRAIN)
        else:
            self.keypoint_hflip_indices = None

        if self.load_proposals:
            self.min_box_side_len = cfg.MODEL.PROPOSAL_GENERATOR.MIN_SIZE
            self.proposal_topk = (cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TRAIN
                                  if is_train else
                                  cfg.DATASETS.PRECOMPUTED_PROPOSAL_TOPK_TEST)
        self.is_train = is_train
        self.vision_type = cfg.INPUT.VISION_TYPE
        self.manipulation_type = cfg.INPUT.INFER_MANIPULATION_TYPE
        self.manipulation_fun = None
        if self.manipulation_type != "":
            supported_manipulations = get_testing_augmentations()
            self.manipulation_fun = supported_manipulations[
                self.manipulation_type]
        self.manipulation_value = cfg.INPUT.INFER_MANIPULATION_VALUE
        self.opponent_space = cfg.INPUT.OPPONENT_SPACE
        self.contrast = cfg.INPUT.CONTRAST
        self.mosaic_pattern = cfg.INPUT.MOSAIC_PATTERN
        if self.contrast == 1.0:
            self.contrast = None
Exemplo n.º 17
0
    def __init__(self, cfg, is_train=True):
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE)
            logging.getLogger(__name__).info("CropGen used in training: " + str(self.crop_gen))
        else:
            self.crop_gen = None

        self.tfm_gens = utils.build_transform_gen(cfg, is_train)

        # fmt: off
        self.img_format     = cfg.INPUT.FORMAT
        self.mask_format    = cfg.INPUT.MASK_FORMAT
        self.relation_on    = cfg.MODEL.SOGNET.RELATION.ENABLED
        self.fcn_roi_on     = cfg.MODEL.SOGNET.FCN_ROI.ENABLED
        # fmt: on

        self.fcn_roi_size = cfg.MODEL.ROI_MASK_HEAD.POOLER_RESOLUTION * 2

        self.stuff_cls_num  = cfg.MODEL.SEM_SEG_HEAD.NUM_CLASSES - cfg.MODEL.ROI_HEADS.NUM_CLASSES
        self.is_train = is_train
Exemplo n.º 18
0
    def __init__(self, cfg, is_train=True):
        self.num_seg_class = 2  # segmentation: foreground and background
        # crop
        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE,
                                         cfg.INPUT.CROP.SIZE)
            logging.getLogger(__name__).info("CropGen used in training: " +
                                             str(self.crop_gen))
        else:
            self.crop_gen = None

        # get basic transform generator, includes resizing and flipping.
        self.tfm_gens = utils.build_transform_gen(cfg, is_train)

        self.img_format = cfg.INPUT.FORMAT  # default type is "BGR"
        self.mask_on = cfg.MODEL.MASK_ON
        self.mask_format = cfg.INPUT.MASK_FORMAT

        # no mask, no key point, no densepose, mo proposals
        assert not cfg.MODEL.LOAD_PROPOSALS, "not supported yet"

        self.is_train = is_train
Exemplo n.º 19
0
    def __init__(self,
                 cfg: CfgNode,
                 is_train: bool = True) -> None:
        """
        Init method for class PanelSegDatasetMapper.

        Args:
            cfg (CfgNode):      The config node filled with necessary options.
            is_train (bool):    Whether we are currently training or testing.
        """

        if cfg.INPUT.CROP.ENABLED and is_train:
            self.crop_gen = T.RandomCrop(cfg.INPUT.CROP.TYPE, cfg.INPUT.CROP.SIZE)
            logging.getLogger(__name__).info("CropGen used in training: %s", str(self.crop_gen))
        else:
            self.crop_gen = None

        self.tfm_gens = utils.build_transform_gen(cfg, is_train)

        self.img_format = cfg.INPUT.FORMAT

        self.is_train = is_train