def get(name): if name.startswith('$'): # the name is '$s', where s is the yaml str for the param from qd.qd_common import load_from_yaml_str args = load_from_yaml_str(name[1:]) import logging from pprint import pformat logging.info('MaskTSVDataset args\n{}'.format(pformat(args))) return {'factory': 'MaskTSVDataset', 'args': args} elif "coco" in name: data_dir = DatasetCatalog.DATA_DIR attrs = DatasetCatalog.DATASETS[name] args = dict( root=os.path.join(data_dir, attrs["img_dir"]), ann_file=os.path.join(data_dir, attrs["ann_file"]), ) return dict( factory="COCODataset", args=args, ) elif "voc" in name: data_dir = DatasetCatalog.DATA_DIR attrs = DatasetCatalog.DATASETS[name] args = dict( data_dir=os.path.join(data_dir, attrs["data_dir"]), split=attrs["split"], ) return dict( factory="PascalVOCDataset", args=args, ) raise RuntimeError("Dataset not available: {}".format(name))
def build_detection_model(cfg): if '\n' in cfg.MODEL.META_ARCHITECTURE: from qd.qd_common import load_from_yaml_str param = load_from_yaml_str(cfg.MODEL.META_ARCHITECTURE) from qd.qd_common import execute_func meta_arch = execute_func(param) else: meta_arch = _DETECTION_META_ARCHITECTURES[cfg.MODEL.META_ARCHITECTURE] return meta_arch(cfg)
def build_shufflenet_fpn_backbone(cfg): from qd.qd_common import load_from_yaml_str param = cfg.MODEL.BACKBONE.CONV_BODY_PARAM param = load_from_yaml_str(param) from qd.qd_common import execute_func body = execute_func(param) out_channels = cfg.MODEL.RESNETS.BACKBONE_OUT_CHANNELS fpn = fpn_module.FPN( in_channels_list=body.get_out_channels(), out_channels=out_channels, conv_block=conv_with_kaiming_uniform( cfg.MODEL.FPN.USE_BN, cfg.MODEL.FPN.USE_GN, cfg.MODEL.FPN.USE_RELU ), top_blocks=fpn_module.LastLevelMaxPool(), interpolate_mode=cfg.MODEL.FPN.INTERPOLATE_MODE, ) model = nn.Sequential(OrderedDict([("body", body), ("fpn", fpn)])) model.out_channels = out_channels return model
def build_transforms(cfg, is_train=True): if is_train: min_size = cfg.INPUT.MIN_SIZE_TRAIN max_size = cfg.INPUT.MAX_SIZE_TRAIN flip_prob = 0.5 # cfg.INPUT.FLIP_PROB_TRAIN brightness = cfg.INPUT.BRIGHTNESS contrast = cfg.INPUT.CONTRAST saturation = cfg.INPUT.SATURATION hue = cfg.INPUT.HUE adaptive = cfg.INPUT.COLORJITTER_ADAPTIVE else: min_size = cfg.INPUT.MIN_SIZE_TEST max_size = cfg.INPUT.MAX_SIZE_TEST flip_prob = 0 brightness = 0.0 contrast = 0.0 saturation = 0.0 hue = 0.0 adaptive = None to_bgr255 = cfg.INPUT.TO_BGR255 from qd.qd_pytorch import ( DictTransformMaskNormalize, DictTransformMaskColorJitter, DictTransformMaskToTensor, DictTransformMaskRandomHorizontalFlip, ) normalize_transform = DictTransformMaskNormalize(mean=cfg.INPUT.PIXEL_MEAN, std=cfg.INPUT.PIXEL_STD, to_bgr255=to_bgr255) color_jitter = DictTransformMaskColorJitter( brightness=brightness, contrast=contrast, saturation=saturation, hue=hue, adaptive=adaptive, ) to_tensor = DictTransformMaskToTensor() flipper = DictTransformMaskRandomHorizontalFlip(flip_prob) from qd.qd_pytorch import DictTransformMaskResize if is_train: if cfg.INPUT.TRAIN_RESIZER != '': from qd.qd_common import load_from_yaml_str from qd.qd_common import execute_func resizer = execute_func(load_from_yaml_str(cfg.INPUT.TRAIN_RESIZER)) elif not cfg.INPUT.USE_FIXED_SIZE_AUGMENTATION: resizer = DictTransformMaskResize( min_size, max_size, cfg.INPUT.MIN_SIZE_ON_ITER, cfg.INPUT.TREAT_MIN_AS_MAX, ) else: from qd.qd_yolov2pt import DictResizeAndPlaceForMaskRCNN resizer = DictResizeAndPlaceForMaskRCNN(cfg) else: resizer = DictTransformMaskResize(min_size, max_size, cfg.INPUT.MIN_SIZE_ON_ITER) from qd.qd_pytorch import DictTransformCompose transform = DictTransformCompose([ color_jitter, resizer, flipper, to_tensor, normalize_transform, ]) return transform