Home

Awesome

OnlineLabelSmoothing

This is a re-implementation of Online Label Smoothing. The code is written based on my understanding of the paper. If there's any bug in my code, please tell me in the Issues page.

Usage

from OLS import OnlineLabelSmoothing

ols_loss = OnlineLabelSmoothing(num_classes=1000, use_gpu=True)

# Training
for epoch in range(total_epoch):
    # train()
    # test()
    ols_loss.update()

# Saving
torch.save({'ols': ols_loss.matrix.cpu().data}, 'ols.pth')

Results

Environment

Other Setting

num_classes: 1000
optimizer: SGD
init_lr: 0.1
weight_decay: 0.0001
momentum: 0.9
lr_gamma: 0.1
total_epoch: 250
batch_size: 256
num_workers: 20
random_seed: 2020
amp: True # automatic mixed-precision training, this function is offered by pytorch

Train

python train.py --amp -s cos --loss ce ols --loss_w 0.5 0.5
CUDA_VISIBLE_DEVICES=0,1 python -m torch.distributed.launch\
--nproc_per_node=2 --master_addr 127.0.0.7 --master_port 23456\
train.py --multi-gpus 1 -nw 20 --amp -s multi --loss ce ols --loss_w 0.5 0.5
# Limited computing resources

Accuracy on Validation Set of ImageNet2012

Although I used AMP(automatic mixed-precision) to speed up my training, it still took me nearly five days, so I didn't do any other experiments with ols. But there are other records of training ImageNet in my blog.

ModelLossepocheslr_scheduleAcc@1Acc@5
ResNet50CE250Multi Step [75,150,225]76.3293.06
ResNet50CE250COS with 5 epochs warmup76.9593.27
ResNet500.5*CE+0.5*OLS250Multi Step [75,150,225]77.2793.47
ResNet500.5*CE+0.5*OLS250COS with 5 epochs warmup77.7993.79
ResNet50LS(e=0.1)250COS with 5 epochs warmup77.6293.75
ResNet50LS(e=0.2)250COS with 5 epochs warmup77.8993.74

Reference