glenn-jocher pre-commit-ci[bot] commited on
Commit
61c5019
1 Parent(s): 27bf428

Update train, val `tqdm` to fixed width (#5367)

Browse files

* Update tqdm for fixed width

* Update val.py

* Update val.py

* Try ncols= in train.py

* NCOLS

* NCOLS

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* bar_format

* position 0 leave true

* exp0

* auto

* auto

* Cleanup

* Cleanup

* Cleanup

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

Files changed (3) hide show
  1. train.py +5 -6
  2. utils/general.py +5 -0
  3. val.py +3 -2
train.py CHANGED
@@ -5,7 +5,6 @@ Train a YOLOv5 model on a custom dataset
5
  Usage:
6
  $ python path/to/train.py --data coco128.yaml --weights yolov5s.pt --img 640
7
  """
8
-
9
  import argparse
10
  import math
11
  import os
@@ -40,10 +39,10 @@ from utils.autobatch import check_train_batch_size
40
  from utils.callbacks import Callbacks
41
  from utils.datasets import create_dataloader
42
  from utils.downloads import attempt_download
43
- from utils.general import (LOGGER, check_dataset, check_file, check_git_status, check_img_size, check_requirements,
44
- check_suffix, check_yaml, colorstr, get_latest_run, increment_path, init_seeds,
45
- intersect_dicts, labels_to_class_weights, labels_to_image_weights, methods, one_cycle,
46
- print_args, print_mutation, strip_optimizer)
47
  from utils.loggers import Loggers
48
  from utils.loggers.wandb.wandb_utils import check_wandb_resume
49
  from utils.loss import ComputeLoss
@@ -289,7 +288,7 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
289
  pbar = enumerate(train_loader)
290
  LOGGER.info(('\n' + '%10s' * 7) % ('Epoch', 'gpu_mem', 'box', 'obj', 'cls', 'labels', 'img_size'))
291
  if RANK in [-1, 0]:
292
- pbar = tqdm(pbar, total=nb) # progress bar
293
  optimizer.zero_grad()
294
  for i, (imgs, targets, paths, _) in pbar: # batch -------------------------------------------------------------
295
  ni = i + nb * epoch # number integrated batches (since train start)
 
5
  Usage:
6
  $ python path/to/train.py --data coco128.yaml --weights yolov5s.pt --img 640
7
  """
 
8
  import argparse
9
  import math
10
  import os
 
39
  from utils.callbacks import Callbacks
40
  from utils.datasets import create_dataloader
41
  from utils.downloads import attempt_download
42
+ from utils.general import (LOGGER, NCOLS, check_dataset, check_file, check_git_status, check_img_size,
43
+ check_requirements, check_suffix, check_yaml, colorstr, get_latest_run, increment_path,
44
+ init_seeds, intersect_dicts, labels_to_class_weights, labels_to_image_weights, methods,
45
+ one_cycle, print_args, print_mutation, strip_optimizer)
46
  from utils.loggers import Loggers
47
  from utils.loggers.wandb.wandb_utils import check_wandb_resume
48
  from utils.loss import ComputeLoss
 
288
  pbar = enumerate(train_loader)
289
  LOGGER.info(('\n' + '%10s' * 7) % ('Epoch', 'gpu_mem', 'box', 'obj', 'cls', 'labels', 'img_size'))
290
  if RANK in [-1, 0]:
291
+ pbar = tqdm(pbar, total=nb, ncols=NCOLS, bar_format='{l_bar}{bar:10}{r_bar}{bar:-10b}') # progress bar
292
  optimizer.zero_grad()
293
  for i, (imgs, targets, paths, _) in pbar: # batch -------------------------------------------------------------
294
  ni = i + nb * epoch # number integrated batches (since train start)
utils/general.py CHANGED
@@ -11,6 +11,7 @@ import os
11
  import platform
12
  import random
13
  import re
 
14
  import signal
15
  import time
16
  import urllib
@@ -834,3 +835,7 @@ def increment_path(path, exist_ok=False, sep='', mkdir=False):
834
  if mkdir:
835
  path.mkdir(parents=True, exist_ok=True) # make directory
836
  return path
 
 
 
 
 
11
  import platform
12
  import random
13
  import re
14
+ import shutil
15
  import signal
16
  import time
17
  import urllib
 
835
  if mkdir:
836
  path.mkdir(parents=True, exist_ok=True) # make directory
837
  return path
838
+
839
+
840
+ # Variables
841
+ NCOLS = 0 if is_docker() else shutil.get_terminal_size().columns # terminal window size
val.py CHANGED
@@ -26,7 +26,7 @@ ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative
26
  from models.common import DetectMultiBackend
27
  from utils.callbacks import Callbacks
28
  from utils.datasets import create_dataloader
29
- from utils.general import (LOGGER, box_iou, check_dataset, check_img_size, check_requirements, check_yaml,
30
  coco80_to_coco91_class, colorstr, increment_path, non_max_suppression, print_args,
31
  scale_coords, xywh2xyxy, xyxy2xywh)
32
  from utils.metrics import ConfusionMatrix, ap_per_class
@@ -162,7 +162,8 @@ def run(data,
162
  dt, p, r, f1, mp, mr, map50, map = [0.0, 0.0, 0.0], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
163
  loss = torch.zeros(3, device=device)
164
  jdict, stats, ap, ap_class = [], [], [], []
165
- for batch_i, (im, targets, paths, shapes) in enumerate(tqdm(dataloader, desc=s)):
 
166
  t1 = time_sync()
167
  if pt:
168
  im = im.to(device, non_blocking=True)
 
26
  from models.common import DetectMultiBackend
27
  from utils.callbacks import Callbacks
28
  from utils.datasets import create_dataloader
29
+ from utils.general import (LOGGER, NCOLS, box_iou, check_dataset, check_img_size, check_requirements, check_yaml,
30
  coco80_to_coco91_class, colorstr, increment_path, non_max_suppression, print_args,
31
  scale_coords, xywh2xyxy, xyxy2xywh)
32
  from utils.metrics import ConfusionMatrix, ap_per_class
 
162
  dt, p, r, f1, mp, mr, map50, map = [0.0, 0.0, 0.0], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
163
  loss = torch.zeros(3, device=device)
164
  jdict, stats, ap, ap_class = [], [], [], []
165
+ pbar = tqdm(dataloader, desc=s, ncols=NCOLS, bar_format='{l_bar}{bar:10}{r_bar}{bar:-10b}') # progress bar
166
+ for batch_i, (im, targets, paths, shapes) in enumerate(pbar):
167
  t1 = time_sync()
168
  if pt:
169
  im = im.to(device, non_blocking=True)