Exemplo n.º 1
0
def add_fbnet_v2_default_configs(_C):
    _C.MODEL.FBNET_V2 = CN()

    _C.MODEL.FBNET_V2.ARCH = "default"
    _C.MODEL.FBNET_V2.ARCH_DEF = []
    # number of channels input to trunk
    _C.MODEL.FBNET_V2.STEM_IN_CHANNELS = 3
    _C.MODEL.FBNET_V2.SCALE_FACTOR = 1.0
    # the output channels will be divisible by WIDTH_DIVISOR
    _C.MODEL.FBNET_V2.WIDTH_DIVISOR = 1

    # normalization configs
    # name of norm such as "bn", "sync_bn", "gn"
    _C.MODEL.FBNET_V2.NORM = "bn"
    # for advanced use case that requries extra arguments, passing a list of
    # dict such as [{"num_groups": 8}, {"momentum": 0.1}] (merged in given order).
    # Note that string written it in .yaml will be evaluated by yacs, thus this
    # node will become normal python object.
    # https://github.com/rbgirshick/yacs/blob/master/yacs/config.py#L410
    _C.MODEL.FBNET_V2.NORM_ARGS = []

    _C.MODEL.VT_FPN = CN()

    _C.MODEL.VT_FPN.IN_FEATURES = ["res2", "res3", "res4", "res5"]
    _C.MODEL.VT_FPN.OUT_CHANNELS = 256
    _C.MODEL.VT_FPN.LAYERS = 3
    _C.MODEL.VT_FPN.TOKEN_LS = [16, 16, 8, 8]
    _C.MODEL.VT_FPN.TOKEN_C = 1024
    _C.MODEL.VT_FPN.HEADS = 16
    _C.MODEL.VT_FPN.MIN_GROUP_PLANES = 64
    _C.MODEL.VT_FPN.NORM = "BN"
    _C.MODEL.VT_FPN.POS_HWS = []
    _C.MODEL.VT_FPN.POS_N_DOWNSAMPLE = []
Exemplo n.º 2
0
 def test_pit_model(self):
     cfg = CN()
     cfg.MODEL = CN()
     add_pit_backbone_config(cfg)
     build_model = BACKBONE_REGISTRY.get("pit_d2go_model_wrapper")
     pit_models = {
         "pit_ti_ours": 160,
         "pit_ti": 224,
         "pit_s_ours_v1": 256,
         "pit_s": 224,
     }
     pit_model_weights = {
         "pit_ti_ours":
         "manifold://mobile_vision_workflows/tree/workflows/kyungminkim/20210515/deit_[model]pit_scalable_distilled_[bs]128_[mcfg]pit_ti_ours_.HImkjNCpJI/checkpoint_best.pth",
         "pit_ti":
         "manifold://mobile_vision_workflows/tree/workflows/kyungminkim/20210515/deit_[model]pit_scalable_distilled_[bs]128_[mcfg]pit_ti_.QJeFNUfYOD/checkpoint_best.pth",
         "pit_s_ours_v1":
         "manifold://mobile_vision_workflows/tree/workflows/kyungminkim/20210515/deit_[model]pit_scalable_distilled_[bs]64_[mcfg]pit_s_ours_v1_.LXdwyBDaNY/checkpoint_best.pth",
         "pit_s":
         "manifold://mobile_vision_workflows/tree/workflows/kyungminkim/20210515/deit_[model]pit_scalable_distilled_[bs]128_[mcfg]pit_s_.zReQLPOuJe/checkpoint_best.pth",
     }
     for model_name, org_size in pit_models.items():
         print("model_name", model_name)
         cfg.MODEL.PIT.MODEL_CONFIG = f"manifold://mobile_vision_workflows/tree/workflows/wbc/deit/model_cfgs/{model_name}.json"
         cfg.MODEL.PIT.WEIGHTS = pit_model_weights[model_name]
         cfg.MODEL.PIT.DILATED = True
         model = build_model(cfg, None)
         model.eval()
         for input_size_h in [org_size, 192, 224, 256, 320]:
             for input_size_w in [org_size, 192, 224, 256, 320]:
                 x = torch.rand(1, 3, input_size_h, input_size_w)
                 y = model(x)
                 print(f"x.shape: {x.shape}, y.shape: {y.shape}")
Exemplo n.º 3
0
def add_subclass_configs(cfg):
    _C = cfg
    _C.MODEL.SUBCLASS = CN()
    _C.MODEL.SUBCLASS.SUBCLASS_ON = False
    _C.MODEL.SUBCLASS.NUM_SUBCLASSES = 0  # must be set
    _C.MODEL.SUBCLASS.NUM_LAYERS = 1
    _C.MODEL.SUBCLASS.SUBCLASS_ID_FETCHER = "SubclassFetcher"  # ABC, must be set
Exemplo n.º 4
0
def create_cfg_from_cli_args(args, default_cfg):
    """
    Instead of loading from defaults.py, this binary only includes necessary
    configs building from scratch, and overrides them from args. There're two
    levels of config:
        _C: the config system used by this binary, which is a sub-set of training
            config, override by configurable_cfg. It can also be override by
            args.opts for convinience.
        configurable_cfg: common configs that user should explicitly specify
            in the args.
    """

    _C = CN()
    _C.INPUT = default_cfg.INPUT
    _C.DATASETS = default_cfg.DATASETS
    _C.DATALOADER = default_cfg.DATALOADER
    _C.TEST = default_cfg.TEST
    if hasattr(default_cfg, "D2GO_DATA"):
        _C.D2GO_DATA = default_cfg.D2GO_DATA
    if hasattr(default_cfg, "TENSORBOARD"):
        _C.TENSORBOARD = default_cfg.TENSORBOARD

    # NOTE configs below might not be necessary, but must add to make code work
    _C.MODEL = CN()
    _C.MODEL.META_ARCHITECTURE = default_cfg.MODEL.META_ARCHITECTURE
    _C.MODEL.MASK_ON = default_cfg.MODEL.MASK_ON
    _C.MODEL.KEYPOINT_ON = default_cfg.MODEL.KEYPOINT_ON
    _C.MODEL.LOAD_PROPOSALS = default_cfg.MODEL.LOAD_PROPOSALS
    assert _C.MODEL.LOAD_PROPOSALS is False, "caffe2 model doesn't support"

    _C.OUTPUT_DIR = args.output_dir

    configurable_cfg = [
        "DATASETS.TEST",
        args.datasets,
        "INPUT.MIN_SIZE_TEST",
        args.min_size,
        "INPUT.MAX_SIZE_TEST",
        args.max_size,
    ]

    cfg = _C.clone()
    cfg.merge_from_list(configurable_cfg)
    cfg.merge_from_list(args.opts)

    return cfg
Exemplo n.º 5
0
def add_subclass_configs(cfg):
    _C = cfg
    _C.MODEL.SUBCLASS = CN()
    _C.MODEL.SUBCLASS.SUBCLASS_ON = False
    _C.MODEL.SUBCLASS.NUM_SUBCLASSES = 0  # must be set
    _C.MODEL.SUBCLASS.NUM_LAYERS = 1
    _C.MODEL.SUBCLASS.SUBCLASS_ID_FETCHER = "SubclassFetcher"  # ABC, must be set
    _C.MODEL.SUBCLASS.SUBCLASS_MAPPING = [
    ]  # subclass mapping from model output to annotation
Exemplo n.º 6
0
def add_bifpn_default_configs(_C):
    _C.MODEL.BIFPN = CN()

    _C.MODEL.BIFPN.DEPTH_MULTIPLIER = 1
    _C.MODEL.BIFPN.SCALE_FACTOR = 1
    _C.MODEL.BIFPN.WIDTH_DIVISOR = 8
    _C.MODEL.BIFPN.NORM = "bn"
    _C.MODEL.BIFPN.NORM_ARGS = []
    _C.MODEL.BIFPN.TOP_BLOCK_BEFORE_FPN = False
Exemplo n.º 7
0
def add_kmeans_anchors_cfg(_C):
    _C.MODEL.KMEANS_ANCHORS = CN()
    _C.MODEL.KMEANS_ANCHORS.KMEANS_ANCHORS_ON = False
    _C.MODEL.KMEANS_ANCHORS.NUM_CLUSTERS = 0
    _C.MODEL.KMEANS_ANCHORS.NUM_TRAINING_IMG = 0
    _C.MODEL.KMEANS_ANCHORS.DATASETS = ()
    _C.MODEL.ANCHOR_GENERATOR.OFFSET = 0.0
    _C.MODEL.KMEANS_ANCHORS.RNG_SEED = 3

    return _C
Exemplo n.º 8
0
def add_model_ema_configs(_C):
    from d2go.config import CfgNode as CN

    _C.MODEL_EMA = CN()
    _C.MODEL_EMA.ENABLED = False
    _C.MODEL_EMA.DECAY = 0.999
    # use the same as MODEL.DEVICE when empty
    _C.MODEL_EMA.DEVICE = ""
    # When True, loading the ema weight to the model when eval_only=True in build_model()
    _C.MODEL_EMA.USE_EMA_WEIGHTS_FOR_EVAL_ONLY = False
Exemplo n.º 9
0
    def get_default_cfg():
        """
        Override `get_default_cfg` for adding non common config.
        """
        from detectron2.config import get_cfg as get_d2_cfg

        cfg = get_d2_cfg()
        cfg = CN(cfg)  # upgrade from D2's CfgNode to D2Go's CfgNode
        cfg.SOLVER.AUTO_SCALING_METHODS = ["default_scale_d2_configs"]
        return cfg
Exemplo n.º 10
0
    def get_default_cfg():
        _C = super(GeneralizedRCNNRunner,
                   GeneralizedRCNNRunner).get_default_cfg()
        _C.EXPORT_CAFFE2 = CN()
        _C.EXPORT_CAFFE2.USE_HEATMAP_MAX_KEYPOINT = False

        _C.RCNN_PREPARE_FOR_EXPORT = "default_rcnn_prepare_for_export"
        _C.RCNN_PREPARE_FOR_QUANT = "default_rcnn_prepare_for_quant"
        _C.RCNN_PREPARE_FOR_QUANT_CONVERT = "default_rcnn_prepare_for_quant_convert"

        return _C
Exemplo n.º 11
0
def add_tensorboard_default_configs(_C):
    _C.TENSORBOARD = CN()
    # Output from dataloader will be written to tensorboard at this frequency
    _C.TENSORBOARD.TRAIN_LOADER_VIS_WRITE_PERIOD = 20
    # This controls max number of images over all batches, be considerate when
    # increasing this number because it takes disk space and slows down the training
    _C.TENSORBOARD.TRAIN_LOADER_VIS_MAX_IMAGES = 16
    # Max number of images per dataset to visualize in tensorboard during evaluation
    _C.TENSORBOARD.TEST_VIS_MAX_IMAGES = 16

    # TENSORBOARD.LOG_DIR will be determined solely by OUTPUT_DIR
    _C.register_deprecated_key("TENSORBOARD.LOG_DIR")
Exemplo n.º 12
0
def add_d2go_data_default_configs(_C):
    _C.D2GO_DATA = CN()

    # Config for "detectron2go.data.extended_coco.extended_coco_load"
    _C.D2GO_DATA.DATASETS = CN()
    # List of class names to use when loading the data, this applies to train
    # and test separately. Default value means using all classes, otherwise it'll create
    # new json file containing only given categories.
    _C.D2GO_DATA.DATASETS.TRAIN_CATEGORIES = ()
    _C.D2GO_DATA.DATASETS.TEST_CATEGORIES = ()

    # Register a list of COCO datasets in config
    _C.D2GO_DATA.DATASETS.COCO_INJECTION = CN()
    _C.D2GO_DATA.DATASETS.COCO_INJECTION.NAMES = []
    _C.D2GO_DATA.DATASETS.COCO_INJECTION.IM_DIRS = []
    _C.D2GO_DATA.DATASETS.COCO_INJECTION.JSON_FILES = []

    # On-the-fly register a list of datasets located under detectron2go/datasets
    # by specifying the filename (without .py).
    _C.D2GO_DATA.DATASETS.DYNAMIC_DATASETS = []

    # TODO: potentially add this config
    # # List of extra keys in annotation, the item will be forwarded by
    # # extended_coco_load.
    # _C.D2GO_DATA.DATASETS.ANNOTATION_FIELDS_TO_FORWARD = ()

    # Config for D2GoDatasetMapper
    _C.D2GO_DATA.MAPPER = CN()
    # dataset mapper name
    _C.D2GO_DATA.MAPPER.NAME = "D2GoDatasetMapper"
    # When enabled, image item from json dataset doesn't need to have width/hegiht,
    # they will be backfilled once image is loaded. This may cause issue when
    # width/hegiht is acutally been used by extended_coco_load, eg. grouping
    # by aspect ratio.
    _C.D2GO_DATA.MAPPER.BACKFILL_SIZE = False
    _C.D2GO_DATA.MAPPER.RETRY = 3
    _C.D2GO_DATA.MAPPER.CATCH_EXCEPTION = True

    _C.D2GO_DATA.AUG_OPS = CN()
    # List of transforms that are represented by string. Each string starts with
    # a registered name in TRANSFORM_OP_REGISTRY, optionally followed by a string
    # argument (separated by "::") which can be used for initializing the
    # transform object. See build_transform_gen for the detail.
    # Some examples are:
    # example 1: RandomFlipOp
    # example 2: RandomFlipOp::{}
    # example 3: RandomFlipOp::{"prob":0.5}
    # example 4: RandomBrightnessOp::{"intensity_min":1.0, "intensity_max":2.0}
    # NOTE: search "example repr:" in fbcode for examples.
    _C.D2GO_DATA.AUG_OPS.TRAIN = ["ResizeShortestEdgeOp", "RandomFlipOp"]
    _C.D2GO_DATA.AUG_OPS.TEST = ["ResizeShortestEdgeOp"]

    _C.D2GO_DATA.TEST = CN()
    # Evaluate on the first specified number of images for each datset during
    # testing, default value 0 means using all images.
    # NOTE: See maybe_subsample_n_images for details.
    _C.D2GO_DATA.TEST.MAX_IMAGES = 0
    _C.D2GO_DATA.TEST.SUBSET_SAMPLING = "frontmost"  # one of {"frontmost", "random"}

    return _C
Exemplo n.º 13
0
    def test_deit_model(self):
        cfg = CN()
        cfg.MODEL = CN()
        add_deit_backbone_config(cfg)
        build_model = BACKBONE_REGISTRY.get("deit_d2go_model_wrapper")
        deit_models = {
            "8X-7-RM_4": 170,
            "DeiT-Tiny": 224,
            "DeiT-Small": 224,
            "32X-1-RM_2": 221,
            "8X-7": 160,
            "32X-1": 256,
        }
        deit_model_weights = {
            "8X-7-RM_4":
            "manifold://mobile_vision_workflows/tree/workflows/kyungminkim/20210511/deit_[model]deit_scaling_distill_[bs]128_[mcfg]8X-7-RM_4_.OIXarYpbZw/checkpoint_best.pth",
            "DeiT-Tiny":
            "manifold://mobile_vision_workflows/tree/workflows/cl114/DeiT-official-ckpt/deit_tiny_distilled_patch16_224-b40b3cf7.pth",
            "DeiT-Small":
            "manifold://mobile_vision_workflows/tree/workflows/cl114/DeiT-official-ckpt/deit_small_distilled_patch16_224-649709d9.pth",
            "32X-1-RM_2":
            "manifold://mobile_vision_workflows/tree/workflows/kyungminkim/20210511/deit_[model]deit_scaling_distill_[bs]64_[mcfg]32X-1-RM_2_.xusuFyNMdD/checkpoint_best.pth",
            "8X-7":
            "manifold://mobile_vision_workflows/tree/workflows/cl114/scaled_best/8X-7.pth",
            "32X-1":
            "manifold://mobile_vision_workflows/tree/workflows/cl114/scaled_best/32X-1.pth",
        }

        for model_name, org_size in deit_models.items():
            print("model_name", model_name)
            cfg.MODEL.DEIT.MODEL_CONFIG = f"manifold://mobile_vision_workflows/tree/workflows/wbc/deit/model_cfgs/{model_name}.json"
            cfg.MODEL.DEIT.WEIGHTS = deit_model_weights[model_name]
            model = build_model(cfg, None)
            model.eval()
            for input_size_h in [org_size, 192, 224, 256, 320]:
                for input_size_w in [org_size, 192, 224, 256, 320]:
                    x = torch.rand(1, 3, input_size_h, input_size_w)
                    y = model(x)
                    print(f"x.shape: {x.shape}, y.shape: {y.shape}")
Exemplo n.º 14
0
def add_detr_config(cfg):
    """
    Add config for DETR.
    """
    cfg.MODEL.DETR = CN()
    cfg.MODEL.DETR.NAME = "DETR"
    cfg.MODEL.DETR.NUM_CLASSES = 80

    # simple backbone
    cfg.MODEL.BACKBONE.SIMPLE = False
    cfg.MODEL.BACKBONE.STRIDE = 1
    cfg.MODEL.BACKBONE.CHANNEL = 0

    # FBNet
    cfg.MODEL.FBNET_V2.OUT_FEATURES = ["trunk3"]

    # For Segmentation
    cfg.MODEL.DETR.FROZEN_WEIGHTS = ""

    # LOSS
    cfg.MODEL.DETR.DEFORMABLE = False
    cfg.MODEL.DETR.USE_FOCAL_LOSS = False
    cfg.MODEL.DETR.CENTERED_POSITION_ENCODIND = False
    cfg.MODEL.DETR.CLS_WEIGHT = 1.0
    cfg.MODEL.DETR.NUM_FEATURE_LEVELS = 4
    cfg.MODEL.DETR.GIOU_WEIGHT = 2.0
    cfg.MODEL.DETR.L1_WEIGHT = 5.0
    cfg.MODEL.DETR.DEEP_SUPERVISION = True
    cfg.MODEL.DETR.NO_OBJECT_WEIGHT = 0.1
    cfg.MODEL.DETR.WITH_BOX_REFINE = False
    cfg.MODEL.DETR.TWO_STAGE = False
    cfg.MODEL.DETR.DECODER_BLOCK_GRAD = True

    # TRANSFORMER
    cfg.MODEL.DETR.NHEADS = 8
    cfg.MODEL.DETR.DROPOUT = 0.1
    cfg.MODEL.DETR.DIM_FEEDFORWARD = 2048
    cfg.MODEL.DETR.ENC_LAYERS = 6
    cfg.MODEL.DETR.DEC_LAYERS = 6
    cfg.MODEL.DETR.BBOX_EMBED_NUM_LAYERS = 3
    cfg.MODEL.DETR.PRE_NORM = False

    cfg.MODEL.DETR.HIDDEN_DIM = 256
    cfg.MODEL.DETR.NUM_OBJECT_QUERIES = 100

    # solver
    cfg.SOLVER.OPTIMIZER = "ADAMW"
    cfg.SOLVER.BACKBONE_MULTIPLIER = 0.1

    # tgt & embeddings
    cfg.MODEL.DETR.LEARNABLE_TGT = False
Exemplo n.º 15
0
def add_fcos_configs(cfg):
    cfg.MODEL.FCOS = CN()
    # the number of foreground classes.
    cfg.MODEL.FCOS.NUM_CLASSES = 80
    cfg.MODEL.FCOS.IN_FEATURES = ["p3", "p4", "p5", "p6", "p7"]
    cfg.MODEL.FCOS.NUM_CONVS = 4
    cfg.MODEL.FCOS.HEAD_NORM = "GN"

    # inference parameters
    cfg.MODEL.FCOS.SCORE_THRESH_TEST = 0.04
    cfg.MODEL.FCOS.TOPK_CANDIDATES_TEST = 1000
    cfg.MODEL.FCOS.NMS_THRESH_TEST = 0.6

    # Focal loss parameters
    cfg.MODEL.FCOS.FOCAL_LOSS_ALPHA = 0.25
    cfg.MODEL.FCOS.FOCAL_LOSS_GAMMA = 2.0
Exemplo n.º 16
0
def add_fbnet_default_configs(_C):
    """ FBNet options and default values
    """
    _C.MODEL.FBNET = CN()
    _C.MODEL.FBNET.ARCH = "default"
    # custom arch
    _C.MODEL.FBNET.ARCH_DEF = ""
    _C.MODEL.FBNET.BN_TYPE = "bn"
    _C.MODEL.FBNET.NUM_GROUPS = 32  # for gn usage only
    _C.MODEL.FBNET.SCALE_FACTOR = 1.0
    # the output channels will be divisible by WIDTH_DIVISOR
    _C.MODEL.FBNET.WIDTH_DIVISOR = 1
    _C.MODEL.FBNET.DW_CONV_SKIP_BN = True
    _C.MODEL.FBNET.DW_CONV_SKIP_RELU = True

    # > 0 scale, == 0 skip, < 0 same dimension
    _C.MODEL.FBNET.DET_HEAD_LAST_SCALE = 1.0
    _C.MODEL.FBNET.DET_HEAD_BLOCKS = []
    # overwrite the stride for the head, 0 to use original value
    _C.MODEL.FBNET.DET_HEAD_STRIDE = 0

    # > 0 scale, == 0 skip, < 0 same dimension
    _C.MODEL.FBNET.KPTS_HEAD_LAST_SCALE = 0.0
    _C.MODEL.FBNET.KPTS_HEAD_BLOCKS = []
    # overwrite the stride for the head, 0 to use original value
    _C.MODEL.FBNET.KPTS_HEAD_STRIDE = 0

    # > 0 scale, == 0 skip, < 0 same dimension
    _C.MODEL.FBNET.MASK_HEAD_LAST_SCALE = 0.0
    _C.MODEL.FBNET.MASK_HEAD_BLOCKS = []
    # overwrite the stride for the head, 0 to use original value
    _C.MODEL.FBNET.MASK_HEAD_STRIDE = 0

    # 0 to use all blocks defined in arch_def
    _C.MODEL.FBNET.RPN_HEAD_BLOCKS = 0
    _C.MODEL.FBNET.RPN_BN_TYPE = ""

    # number of channels input to trunk
    _C.MODEL.FBNET.STEM_IN_CHANNELS = 3
Exemplo n.º 17
0
def add_subclass_configs(cfg):
    _C = cfg
    _C.MODEL.SUBCLASS = CN()
    _C.MODEL.SUBCLASS.SUBCLASS_ON = False
    _C.MODEL.SUBCLASS.NUM_SUBCLASSES = 0  # must be set
    _C.MODEL.SUBCLASS.NUM_LAYERS = 1
Exemplo n.º 18
0
 def get_default_cfg():
     _C = super(GeneralizedRCNNRunner,
                GeneralizedRCNNRunner).get_default_cfg()
     _C.EXPORT_CAFFE2 = CN()
     _C.EXPORT_CAFFE2.USE_HEATMAP_MAX_KEYPOINT = False
     return _C
Exemplo n.º 19
0
def add_abnormal_checker_configs(_C):
    _C.ABNORMAL_CHECKER = CN()
    # check and log the iteration with bad losses if enabled
    _C.ABNORMAL_CHECKER.ENABLED = False
Exemplo n.º 20
0
 def get_default_cfg(self):
     _C = super().get_default_cfg()
     add_detr_config(_C)
     _C.MODEL.DETR = CN(_C.MODEL.DETR)
     return _C