(rank, world_size, args)
| 68 | return start_epoch + 1 |
| 69 | |
| 70 | def train(rank, world_size, args): |
| 71 | print(f"Training on rank {rank}.") |
| 72 | setup(args, rank, world_size) |
| 73 | torch.cuda.set_device(rank) |
| 74 | |
| 75 | if rank == 0: |
| 76 | wandb.init(project="NeuralMarker", entity='corr', config=args, name=args.experiment_name) |
| 77 | |
| 78 | wandb.define_metric('val_step') |
| 79 | wandb.define_metric('validate/*', step='val_step') |
| 80 | |
| 81 | model = BiRAFT(args).to(rank) |
| 82 | model = DDP(model, device_ids=[rank], |
| 83 | broadcast_buffers=False, |
| 84 | find_unused_parameters=True) |
| 85 | |
| 86 | train_loader = datasets.fetch_dataloader(args) |
| 87 | |
| 88 | optimizer = optim.AdamW(model.parameters(), lr=args.lr, weight_decay=args.wdecay, eps=args.epsilon) |
| 89 | scheduler = optim.lr_scheduler.OneCycleLR(optimizer, args.lr, steps_per_epoch=len(train_loader), |
| 90 | epochs=args.epochs, pct_start=0.05, cycle_momentum=False, anneal_strategy='linear') |
| 91 | |
| 92 | global_step = 1 |
| 93 | start_epoch = 1 |
| 94 | val_step = 1 |
| 95 | |
| 96 | if args.resume: |
| 97 | start_epoch = load_checkpoint(args, model, optimizer) |
| 98 | global_step = (start_epoch - 1) * len(train_loader) + 1 |
| 99 | scheduler.last_epoch = global_step |
| 100 | |
| 101 | model.train() |
| 102 | scaler = GradScaler(enabled=args.mixed_precision) |
| 103 | |
| 104 | tic = toc = time.time() |
| 105 | for epoch_idx in range(start_epoch, args.epochs + 1): |
| 106 | for step, input in enumerate(train_loader): |
| 107 | iter_cost = max(0, time.time() - tic) |
| 108 | tic = time.time() |
| 109 | optimizer.zero_grad() |
| 110 | for key in input.keys(): |
| 111 | if not isinstance(input[key], list): |
| 112 | input[key] = input[key].to(rank) |
| 113 | |
| 114 | image1, image2, image3 = input['im1'], input['im2'], input['im3'] |
| 115 | |
| 116 | # predict flow |
| 117 | # flow_ab means flow from a to b |
| 118 | output_BA = output_AB = output_BB1 = output_B1B = 0 |
| 119 | if args.sed_loss: |
| 120 | output_BA, output_AB = model(image2, image1, iters=args.iters) |
| 121 | if args.tnf_loss: |
| 122 | output_BB1, output_B1B = model(image2, image3, iters=args.iters) |
| 123 | |
| 124 | output = { |
| 125 | 'output_BA' : output_BA, |
| 126 | 'output_AB' : output_AB, |
| 127 | 'output_BB1': output_BB1, |
nothing calls this directly
no test coverage detected