glenn-jocher commited on
Commit
c09fb2a
1 Parent(s): 932dc78

Update TQDM bar format (#6988)

Browse files
Files changed (2) hide show
  1. utils/autoanchor.py +1 -1
  2. utils/datasets.py +4 -3
utils/autoanchor.py CHANGED
@@ -152,7 +152,7 @@ def kmean_anchors(dataset='./data/coco128.yaml', n=9, img_size=640, thr=4.0, gen
152
 
153
  # Evolve
154
  f, sh, mp, s = anchor_fitness(k), k.shape, 0.9, 0.1 # fitness, generations, mutation prob, sigma
155
- pbar = tqdm(range(gen), desc=f'{PREFIX}Evolving anchors with Genetic Algorithm:') # progress bar
156
  for _ in pbar:
157
  v = np.ones(sh)
158
  while (v == 1).all(): # mutate until a change occurs (prevent duplicates)
 
152
 
153
  # Evolve
154
  f, sh, mp, s = anchor_fitness(k), k.shape, 0.9, 0.1 # fitness, generations, mutation prob, sigma
155
+ pbar = tqdm(range(gen), bar_format='{l_bar}{bar:10}{r_bar}{bar:-10b}') # progress bar
156
  for _ in pbar:
157
  v = np.ones(sh)
158
  while (v == 1).all(): # mutate until a change occurs (prevent duplicates)
utils/datasets.py CHANGED
@@ -35,6 +35,7 @@ from utils.torch_utils import torch_distributed_zero_first
35
  HELP_URL = 'https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data'
36
  IMG_FORMATS = 'bmp', 'dng', 'jpeg', 'jpg', 'mpo', 'png', 'tif', 'tiff', 'webp' # include image suffixes
37
  VID_FORMATS = 'asf', 'avi', 'gif', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'ts', 'wmv' # include video suffixes
 
38
 
39
  # Get orientation exif tag
40
  for orientation in ExifTags.TAGS.keys():
@@ -427,7 +428,7 @@ class LoadImagesAndLabels(Dataset):
427
  nf, nm, ne, nc, n = cache.pop('results') # found, missing, empty, corrupt, total
428
  if exists:
429
  d = f"Scanning '{cache_path}' images and labels... {nf} found, {nm} missing, {ne} empty, {nc} corrupt"
430
- tqdm(None, desc=prefix + d, total=n, initial=n) # display cache results
431
  if cache['msgs']:
432
  LOGGER.info('\n'.join(cache['msgs'])) # display warnings
433
  assert nf > 0 or not augment, f'{prefix}No labels in {cache_path}. Can not train without labels. See {HELP_URL}'
@@ -492,7 +493,7 @@ class LoadImagesAndLabels(Dataset):
492
  self.im_hw0, self.im_hw = [None] * n, [None] * n
493
  fcn = self.cache_images_to_disk if cache_images == 'disk' else self.load_image
494
  results = ThreadPool(NUM_THREADS).imap(fcn, range(n))
495
- pbar = tqdm(enumerate(results), total=n)
496
  for i, x in pbar:
497
  if cache_images == 'disk':
498
  gb += self.npy_files[i].stat().st_size
@@ -509,7 +510,7 @@ class LoadImagesAndLabels(Dataset):
509
  desc = f"{prefix}Scanning '{path.parent / path.stem}' images and labels..."
510
  with Pool(NUM_THREADS) as pool:
511
  pbar = tqdm(pool.imap(verify_image_label, zip(self.im_files, self.label_files, repeat(prefix))),
512
- desc=desc, total=len(self.im_files))
513
  for im_file, lb, shape, segments, nm_f, nf_f, ne_f, nc_f, msg in pbar:
514
  nm += nm_f
515
  nf += nf_f
 
35
  HELP_URL = 'https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data'
36
  IMG_FORMATS = 'bmp', 'dng', 'jpeg', 'jpg', 'mpo', 'png', 'tif', 'tiff', 'webp' # include image suffixes
37
  VID_FORMATS = 'asf', 'avi', 'gif', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'ts', 'wmv' # include video suffixes
38
+ BAR_FORMAT = '{l_bar}{bar:10}{r_bar}{bar:-10b}' # tqdm bar format
39
 
40
  # Get orientation exif tag
41
  for orientation in ExifTags.TAGS.keys():
 
428
  nf, nm, ne, nc, n = cache.pop('results') # found, missing, empty, corrupt, total
429
  if exists:
430
  d = f"Scanning '{cache_path}' images and labels... {nf} found, {nm} missing, {ne} empty, {nc} corrupt"
431
+ tqdm(None, desc=prefix + d, total=n, initial=n, bar_format=BAR_FORMAT) # display cache results
432
  if cache['msgs']:
433
  LOGGER.info('\n'.join(cache['msgs'])) # display warnings
434
  assert nf > 0 or not augment, f'{prefix}No labels in {cache_path}. Can not train without labels. See {HELP_URL}'
 
493
  self.im_hw0, self.im_hw = [None] * n, [None] * n
494
  fcn = self.cache_images_to_disk if cache_images == 'disk' else self.load_image
495
  results = ThreadPool(NUM_THREADS).imap(fcn, range(n))
496
+ pbar = tqdm(enumerate(results), total=n, bar_format=BAR_FORMAT)
497
  for i, x in pbar:
498
  if cache_images == 'disk':
499
  gb += self.npy_files[i].stat().st_size
 
510
  desc = f"{prefix}Scanning '{path.parent / path.stem}' images and labels..."
511
  with Pool(NUM_THREADS) as pool:
512
  pbar = tqdm(pool.imap(verify_image_label, zip(self.im_files, self.label_files, repeat(prefix))),
513
+ desc=desc, total=len(self.im_files), bar_format=BAR_FORMAT)
514
  for im_file, lb, shape, segments, nm_f, nf_f, ne_f, nc_f, msg in pbar:
515
  nm += nm_f
516
  nf += nf_f