Skip to content

Commit

Permalink
Update TQDM bar format (ultralytics#6988)
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher committed Mar 15, 2022
1 parent 9326c0e commit 73bb73b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion utils/autoanchor.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def print_results(k, verbose=True):

# Evolve
f, sh, mp, s = anchor_fitness(k), k.shape, 0.9, 0.1 # fitness, generations, mutation prob, sigma
pbar = tqdm(range(gen), desc=f'{PREFIX}Evolving anchors with Genetic Algorithm:') # progress bar
pbar = tqdm(range(gen), bar_format='{l_bar}{bar:10}{r_bar}{bar:-10b}') # progress bar
for _ in pbar:
v = np.ones(sh)
while (v == 1).all(): # mutate until a change occurs (prevent duplicates)
Expand Down
7 changes: 4 additions & 3 deletions utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
HELP_URL = 'https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data'
IMG_FORMATS = 'bmp', 'dng', 'jpeg', 'jpg', 'mpo', 'png', 'tif', 'tiff', 'webp' # include image suffixes
VID_FORMATS = 'asf', 'avi', 'gif', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'ts', 'wmv' # include video suffixes
BAR_FORMAT = '{l_bar}{bar:10}{r_bar}{bar:-10b}' # tqdm bar format

# Get orientation exif tag
for orientation in ExifTags.TAGS.keys():
Expand Down Expand Up @@ -427,7 +428,7 @@ def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, r
nf, nm, ne, nc, n = cache.pop('results') # found, missing, empty, corrupt, total
if exists:
d = f"Scanning '{cache_path}' images and labels... {nf} found, {nm} missing, {ne} empty, {nc} corrupt"
tqdm(None, desc=prefix + d, total=n, initial=n) # display cache results
tqdm(None, desc=prefix + d, total=n, initial=n, bar_format=BAR_FORMAT) # display cache results
if cache['msgs']:
LOGGER.info('\n'.join(cache['msgs'])) # display warnings
assert nf > 0 or not augment, f'{prefix}No labels in {cache_path}. Can not train without labels. See {HELP_URL}'
Expand Down Expand Up @@ -492,7 +493,7 @@ def __init__(self, path, img_size=640, batch_size=16, augment=False, hyp=None, r
self.im_hw0, self.im_hw = [None] * n, [None] * n
fcn = self.cache_images_to_disk if cache_images == 'disk' else self.load_image
results = ThreadPool(NUM_THREADS).imap(fcn, range(n))
pbar = tqdm(enumerate(results), total=n)
pbar = tqdm(enumerate(results), total=n, bar_format=BAR_FORMAT)
for i, x in pbar:
if cache_images == 'disk':
gb += self.npy_files[i].stat().st_size
Expand All @@ -509,7 +510,7 @@ def cache_labels(self, path=Path('./labels.cache'), prefix=''):
desc = f"{prefix}Scanning '{path.parent / path.stem}' images and labels..."
with Pool(NUM_THREADS) as pool:
pbar = tqdm(pool.imap(verify_image_label, zip(self.im_files, self.label_files, repeat(prefix))),
desc=desc, total=len(self.im_files))
desc=desc, total=len(self.im_files), bar_format=BAR_FORMAT)
for im_file, lb, shape, segments, nm_f, nf_f, ne_f, nc_f, msg in pbar:
nm += nm_f
nf += nf_f
Expand Down

0 comments on commit 73bb73b

Please sign in to comment.