def main():
    start_time = time.monotonic()
    (args, cfg) = parge_config()
    dist = init_dist(cfg)
    synchronize()
    logger = Logger((cfg.work_dir / 'log.txt'), debug=False)
    sys.stdout = logger
    print('==========\nArgs:{}\n=========='.format(args))
    log_config_to_file(cfg)
    (train_loader, train_sets) = build_train_dataloader(cfg)
    model = build_model(cfg, 0, init=cfg.MODEL.source_pretrained)
    model.cuda()
    if dist:
        model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[cfg.gpu], output_device=cfg.gpu, find_unused_parameters=True)
    elif (cfg.total_gpus > 1):
        model = torch.nn.DataParallel(model)
    optimizer = build_optimizer([model], **cfg.TRAIN.OPTIM)
    if (cfg.TRAIN.SCHEDULER.lr_scheduler is not None):
        lr_scheduler = build_lr_scheduler(optimizer, **cfg.TRAIN.SCHEDULER)
    else:
        lr_scheduler = None
    criterions = build_loss(cfg.TRAIN.LOSS, triplet_key='feat', cuda=True)
    runner = BaseRunner(cfg, model, optimizer, criterions, train_loader, train_sets=train_sets, lr_scheduler=lr_scheduler, meter_formats={'Time': ':.3f'}, reset_optim=False)
    if args.resume_from:
        runner.resume(args.resume_from)
    runner.run()
    runner.resume((cfg.work_dir / 'model_best.pth'))
    (test_loaders, queries, galleries) = build_test_dataloader(cfg)
    for (i, (loader, query, gallery)) in enumerate(zip(test_loaders, queries, galleries)):
        (cmc, mAP) = test_reid(cfg, model, loader, query, gallery, dataset_name=cfg.TEST.datasets[i])
    end_time = time.monotonic()
    print('Total running time: ', timedelta(seconds=(end_time - start_time)))
def main():
    start_time = time.monotonic()
    (args, cfg) = parge_config()
    dist = init_dist(cfg)
    synchronize()
    logger = Logger((cfg.work_dir / 'log.txt'), debug=False)
    sys.stdout = logger
    print('==========\nArgs:{}\n=========='.format(args))
    log_config_to_file(cfg)
    (train_loader, train_sets) = build_train_dataloader(cfg)
    model = build_model(cfg, 0, init=cfg.MODEL.source_pretrained)
    model.cuda()
    if dist:
        model = torch.nn.parallel.DistributedDataParallel(model, device_ids=[cfg.gpu], output_device=cfg.gpu, find_unused_parameters=True)
    elif (cfg.total_gpus > 1):
        model = torch.nn.DataParallel(model)
    optimizer = build_optimizer([model], **cfg.TRAIN.OPTIM)
    if (cfg.TRAIN.SCHEDULER.lr_scheduler is not None):
        lr_scheduler = build_lr_scheduler(optimizer, **cfg.TRAIN.SCHEDULER)
    else:
        lr_scheduler = None
    criterions = build_loss(cfg.TRAIN.LOSS, triplet_key='feat', cuda=True)
    runner = BaseRunner(cfg, model, optimizer, criterions, train_loader, train_sets=train_sets, lr_scheduler=lr_scheduler, meter_formats={'Time': ':.3f'}, reset_optim=False)
    if args.resume_from:
        runner.resume(args.resume_from)
    runner.run()
    runner.resume((cfg.work_dir / 'model_best.pth'))
    (test_loaders, queries, galleries) = build_test_dataloader(cfg)
    for (i, (loader, query, gallery)) in enumerate(zip(test_loaders, queries, galleries)):
        (cmc, mAP) = test_reid(cfg, model, loader, query, gallery, dataset_name=cfg.TEST.datasets[i])
    end_time = time.monotonic()
    print('Total running time: ', timedelta(seconds=(end_time - start_time)))