CoolFace
Apppublic

fffiloni/Video-Matting-Anything

sourceHugging Facemitupdated 1y agoView on Hugging Face
53likes
config.py162 linesDownload Raw Back to utils
1from easydict import EasyDict2 3# Base default config4CONFIG = EasyDict({})5# to indicate this is a default setting, should not be changed by user6CONFIG.is_default = True7CONFIG.version = "baseline"8CONFIG.phase = "train"9# distributed training10CONFIG.dist = False11CONFIG.wandb = False12# global variables which will be assigned in the runtime13CONFIG.local_rank = 014CONFIG.gpu = 015CONFIG.world_size = 116 17# Model config18CONFIG.model = EasyDict({})19# use pretrained checkpoint as encoder20CONFIG.model.freeze_seg = True21CONFIG.model.multi_scale = False22CONFIG.model.imagenet_pretrain = True23CONFIG.model.imagenet_pretrain_path = "/home/liyaoyi/Source/python/attentionMatting/pretrain/model_best_resnet34_En_nomixup.pth"24CONFIG.model.batch_size = 1625# one-hot or class, choice: [3, 1]26CONFIG.model.mask_channel = 127CONFIG.model.trimap_channel = 328 29# hyper-parameter for refinement30CONFIG.model.self_refine_width1 = 3031CONFIG.model.self_refine_width2 = 1532CONFIG.model.self_mask_width = 1033 34# Model -> Architecture config35CONFIG.model.arch = EasyDict({})36# definition in networks/encoders/__init__.py and networks/encoders/__init__.py37CONFIG.model.arch.encoder = "res_shortcut_encoder_29"38CONFIG.model.arch.decoder = "res_shortcut_decoder_22"39CONFIG.model.arch.m2m = "conv_baseline"40CONFIG.model.arch.seg = "maskrcnn"41# predefined for GAN structure42CONFIG.model.arch.discriminator = None43 44 45# Dataloader config46CONFIG.data = EasyDict({})47CONFIG.data.cutmask_prob = 048CONFIG.data.workers = 049CONFIG.data.pha_ratio = 0.550# data path for training and validation in training phase51CONFIG.data.train_fg = None52CONFIG.data.train_alpha = None53CONFIG.data.train_bg = None54CONFIG.data.test_merged = None55CONFIG.data.test_alpha = None56CONFIG.data.test_trimap = None57CONFIG.data.imagematte_fg = None58CONFIG.data.imagematte_pha = None59CONFIG.data.d646_fg = None60CONFIG.data.d646_pha = None61CONFIG.data.aim_fg = None62CONFIG.data.aim_pha = None63CONFIG.data.human2k_fg = None64CONFIG.data.human2k_pha = None65CONFIG.data.am2k_fg = None66CONFIG.data.am2k_pha = None67CONFIG.data.coco_bg = None68CONFIG.data.bg20k_bg = None69CONFIG.data.rim_pha = None70CONFIG.data.rim_img = None71CONFIG.data.spd_pha = None72CONFIG.data.spd_img = None73# feed forward image size (untested)74CONFIG.data.crop_size = 102475# composition of two foregrounds, affine transform, crop and HSV jitter76CONFIG.data.real_world_aug = False77CONFIG.data.augmentation = True78CONFIG.data.random_interp = True79 80### Benchmark config81CONFIG.benchmark = EasyDict({})82CONFIG.benchmark.him2k_img = '/home/jiachen.li/data/HIM2K/images/natural'83CONFIG.benchmark.him2k_alpha = '/home/jiachen.li/data/HIM2K/alphas/natural'84CONFIG.benchmark.him2k_comp_img = '/home/jiachen.li/data/HIM2K/images/comp'85CONFIG.benchmark.him2k_comp_alpha = '/home/jiachen.li/data/HIM2K/alphas/comp'86CONFIG.benchmark.rwp636_img = '/home/jiachen.li/data/RealWorldPortrait-636/image'87CONFIG.benchmark.rwp636_alpha = '/home/jiachen.li/data/RealWorldPortrait-636/alpha'88CONFIG.benchmark.ppm100_img = '/home/jiachen.li/data/PPM-100/image'89CONFIG.benchmark.ppm100_alpha = '/home/jiachen.li/data/PPM-100/matte'90CONFIG.benchmark.am2k_img = '/home/jiachen.li/data/AM2k/validation/original'91CONFIG.benchmark.am2k_alpha = '/home/jiachen.li/data/AM2k/validation/mask'92CONFIG.benchmark.rw100_img = '/home/jiachen.li/data/RefMatte_RW_100/image_all'93CONFIG.benchmark.rw100_alpha = '/home/jiachen.li/data/RefMatte_RW_100/mask'94CONFIG.benchmark.rw100_text = '/home/jiachen.li/data/RefMatte_RW_100/refmatte_rw100_label.json'95CONFIG.benchmark.rw100_index = '/home/jiachen.li/data/RefMatte_RW_100/eval_index_expression.json'96CONFIG.benchmark.vm_img = '/home/jiachen.li/data/videomatte_512x288'97 98# Training config99CONFIG.train = EasyDict({})100CONFIG.train.total_step = 100000101CONFIG.train.warmup_step = 5000102CONFIG.train.val_step = 1000103# basic learning rate of optimizer104CONFIG.train.G_lr = 1e-3105# beta1 and beta2 for Adam106CONFIG.train.beta1 = 0.5107CONFIG.train.beta2 = 0.999108# weight of different losses109CONFIG.train.rec_weight = 1110CONFIG.train.comp_weight = 1111CONFIG.train.lap_weight = 1112# clip large gradient113CONFIG.train.clip_grad = True114# resume the training (checkpoint file name)115CONFIG.train.resume_checkpoint = None116# reset the learning rate (this option will reset the optimizer and learning rate scheduler and ignore warmup)117CONFIG.train.reset_lr = False118 119 120# Logging config121CONFIG.log = EasyDict({})122CONFIG.log.tensorboard_path = "./logs/tensorboard"123CONFIG.log.tensorboard_step = 100124# save less images to save disk space125CONFIG.log.tensorboard_image_step = 500126CONFIG.log.logging_path = "./logs/stdout"127CONFIG.log.logging_step = 10128CONFIG.log.logging_level = "DEBUG"129CONFIG.log.checkpoint_path = "./checkpoints"130CONFIG.log.checkpoint_step = 10000131 132 133def load_config(custom_config, default_config=CONFIG, prefix="CONFIG"):134    """135    This function will recursively overwrite the default config by a custom config136    :param default_config:137    :param custom_config: parsed from config/config.toml138    :param prefix: prefix for config key139    :return: None140    """141    if "is_default" in default_config:142        default_config.is_default = False143 144    for key in custom_config.keys():145        full_key = ".".join([prefix, key])146        if key not in default_config:147            raise NotImplementedError("Unknown config key: {}".format(full_key))148        elif isinstance(custom_config[key], dict):149            if isinstance(default_config[key], dict):150                load_config(default_config=default_config[key],151                            custom_config=custom_config[key],152                            prefix=full_key)153            else:154                raise ValueError("{}: Expected {}, got dict instead.".format(full_key, type(custom_config[key])))155        else:156            if isinstance(default_config[key], dict):157                raise ValueError("{}: Expected dict, got {} instead.".format(full_key, type(custom_config[key])))158            else:159                default_config[key] = custom_config[key]160 161 162