Skip to content

Commit 5f941a8

Browse files
Print dataset scan only if RANK in (-1, 0) (#7337)
* Print dataset scan only `if RANK in (-1, 0)` * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 676e10c commit 5f941a8

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

train.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio
316316
train_loader.sampler.set_epoch(epoch)
317317
pbar = enumerate(train_loader)
318318
LOGGER.info(('\n' + '%10s' * 7) % ('Epoch', 'gpu_mem', 'box', 'obj', 'cls', 'labels', 'img_size'))
319-
if RANK in [-1, 0]:
319+
if RANK in (-1, 0):
320320
pbar = tqdm(pbar, total=nb, bar_format='{l_bar}{bar:10}{r_bar}{bar:-10b}') # progress bar
321321
optimizer.zero_grad()
322322
for i, (imgs, targets, paths, _) in pbar: # batch -------------------------------------------------------------
@@ -365,7 +365,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio
365365
last_opt_step = ni
366366

367367
# Log
368-
if RANK in [-1, 0]:
368+
if RANK in (-1, 0):
369369
mloss = (mloss * i + loss_items) / (i + 1) # update mean losses
370370
mem = f'{torch.cuda.memory_reserved() / 1E9 if torch.cuda.is_available() else 0:.3g}G' # (GB)
371371
pbar.set_description(('%10s' * 2 + '%10.4g' * 5) %
@@ -379,7 +379,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio
379379
lr = [x['lr'] for x in optimizer.param_groups] # for loggers
380380
scheduler.step()
381381

382-
if RANK in [-1, 0]:
382+
if RANK in (-1, 0):
383383
# mAP
384384
callbacks.run('on_train_epoch_end', epoch=epoch)
385385
ema.update_attr(model, include=['yaml', 'nc', 'hyp', 'names', 'stride', 'class_weights'])
@@ -440,7 +440,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio
440440

441441
# end epoch ----------------------------------------------------------------------------------------------------
442442
# end training -----------------------------------------------------------------------------------------------------
443-
if RANK in [-1, 0]:
443+
if RANK in (-1, 0):
444444
LOGGER.info(f'\n{epoch - start_epoch + 1} epochs completed in {(time.time() - t0) / 3600:.3f} hours.')
445445
for f in last, best:
446446
if f.exists():
@@ -518,7 +518,7 @@ def parse_opt(known=False):
518518

519519
def main(opt, callbacks=Callbacks()):
520520
# Checks
521-
if RANK in [-1, 0]:
521+
if RANK in (-1, 0):
522522
print_args(vars(opt))
523523
check_git_status()
524524
check_requirements(exclude=['thop'])

utils/datasets.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
IMG_FORMATS = 'bmp', 'dng', 'jpeg', 'jpg', 'mpo', 'png', 'tif', 'tiff', 'webp' # include image suffixes
3737
VID_FORMATS = 'asf', 'avi', 'gif', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'ts', 'wmv' # include video suffixes
3838
BAR_FORMAT = '{l_bar}{bar:10}{r_bar}{bar:-10b}' # tqdm bar format
39+
LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html
3940

4041
# Get orientation exif tag
4142
for orientation in ExifTags.TAGS.keys():
@@ -454,7 +455,7 @@ def __init__(self,
454455

455456
# Display cache
456457
nf, nm, ne, nc, n = cache.pop('results') # found, missing, empty, corrupt, total
457-
if exists:
458+
if exists and LOCAL_RANK in (-1, 0):
458459
d = f"Scanning '{cache_path}' images and labels... {nf} found, {nm} missing, {ne} empty, {nc} corrupt"
459460
tqdm(None, desc=prefix + d, total=n, initial=n, bar_format=BAR_FORMAT) # display cache results
460461
if cache['msgs']:

0 commit comments

Comments
 (0)