Update get_loggers() (#4854)
* Update `set_logging()` * Update export.py * pre-commit fixes * Update LoadImages * Update LoadStreams * Update print_args * Single LOGGER definition * yolo.py fix Co-authored-by: pre-commit <pre-commit@example.com>
This commit is contained in:
1 parent
8c326a1edf
commit
7b1f7aec46
8 files changed
+84
-91
No files matched your search
@@ -25,8 +25,7 @@ ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative
|
||||
from models.experimental import attempt_load
|
||||
from utils.datasets import LoadImages, LoadStreams
|
||||
from utils.general import apply_classifier, check_img_size, check_imshow, check_requirements, check_suffix, colorstr, \
|
||||
increment_path, non_max_suppression, print_args, save_one_box, scale_coords, set_logging, \
|
||||
strip_optimizer, xyxy2xywh
|
||||
increment_path, non_max_suppression, print_args, save_one_box, scale_coords, strip_optimizer, xyxy2xywh, LOGGER
|
||||
from utils.plots import Annotator, colors
|
||||
from utils.torch_utils import load_classifier, select_device, time_sync
|
||||
|
||||
@@ -68,7 +67,6 @@ def run(weights=ROOT / 'yolov5s.pt', # model.pt path(s)
|
||||
(save_dir / 'labels' if save_txt else save_dir).mkdir(parents=True, exist_ok=True) # make dir
|
||||
|
||||
# Initialize
|
||||
set_logging()
|
||||
device = select_device(device)
|
||||
half &= device.type != 'cpu' # half precision only supported on CUDA
|
||||
|
||||
@@ -132,7 +130,7 @@ def run(weights=ROOT / 'yolov5s.pt', # model.pt path(s)
|
||||
if pt and device.type != 'cpu':
|
||||
model(torch.zeros(1, 3, *imgsz).to(device).type_as(next(model.parameters()))) # run once
|
||||
dt, seen = [0.0, 0.0, 0.0], 0
|
||||
for path, img, im0s, vid_cap in dataset:
|
||||
for path, img, im0s, vid_cap, s in dataset:
|
||||
t1 = time_sync()
|
||||
if onnx:
|
||||
img = img.astype('float32')
|
||||
@@ -191,9 +189,10 @@ def run(weights=ROOT / 'yolov5s.pt', # model.pt path(s)
|
||||
for i, det in enumerate(pred): # per image
|
||||
seen += 1
|
||||
if webcam: # batch_size >= 1
|
||||
p, s, im0, frame = path[i], f'{i}: ', im0s[i].copy(), dataset.count
|
||||
p, im0, frame = path[i], im0s[i].copy(), dataset.count
|
||||
s += f'{i}: '
|
||||
else:
|
||||
p, s, im0, frame = path, '', im0s.copy(), getattr(dataset, 'frame', 0)
|
||||
p, im0, frame = path, im0s.copy(), getattr(dataset, 'frame', 0)
|
||||
|
||||
p = Path(p) # to Path
|
||||
save_path = str(save_dir / p.name) # img.jpg
|
||||
@@ -227,7 +226,7 @@ def run(weights=ROOT / 'yolov5s.pt', # model.pt path(s)
|
||||
save_one_box(xyxy, imc, file=save_dir / 'crops' / names[c] / f'{p.stem}.jpg', BGR=True)
|
||||
|
||||
# Print time (inference-only)
|
||||
print(f'{s}Done. ({t3 - t2:.3f}s)')
|
||||
LOGGER.info(f'{s}Done. ({t3 - t2:.3f}s)')
|
||||
|
||||
# Stream results
|
||||
im0 = annotator.result()
|
||||
@@ -256,10 +255,10 @@ def run(weights=ROOT / 'yolov5s.pt', # model.pt path(s)
|
||||
|
||||
# Print results
|
||||
t = tuple(x / seen * 1E3 for x in dt) # speeds per image
|
||||
print(f'Speed: %.1fms pre-process, %.1fms inference, %.1fms NMS per image at shape {(1, 3, *imgsz)}' % t)
|
||||
LOGGER.info(f'Speed: %.1fms pre-process, %.1fms inference, %.1fms NMS per image at shape {(1, 3, *imgsz)}' % t)
|
||||
if save_txt or save_img:
|
||||
s = f"\n{len(list(save_dir.glob('labels/*.txt')))} labels saved to {save_dir / 'labels'}" if save_txt else ''
|
||||
print(f"Results saved to {colorstr('bold', save_dir)}{s}")
|
||||
LOGGER.info(f"Results saved to {colorstr('bold', save_dir)}{s}")
|
||||
if update:
|
||||
strip_optimizer(weights) # update model (to fix SourceChangeWarning)
|
||||
|
||||
|
||||
Reference in new issue
Block a user