def main(): config.load_cfg_fom_args("Train a classification model.") config.assert_and_infer_cfg() cfg.freeze() # Perform training dist.multi_proc_run(num_proc=cfg.NUM_GPUS, fun=trainer.train_model)
def main(): config.load_cfg_fom_args("Scale a model.") config.assert_and_infer_cfg() cx_orig = net.complexity(builders.get_model()) scaler.scale_model() cx_scaled = net.complexity(builders.get_model()) cfg_file = config.dump_cfg() print("Scaled config dumped to:", cfg_file) print("Original model complexity:", cx_orig) print("Scaled model complexity:", cx_scaled)
def main(): # Load config options config.load_cfg_fom_args("Test a trained classification model.") config.assert_and_infer_cfg() cfg.freeze() # Perform evaluation if cfg.NUM_GPUS > 1: dist.multi_proc_run(num_proc=cfg.NUM_GPUS, fun=test_model) else: test_model()
def main(): config.load_cfg_fom_args("Train a classification model.") config.assert_and_infer_cfg() D2Utils.cfg_merge_from_easydict(cfg, global_cfg) cfg.freeze() trainer_module = cfg.get('trainer_module', 'pycls.core.trainer') trainer_module = importlib.import_module(trainer_module) dist.multi_proc_run(num_proc=cfg.NUM_GPUS, fun=trainer_module.train_model)
def main(): config.load_cfg_fom_args("Train a classification model.") config.assert_and_infer_cfg() cfg.freeze() print("building model {}".format(cfg.MODEL.TYPE)) model = build_model() model.eval() x = torch.randn(1, 3, 224, 224) y = model(x) print(y.shape) model_complex = complexity(model) print(model_complex)
def __init__(self, num_classes=1, ckpt=None): super(Regnet, self).__init__() from pycls.core.config import cfg import pycls.core.config as model_config from pycls.core.builders import build_model model_config.load_cfg_fom_args("Train a cls model") cfg.freeze() model = build_model() if ckpt: model.load_state_dict(torch.load(ckpt)['model_state']) in_features = model.head.fc.in_features fc = nn.Linear(in_features, num_classes) self.model = model self.model.head.fc = fc
def main(): # Load config options config.load_cfg_fom_args("Train a classification model.") config.assert_and_infer_cfg() cfg.freeze() # Ensure that the output dir exists os.makedirs(cfg.OUT_DIR, exist_ok=True) # Save the config config.dump_cfg() # Perform training if cfg.NUM_GPUS > 1: dist.multi_proc_run(num_proc=cfg.NUM_GPUS, fun=train_model) else: train_model()
def __init__(self, num_clusters, num_tiles, num_classes, ckpt): super().__init__() from pycls.core.config import cfg import pycls.core.config as model_config from pycls.core.builders import build_model model_config.load_cfg_fom_args("Train a cls model") cfg.freeze() model = build_model() if ckpt: model.load_state_dict(torch.load(ckpt)['model_state']) self.enc = nn.Sequential(model.stem, model.s1, model.s2, model.s3, model.s4, nn.AdaptiveAvgPool2d(output_size=(1, 1)), nn.Flatten(), nn.Dropout(p=0.3)) self.nc = model.head.fc.in_features self.netvlad = NetVLAD(cluster_size=num_clusters, max_frames=num_tiles, feature_size=self.nc, truncate=False) self.fc = nn.Linear(num_clusters * self.nc, num_classes)
def main(): corruptions, levels = config.load_cfg_fom_args( "Train a classification model.") config.assert_and_infer_cfg() # Perform training results = dist.multi_proc_run( num_proc=cfg.NUM_GPUS, fun=lambda: trainer.test_ftta_model(corruptions, levels)) # plot the results table for index, level in enumerate(levels): console = Console() table = Table(show_header=True, header_style="cyan") table.add_column('level') for corruption in corruptions: table.add_column(corruptions_concise[corruption]) res = list(map(lambda x: str(x), results[index])) res = [str(level)] + res table.add_row(*res) console.print(table)
def main(): config.load_cfg_fom_args("Test a trained classification model.") config.assert_and_infer_cfg() cfg.freeze() test()
def main(): config.load_cfg_fom_args("Compute model and loader timings.") config.assert_and_infer_cfg() cfg.freeze() dist.multi_proc_run(num_proc=cfg.NUM_GPUS, fun=trainer.time_model)
def main(): config.load_cfg_fom_args("Test a trained classification model.") config.assert_and_infer_cfg() cfg.freeze() dist.multi_proc_run(num_proc=cfg.NUM_GPUS, fun=trainer.test_model)
def main(): config.load_cfg_fom_args("Compute precise time for a model on 1 GPU.") config.assert_and_infer_cfg() cfg.freeze() dist.multi_proc_run(num_proc=cfg.NUM_GPUS, fun=trainer.time_model)