in source/train.py [0:0]
def _setup(sm_args):
"""
Create D2 configs and perform basic setups.
"""
# Choose whether to use config file from D2 model zoo or
# user supplied config file ("local_config_file")
if sm_args.local_config_file is not None:
config_file_path = f"/opt/ml/code/{sm_args.local_config_file}"
config_file = sm_args.local_config_file
else:
config_file_path = f"/opt/ml/code/detectron2/configs/{sm_args.config_file}"
config_file = sm_args.config_file
# Register custom dataset
dataset_train_name = "cb_train"
_register_dataset(dataset_train_name, "train.json", "train")
dataset_val_name = "cb_val"
_register_dataset(dataset_val_name, "val.json", "val")
# Build config file
cfg = get_cfg() # retrieve baseline config: https://github.com/facebookresearch/detectron2/blob/master/detectron2/config/defaults.py
cfg.merge_from_file(config_file_path) # merge defaults with provided config file
list_opts = _opts_to_list(sm_args.opts)
cfg.merge_from_list(list_opts) # override parameters with user defined opts
cfg.DATASETS.TRAIN = (dataset_train_name,) # define dataset used for training
cfg.DATASETS.TEST = (dataset_val_name,) # no test dataset available
cfg.OUTPUT_DIR = os.environ['SM_OUTPUT_DATA_DIR']
cfg.TEST.EVAL_PERIOD = 500
cfg.freeze()
# D2 expects ArgParser.NameSpace object to ammend Cfg node.
d2_args = _custom_argument_parser(config_file_path, sm_args.opts, sm_args.resume)
# Perform training setup before training job starts
default_setup(cfg, d2_args)
return cfg