My PyTorch Utils

Useful util functions.

LR_Scheduler

class encoding.utils.LR_Scheduler(args, niters=0)[source]

Learning Rate Scheduler

Step mode: lr = baselr * 0.1 ^ {floor(epoch-1 / lr_step)}

Cosine mode: lr = baselr * 0.5 * (1 + cos(iter/maxiter))

Poly mode: lr = baselr * (1 - iter/maxiter) ^ 0.9

Parameters:
  • argsargs.lr_scheduler lr scheduler mode (cos, poly), args.lr base learning rate, args.epochs number of epochs, args.lr_step
  • niters – number of iterations per epoch

get_optimizer

encoding.utils.get_optimizer(args, model, diff_LR=True)[source]

Returns an optimizer for given model,

Parameters:
  • argsargs.lr, args.momentum, args.weight_decay
  • model – if using different lr, define model.pretrained and model.head.

save_checkpoint

encoding.utils.save_checkpoint(state, args, is_best, filename='checkpoint.pth.tar')[source]

Saves checkpoint to disk

progress_bar

encoding.utils.progress_bar(current, total, msg=None)[source]

Progress Bar for display