From 6f3db5e662839796d91a858dd80a22c00e989f96 Mon Sep 17 00:00:00 2001 From: Naman Gupta <32638824+namangup@users.noreply.github.com> Date: Wed, 2 Sep 2020 21:35:31 +0530 Subject: [PATCH] Remove autoanchor and class checks on resumed training (#889) * Class frequency not calculated on resuming training Calculation of class frequency is not needed when resuming training. Anchors can still be recalculated whether resuming or not. * Check rank for autoanchor * Update train.py no autoanchor checks on resume Co-authored-by: Glenn Jocher --- train.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/train.py b/train.py index 6ff0c7d..c1e8db3 100644 --- a/train.py +++ b/train.py @@ -185,18 +185,18 @@ def train(hyp, opt, device, tb_writer=None): model.class_weights = labels_to_class_weights(dataset.labels, nc).to(device) # attach class weights model.names = names - # Class frequency - if rank in [-1, 0]: + # Classes and Anchors + if rank in [-1, 0] and not opt.resume: labels = np.concatenate(dataset.labels, 0) c = torch.tensor(labels[:, 0]) # classes - # cf = torch.bincount(c.long(), minlength=nc) + 1. + # cf = torch.bincount(c.long(), minlength=nc) + 1. # frequency # model._initialize_biases(cf.to(device)) plot_labels(labels, save_dir=log_dir) if tb_writer: # tb_writer.add_hparams(hyp, {}) # causes duplicate https://github.com/ultralytics/yolov5/pull/384 tb_writer.add_histogram('classes', c, 0) - # Check anchors + # Anchors if not opt.noautoanchor: check_anchors(dataset, model=model, thr=hyp['anchor_t'], imgsz=imgsz)