From 9b1f341a2c31d6d802c511398cbd6cbed0d50442 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 28 Aug 2021 19:08:24 +0200 Subject: [PATCH 1/2] Initial commit --- train.py | 1 + 1 file changed, 1 insertion(+) diff --git a/train.py b/train.py index a6c34cbc466c..dd670201a29e 100644 --- a/train.py +++ b/train.py @@ -278,6 +278,7 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary dist.broadcast(indices, 0) if RANK != 0: dataset.indices = indices.cpu().numpy() + print(RANK, dataset.indices[:10]) # Update mosaic border # b = int(random.uniform(0.25 * imgsz, 0.75 * imgsz + gs) // gs * gs) From 982d4e2aa84ce56bca799bc79832deb64789fc45 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 28 Aug 2021 19:12:29 +0200 Subject: [PATCH 2/2] Update --- train.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/train.py b/train.py index dd670201a29e..aaee41a499e4 100644 --- a/train.py +++ b/train.py @@ -265,22 +265,13 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary for epoch in range(start_epoch, epochs): # epoch ------------------------------------------------------------------ model.train() - # Update image weights (optional) + # Update image weights (optional, single-GPU only) if opt.image_weights: - # Generate indices - if RANK in [-1, 0]: - cw = model.class_weights.cpu().numpy() * (1 - maps) ** 2 / nc # class weights - iw = labels_to_image_weights(dataset.labels, nc=nc, class_weights=cw) # image weights - dataset.indices = random.choices(range(dataset.n), weights=iw, k=dataset.n) # rand weighted idx - # Broadcast if DDP - if RANK != -1: - indices = (torch.tensor(dataset.indices) if RANK == 0 else torch.zeros(dataset.n)).int() - dist.broadcast(indices, 0) - if RANK != 0: - dataset.indices = indices.cpu().numpy() - print(RANK, dataset.indices[:10]) - - # Update mosaic border + cw = model.class_weights.cpu().numpy() * (1 - maps) ** 2 / nc # class weights + iw = labels_to_image_weights(dataset.labels, nc=nc, class_weights=cw) # image weights + dataset.indices = random.choices(range(dataset.n), weights=iw, k=dataset.n) # rand weighted idx + + # Update mosaic border (optional) # b = int(random.uniform(0.25 * imgsz, 0.75 * imgsz + gs) // gs * gs) # dataset.mosaic_border = [b - imgsz, -b] # height, width borders