Update train, val `tqdm` to fixed width (#5367)
* 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>
This commit is contained in:
parent
27bf4282d3
commit
61c50199a2
11
train.py
11
train.py
|
|
@ -5,7 +5,6 @@ Train a YOLOv5 model on a custom dataset
|
||||||
Usage:
|
Usage:
|
||||||
$ python path/to/train.py --data coco128.yaml --weights yolov5s.pt --img 640
|
$ python path/to/train.py --data coco128.yaml --weights yolov5s.pt --img 640
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
|
|
@ -40,10 +39,10 @@ from utils.autobatch import check_train_batch_size
|
||||||
from utils.callbacks import Callbacks
|
from utils.callbacks import Callbacks
|
||||||
from utils.datasets import create_dataloader
|
from utils.datasets import create_dataloader
|
||||||
from utils.downloads import attempt_download
|
from utils.downloads import attempt_download
|
||||||
from utils.general import (LOGGER, check_dataset, check_file, check_git_status, check_img_size, check_requirements,
|
from utils.general import (LOGGER, NCOLS, check_dataset, check_file, check_git_status, check_img_size,
|
||||||
check_suffix, check_yaml, colorstr, get_latest_run, increment_path, init_seeds,
|
check_requirements, check_suffix, check_yaml, colorstr, get_latest_run, increment_path,
|
||||||
intersect_dicts, labels_to_class_weights, labels_to_image_weights, methods, one_cycle,
|
init_seeds, intersect_dicts, labels_to_class_weights, labels_to_image_weights, methods,
|
||||||
print_args, print_mutation, strip_optimizer)
|
one_cycle, print_args, print_mutation, strip_optimizer)
|
||||||
from utils.loggers import Loggers
|
from utils.loggers import Loggers
|
||||||
from utils.loggers.wandb.wandb_utils import check_wandb_resume
|
from utils.loggers.wandb.wandb_utils import check_wandb_resume
|
||||||
from utils.loss import ComputeLoss
|
from utils.loss import ComputeLoss
|
||||||
|
|
@ -289,7 +288,7 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
|
||||||
pbar = enumerate(train_loader)
|
pbar = enumerate(train_loader)
|
||||||
LOGGER.info(('\n' + '%10s' * 7) % ('Epoch', 'gpu_mem', 'box', 'obj', 'cls', 'labels', 'img_size'))
|
LOGGER.info(('\n' + '%10s' * 7) % ('Epoch', 'gpu_mem', 'box', 'obj', 'cls', 'labels', 'img_size'))
|
||||||
if RANK in [-1, 0]:
|
if RANK in [-1, 0]:
|
||||||
pbar = tqdm(pbar, total=nb) # progress bar
|
pbar = tqdm(pbar, total=nb, ncols=NCOLS, bar_format='{l_bar}{bar:10}{r_bar}{bar:-10b}') # progress bar
|
||||||
optimizer.zero_grad()
|
optimizer.zero_grad()
|
||||||
for i, (imgs, targets, paths, _) in pbar: # batch -------------------------------------------------------------
|
for i, (imgs, targets, paths, _) in pbar: # batch -------------------------------------------------------------
|
||||||
ni = i + nb * epoch # number integrated batches (since train start)
|
ni = i + nb * epoch # number integrated batches (since train start)
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import os
|
||||||
import platform
|
import platform
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
import shutil
|
||||||
import signal
|
import signal
|
||||||
import time
|
import time
|
||||||
import urllib
|
import urllib
|
||||||
|
|
@ -834,3 +835,7 @@ def increment_path(path, exist_ok=False, sep='', mkdir=False):
|
||||||
if mkdir:
|
if mkdir:
|
||||||
path.mkdir(parents=True, exist_ok=True) # make directory
|
path.mkdir(parents=True, exist_ok=True) # make directory
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
NCOLS = 0 if is_docker() else shutil.get_terminal_size().columns # terminal window size
|
||||||
|
|
|
||||||
5
val.py
5
val.py
|
|
@ -26,7 +26,7 @@ ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative
|
||||||
from models.common import DetectMultiBackend
|
from models.common import DetectMultiBackend
|
||||||
from utils.callbacks import Callbacks
|
from utils.callbacks import Callbacks
|
||||||
from utils.datasets import create_dataloader
|
from utils.datasets import create_dataloader
|
||||||
from utils.general import (LOGGER, box_iou, check_dataset, check_img_size, check_requirements, check_yaml,
|
from utils.general import (LOGGER, NCOLS, box_iou, check_dataset, check_img_size, check_requirements, check_yaml,
|
||||||
coco80_to_coco91_class, colorstr, increment_path, non_max_suppression, print_args,
|
coco80_to_coco91_class, colorstr, increment_path, non_max_suppression, print_args,
|
||||||
scale_coords, xywh2xyxy, xyxy2xywh)
|
scale_coords, xywh2xyxy, xyxy2xywh)
|
||||||
from utils.metrics import ConfusionMatrix, ap_per_class
|
from utils.metrics import ConfusionMatrix, ap_per_class
|
||||||
|
|
@ -162,7 +162,8 @@ def run(data,
|
||||||
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
|
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
|
||||||
loss = torch.zeros(3, device=device)
|
loss = torch.zeros(3, device=device)
|
||||||
jdict, stats, ap, ap_class = [], [], [], []
|
jdict, stats, ap, ap_class = [], [], [], []
|
||||||
for batch_i, (im, targets, paths, shapes) in enumerate(tqdm(dataloader, desc=s)):
|
pbar = tqdm(dataloader, desc=s, ncols=NCOLS, bar_format='{l_bar}{bar:10}{r_bar}{bar:-10b}') # progress bar
|
||||||
|
for batch_i, (im, targets, paths, shapes) in enumerate(pbar):
|
||||||
t1 = time_sync()
|
t1 = time_sync()
|
||||||
if pt:
|
if pt:
|
||||||
im = im.to(device, non_blocking=True)
|
im = im.to(device, non_blocking=True)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue