LOGGER consolidation (#5569)

* Logger consolidation

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

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

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Glenn Jocher 2021-11-08 16:32:15 +01:00 committed by GitHub
parent 0de4a9c35d
commit 79bca2bf64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 21 deletions

View File

@ -3,7 +3,6 @@
Common modules Common modules
""" """
import logging
import math import math
import warnings import warnings
from copy import copy from copy import copy
@ -18,12 +17,10 @@ from PIL import Image
from torch.cuda import amp from torch.cuda import amp
from utils.datasets import exif_transpose, letterbox from utils.datasets import exif_transpose, letterbox
from utils.general import colorstr, increment_path, make_divisible, non_max_suppression, scale_coords, xyxy2xywh from utils.general import LOGGER, colorstr, increment_path, make_divisible, non_max_suppression, scale_coords, xyxy2xywh
from utils.plots import Annotator, colors, save_one_box from utils.plots import Annotator, colors, save_one_box
from utils.torch_utils import time_sync from utils.torch_utils import time_sync
LOGGER = logging.getLogger(__name__)
def autopad(k, p=None): # kernel, padding def autopad(k, p=None): # kernel, padding
# Pad to 'same' # Pad to 'same'

View File

@ -7,7 +7,6 @@ Usage:
""" """
import argparse import argparse
import logging
import math import math
import os import os
import random import random
@ -201,8 +200,8 @@ def train(hyp, # path/to/hyp.yaml or hyp dictionary
# DP mode # DP mode
if cuda and RANK == -1 and torch.cuda.device_count() > 1: if cuda and RANK == -1 and torch.cuda.device_count() > 1:
logging.warning('DP not recommended, instead use torch.distributed.run for best DDP Multi-GPU results.\n' LOGGER.warning('WARNING: DP not recommended, use torch.distributed.run for best DDP Multi-GPU results.\n'
'See Multi-GPU Tutorial at https://github.com/ultralytics/yolov5/issues/475 to get started.') 'See Multi-GPU Tutorial at https://github.com/ultralytics/yolov5/issues/475 to get started.')
model = torch.nn.DataParallel(model) model = torch.nn.DataParallel(model)
# SyncBatchNorm # SyncBatchNorm

View File

@ -3,14 +3,13 @@
Image augmentation functions Image augmentation functions
""" """
import logging
import math import math
import random import random
import cv2 import cv2
import numpy as np import numpy as np
from utils.general import check_version, colorstr, resample_segments, segment2box from utils.general import LOGGER, check_version, colorstr, resample_segments, segment2box
from utils.metrics import bbox_ioa from utils.metrics import bbox_ioa
@ -32,11 +31,11 @@ class Albumentations:
A.ImageCompression(quality_lower=75, p=0.0)], A.ImageCompression(quality_lower=75, p=0.0)],
bbox_params=A.BboxParams(format='yolo', label_fields=['class_labels'])) bbox_params=A.BboxParams(format='yolo', label_fields=['class_labels']))
logging.info(colorstr('albumentations: ') + ', '.join(f'{x}' for x in self.transform.transforms if x.p)) LOGGER.info(colorstr('albumentations: ') + ', '.join(f'{x}' for x in self.transform.transforms if x.p))
except ImportError: # package not installed, skip except ImportError: # package not installed, skip
pass pass
except Exception as e: except Exception as e:
logging.info(colorstr('albumentations: ') + f'{e}') LOGGER.info(colorstr('albumentations: ') + f'{e}')
def __call__(self, im, labels, p=1.0): def __call__(self, im, labels, p=1.0):
if self.transform and random.random() < p: if self.transform and random.random() < p:

View File

@ -6,7 +6,6 @@ Dataloaders and dataset utils
import glob import glob
import hashlib import hashlib
import json import json
import logging
import os import os
import random import random
import shutil import shutil
@ -335,7 +334,7 @@ class LoadStreams:
if success: if success:
self.imgs[i] = im self.imgs[i] = im
else: else:
LOGGER.warn('WARNING: Video stream unresponsive, please check your IP camera connection.') LOGGER.warning('WARNING: Video stream unresponsive, please check your IP camera connection.')
self.imgs[i] *= 0 self.imgs[i] *= 0
cap.open(stream) # re-open stream if signal was lost cap.open(stream) # re-open stream if signal was lost
time.sleep(1 / self.fps[i]) # wait time time.sleep(1 / self.fps[i]) # wait time
@ -427,7 +426,7 @@ class LoadImagesAndLabels(Dataset):
d = f"Scanning '{cache_path}' images and labels... {nf} found, {nm} missing, {ne} empty, {nc} corrupted" d = f"Scanning '{cache_path}' images and labels... {nf} found, {nm} missing, {ne} empty, {nc} corrupted"
tqdm(None, desc=prefix + d, total=n, initial=n) # display cache results tqdm(None, desc=prefix + d, total=n, initial=n) # display cache results
if cache['msgs']: if cache['msgs']:
logging.info('\n'.join(cache['msgs'])) # display warnings 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}' assert nf > 0 or not augment, f'{prefix}No labels in {cache_path}. Can not train without labels. See {HELP_URL}'
# Read cache # Read cache
@ -525,9 +524,9 @@ class LoadImagesAndLabels(Dataset):
pbar.close() pbar.close()
if msgs: if msgs:
logging.info('\n'.join(msgs)) LOGGER.info('\n'.join(msgs))
if nf == 0: if nf == 0:
logging.info(f'{prefix}WARNING: No labels found in {path}. See {HELP_URL}') LOGGER.warning(f'{prefix}WARNING: No labels found in {path}. See {HELP_URL}')
x['hash'] = get_hash(self.label_files + self.img_files) x['hash'] = get_hash(self.label_files + self.img_files)
x['results'] = nf, nm, ne, nc, len(self.img_files) x['results'] = nf, nm, ne, nc, len(self.img_files)
x['msgs'] = msgs # warnings x['msgs'] = msgs # warnings
@ -535,9 +534,9 @@ class LoadImagesAndLabels(Dataset):
try: try:
np.save(path, x) # save cache for next time np.save(path, x) # save cache for next time
path.with_suffix('.cache.npy').rename(path) # remove .npy suffix path.with_suffix('.cache.npy').rename(path) # remove .npy suffix
logging.info(f'{prefix}New cache created: {path}') LOGGER.info(f'{prefix}New cache created: {path}')
except Exception as e: except Exception as e:
logging.info(f'{prefix}WARNING: Cache directory {path.parent} is not writeable: {e}') # path not writeable LOGGER.warning(f'{prefix}WARNING: Cache directory {path.parent} is not writeable: {e}') # not writeable
return x return x
def __len__(self): def __len__(self):

View File

@ -45,7 +45,7 @@ ROOT = FILE.parents[1] # YOLOv5 root directory
def set_logging(name=None, verbose=True): def set_logging(name=None, verbose=True):
# Sets level and returns logger # Sets level and returns logger
rank = int(os.getenv('RANK', -1)) # rank in world for Multi-GPU trainings rank = int(os.getenv('RANK', -1)) # rank in world for Multi-GPU trainings
logging.basicConfig(format="%(message)s", level=logging.INFO if (verbose and rank in (-1, 0)) else logging.WARN) logging.basicConfig(format="%(message)s", level=logging.INFO if (verbose and rank in (-1, 0)) else logging.WARNING)
return logging.getLogger(name) return logging.getLogger(name)

View File

@ -4,7 +4,6 @@ PyTorch utils
""" """
import datetime import datetime
import logging
import math import math
import os import os
import platform import platform
@ -100,7 +99,6 @@ def profile(input, ops, n=10, device=None):
# profile(input, [m1, m2], n=100) # profile over 100 iterations # profile(input, [m1, m2], n=100) # profile over 100 iterations
results = [] results = []
logging.basicConfig(format="%(message)s", level=logging.INFO)
device = device or select_device() device = device or select_device()
print(f"{'Params':>12s}{'GFLOPs':>12s}{'GPU_mem (GB)':>14s}{'forward (ms)':>14s}{'backward (ms)':>14s}" print(f"{'Params':>12s}{'GFLOPs':>12s}{'GPU_mem (GB)':>14s}{'forward (ms)':>14s}{'backward (ms)':>14s}"
f"{'input':>24s}{'output':>24s}") f"{'input':>24s}{'output':>24s}")