MCPcopy Index your code
hub / github.com/ActiveVisionLab/DFNet / train_posenet

Function train_posenet

script/dm/pose_model.py:359–391  ·  view source on GitHub ↗
(args, train_dl, val_dl, model, epochs, optimizer, loss_func, scheduler, device, early_stopping)

Source from the content-addressed store, hash-verified

357 return train_loss_epoch_mean
358
359def train_posenet(args, train_dl, val_dl, model, epochs, optimizer, loss_func, scheduler, device, early_stopping):
360 writer = SummaryWriter()
361 model_log = tqdm(total=0, position=1, bar_format='{desc}')
362 for epoch in tqdm(range(epochs), desc='epochs'):
363
364 # train 1 epoch
365 train_loss = train_on_epoch(args, train_dl, model, optimizer, loss_func, device)
366 writer.add_scalar("Loss/train", train_loss, epoch)
367
368 # validate every epoch
369 val_loss = eval_on_epoch(args, val_dl, model, optimizer, loss_func, device)
370 writer.add_scalar("Loss/val", val_loss, epoch)
371
372 # reduce LR on plateau
373 scheduler.step(val_loss)
374 writer.add_scalar("lr", optimizer.param_groups[0]['lr'], epoch)
375
376 # logging
377 tqdm.write('At epoch {0:6d} : train loss: {1:.4f}, val loss: {2:.4f}'.format(epoch, train_loss, val_loss))
378
379 # check wether to early stop
380 early_stopping(val_loss, model, epoch=epoch, save_multiple=(not args.no_save_multiple), save_all=args.save_all_ckpt)
381 if early_stopping.early_stop:
382 print("Early stopping")
383 break
384
385 model_log.set_description_str(f'Best val loss: {early_stopping.val_loss_min:.4f}')
386
387 if epoch % args.i_eval == 0:
388 get_error_in_q(args, val_dl, model, len(val_dl.dataset), device, batch_size=1)
389
390
391 writer.flush()

Callers

nothing calls this directly

Calls 3

train_on_epochFunction · 0.70
eval_on_epochFunction · 0.70
get_error_in_qFunction · 0.70

Tested by

no test coverage detected