diff --git a/train.py b/train.py index 3c74bdfe..ea1a6034 100644 --- a/train.py +++ b/train.py @@ -100,19 +100,23 @@ def train( else: cutoff = load_darknet_weights(model, weights + 'darknet53.conv.74') - # Scheduler (reduce lr at epochs 218, 245, i.e. batches 400k, 450k) + # Scheduler https://github.com/ultralytics/yolov3/issues/238 # lf = lambda x: 1 - x / epochs # linear ramp to zero - # lf = lambda x: 10 ** (-2 * x / epochs) # exp ramp to lr0 * 1e-2 - lf = lambda x: 1 - 10 ** (hyp['lrf'] * (1 - x / epochs)) # inv exp ramp to lr0 * 1e-2 + # lf = lambda x: 10 ** (hyp['lrf'] * x / epochs) # exp ramp to lr0 * hyp['lrf'] + lf = lambda x: 1 - 10 ** (hyp['lrf'] * (1 - x / epochs)) # inv exp ramp to lr0 * hyp['lrf'] scheduler = optim.lr_scheduler.LambdaLR(optimizer, lr_lambda=lf, last_epoch=start_epoch - 1) - # scheduler = optim.lr_scheduler.MultiStepLR(optimizer,milestones=[218, 245],gamma=0.1,last_epoch=start_epoch - 1) + # scheduler = optim.lr_scheduler.MultiStepLR(optimizer, milestones=[218, 245], gamma=0.1, last_epoch=start_epoch - 1) - # Plot lr schedule + # # Plot lr schedule # y = [] # for _ in range(epochs): # scheduler.step() # y.append(optimizer.param_groups[0]['lr']) - # plt.plot(y) + # plt.plot(y, label='LambdaLR') + # plt.xlabel('epoch') + # plt.xlabel('LR') + # plt.tight_layout() + # plt.savefig('LR.png', dpi=300) # Dataset dataset = LoadImagesAndLabels(train_path, img_size=img_size, augment=True) @@ -165,8 +169,6 @@ def train( imgs = imgs.to(device) targets = targets.to(device) nt = len(targets) - # if nt == 0: # if no targets continue - # continue # Plot images with bounding boxes if epoch == 0 and i == 0: