8"""Configuration file (powered by YACS)."""
14from yacs.config
import CfgNode
as CfgNode
37_C.MODEL.NUM_CLASSES = 10
40_C.MODEL.LOSS_FUN =
"cross_entropy"
49_C.RESNET.TRANS_FUN =
"basic_transform"
52_C.RESNET.NUM_GROUPS = 1
55_C.RESNET.WIDTH_PER_GROUP = 64
58_C.RESNET.STRIDE_1X1 =
True
67_C.ANYNET.STEM_TYPE =
"simple_stem_in"
73_C.ANYNET.BLOCK_TYPE =
"res_bottleneck_block"
85_C.ANYNET.BOT_MULS = []
88_C.ANYNET.GROUP_WS = []
91_C.ANYNET.SE_ON =
False
103_C.REGNET.STEM_TYPE =
"simple_stem_in"
109_C.REGNET.BLOCK_TYPE =
"res_bottleneck_block"
115_C.REGNET.SE_ON =
False
131_C.REGNET.GROUP_W = 16
134_C.REGNET.BOT_MUL = 1.0
170_C.EN.DROPOUT_RATIO = 0.0
185_C.BN.USE_PRECISE_STATS =
True
186_C.BN.NUM_SAMPLES_PRECISE = 8192
189_C.BN.ZERO_INIT_FINAL_GAMMA =
False
192_C.BN.USE_CUSTOM_WEIGHT_DECAY =
False
193_C.BN.CUSTOM_WEIGHT_DECAY = 0.0
202_C.OPTIM.BASE_LR = 0.1
205_C.OPTIM.LR_POLICY =
"cos"
214_C.OPTIM.LR_MULT = 0.1
217_C.OPTIM.MAX_EPOCH = 200
220_C.OPTIM.MOMENTUM = 0.9
223_C.OPTIM.DAMPENING = 0.0
226_C.OPTIM.NESTEROV =
True
229_C.OPTIM.WEIGHT_DECAY = 5e-4
232_C.OPTIM.WARMUP_FACTOR = 0.1
235_C.OPTIM.WARMUP_EPOCHS = 0
245_C.TRAIN.SPLIT =
"train"
248_C.TRAIN.BATCH_SIZE = 128
251_C.TRAIN.IM_SIZE = 224
254_C.TRAIN.EVAL_PERIOD = 1
257_C.TRAIN.CHECKPOINT_PERIOD = 1
260_C.TRAIN.AUTO_RESUME =
True
276_C.TEST.BATCH_SIZE = 200
288_C.DATA_LOADER = CfgNode()
291_C.DATA_LOADER.NUM_WORKERS = 8
294_C.DATA_LOADER.PIN_MEMORY =
True
303_C.MEM.RELU_INPLACE =
True
314_C.CUDNN.BENCHMARK =
True
320_C.PREC_TIME = CfgNode()
323_C.PREC_TIME.WARMUP_ITER = 3
326_C.PREC_TIME.NUM_ITER = 30
340_C.CFG_DEST =
"config.yaml"
347_C.LOG_DEST =
"stdout"
353_C.DIST_BACKEND =
"nccl"
357_C.PORT_RANGE = [10000, 65000]
360_C.DOWNLOAD_CACHE =
"/tmp/pycls-download-cache"
367_C.register_deprecated_key(
"PREC_TIME.BATCH_SIZE")
368_C.register_deprecated_key(
"PREC_TIME.ENABLED")
369_C.register_deprecated_key(
"PORT")
373 """Checks config values invariants."""
374 err_str =
"The first lr step must start at 0"
375 assert not _C.OPTIM.STEPS
or _C.OPTIM.STEPS[0] == 0, err_str
376 data_splits = [
"train",
"val",
"test"]
377 err_str =
"Data split '{}' not supported"
378 assert _C.TRAIN.SPLIT
in data_splits, err_str.format(_C.TRAIN.SPLIT)
379 assert _C.TEST.SPLIT
in data_splits, err_str.format(_C.TEST.SPLIT)
380 err_str =
"Mini-batch size should be a multiple of NUM_GPUS."
381 assert _C.TRAIN.BATCH_SIZE % _C.NUM_GPUS == 0, err_str
382 assert _C.TEST.BATCH_SIZE % _C.NUM_GPUS == 0, err_str
383 err_str =
"Log destination '{}' not supported"
384 assert _C.LOG_DEST
in [
"stdout",
"file"], err_str.format(_C.LOG_DEST)
390 """Download URLs in config, cache them, and rewrite cfg to use cached file."""
391 _C.TRAIN.WEIGHTS = cache_url(_C.TRAIN.WEIGHTS, _C.DOWNLOAD_CACHE)
392 _C.TEST.WEIGHTS = cache_url(_C.TEST.WEIGHTS, _C.DOWNLOAD_CACHE)
396 """Dumps the config to the output directory."""
397 cfg_file = os.path.join(_C.OUT_DIR, _C.CFG_DEST)
398 with open(cfg_file,
"w")
as f:
403 """Loads config from specified output directory."""
404 cfg_file = os.path.join(out_dir, cfg_dest)
405 _C.merge_from_file(cfg_file)
409 """Load config from command line arguments and set any specified options."""
410 parser = argparse.ArgumentParser(description=description)
411 help_s =
"Config file location"
412 parser.add_argument(
"--cfg", dest=
"cfg_file", help=help_s, required=
True, type=str)
413 help_s =
"See pycls/core/config.py for all options"
414 parser.add_argument(
"opts", help=help_s, default=
None, nargs=argparse.REMAINDER)
415 if len(sys.argv) == 1:
418 args = parser.parse_args()
419 _C.merge_from_file(args.cfg_file)
420 _C.merge_from_list(args.opts)
load_cfg_fom_args(description="Config file options.")
load_cfg(out_dir, cfg_dest="config.yaml")
assert_and_infer_cfg(cache_urls=True)