From 988dfbe25095880c6ada83af55dc7ab990ea6d67 Mon Sep 17 00:00:00 2001 From: Ayush Chaurasia Date: Mon, 29 May 2023 15:28:13 +0530 Subject: [PATCH 01/15] first commit --- benchmarks.py | 10 ++++++---- classify/train.py | 4 ++-- export.py | 5 +++-- hubconf.py | 4 ++-- models/common.py | 5 +++-- models/experimental.py | 43 +----------------------------------------- models/tf.py | 6 ++++-- segment/train.py | 4 ++-- train.py | 4 ++-- utils/general.py | 32 ------------------------------- utils/torch_utils.py | 36 ----------------------------------- 11 files changed, 25 insertions(+), 128 deletions(-) diff --git a/benchmarks.py b/benchmarks.py index fc3073965ab3..24549dacc388 100644 --- a/benchmarks.py +++ b/benchmarks.py @@ -32,6 +32,10 @@ from pathlib import Path import pandas as pd +from ulralytics.yolo.utils.checks import check_yaml, print_args +from ultraltics.yolo.utils import LOGGER, file_size +from ultralytics.yolo.utils.torch_utils import select_device +from ultralytics.nn.tasks import attempt_load_weights FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -40,15 +44,13 @@ # ROOT = ROOT.relative_to(Path.cwd()) # relative import export -from models.experimental import attempt_load from models.yolo import SegmentationModel from segment.val import run as val_seg from utils import notebook_init -from utils.general import LOGGER, check_yaml, file_size, print_args -from utils.torch_utils import select_device from val import run as val_det + def run( weights=ROOT / 'yolov5s.pt', # weights path imgsz=640, # inference size (pixels) @@ -62,7 +64,7 @@ def run( ): y, t = [], time.time() device = select_device(device) - model_type = type(attempt_load(weights, fuse=False)) # DetectionModel, SegmentationModel, etc. + model_type = type(attempt_load_weights(weights, fuse=False)) # DetectionModel, SegmentationModel, etc. for i, (name, f, suffix, cpu, gpu) in export.export_formats().iterrows(): # index, (name, file, suffix, CPU, GPU) try: assert i not in (9, 10), 'inference not supported' # Edge TPU and TF.js are unsupported diff --git a/classify/train.py b/classify/train.py index ecbea1d8c0de..4957f13ca46e 100644 --- a/classify/train.py +++ b/classify/train.py @@ -29,6 +29,7 @@ import torchvision from torch.cuda import amp from tqdm import tqdm +from ultralytics.nn.tasks import attempt_load_weights FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -37,7 +38,6 @@ ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative from classify import val as validate -from models.experimental import attempt_load from models.yolo import ClassificationModel, DetectionModel from utils.dataloaders import create_classification_dataloader from utils.general import (DATASETS_DIR, LOGGER, TQDM_BAR_FORMAT, WorkingDirectory, check_git_info, check_git_status, @@ -108,7 +108,7 @@ def train(opt, device): # Model with torch_distributed_zero_first(LOCAL_RANK), WorkingDirectory(ROOT): if Path(opt.model).is_file() or opt.model.endswith('.pt'): - model = attempt_load(opt.model, device='cpu', fuse=False) + model = attempt_load_weights(opt.model, device='cpu', fuse=False) elif opt.model in torchvision.models.__dict__: # TorchVision models i.e. resnet50, efficientnet_b0 model = torchvision.models.__dict__[opt.model](weights='IMAGENET1K_V1' if pretrained else None) else: diff --git a/export.py b/export.py index 5f8e1c4821da..06cb308a3201 100644 --- a/export.py +++ b/export.py @@ -59,6 +59,7 @@ import pandas as pd import torch from torch.utils.mobile_optimizer import optimize_for_mobile +from ultralytics.nn.tasks import attempt_load_weights FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -67,7 +68,7 @@ if platform.system() != 'Windows': ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative -from models.experimental import attempt_load + from models.yolo import ClassificationModel, Detect, DetectionModel, SegmentationModel from utils.dataloaders import LoadImages from utils.general import (LOGGER, Profile, check_dataset, check_img_size, check_requirements, check_version, @@ -688,7 +689,7 @@ def run( if half: assert device.type != 'cpu' or coreml, '--half only compatible with GPU export, i.e. use --device 0' assert not dynamic, '--half not compatible with --dynamic, i.e. use either --half or --dynamic but not both' - model = attempt_load(weights, device=device, inplace=True, fuse=True) # load FP32 model + model = attempt_load_weights(weights, device=device, inplace=True, fuse=True) # load FP32 model # Checks imgsz *= 2 if len(imgsz) == 1 else 1 # expand diff --git a/hubconf.py b/hubconf.py index f0192698fbe3..ecaa5041475d 100644 --- a/hubconf.py +++ b/hubconf.py @@ -30,8 +30,8 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo """ from pathlib import Path + from ultralytics.nn.tasks import attempt_load_weights from models.common import AutoShape, DetectMultiBackend - from models.experimental import attempt_load from models.yolo import ClassificationModel, DetectionModel, SegmentationModel from utils.downloads import attempt_download from utils.general import LOGGER, ROOT, check_requirements, intersect_dicts, logging @@ -57,7 +57,7 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo else: model = AutoShape(model) # for file/URI/PIL/cv2/np inputs and NMS except Exception: - model = attempt_load(path, device=device, fuse=False) # arbitrary model + model = attempt_load_weights(path, device=device, fuse=False) # arbitrary model else: cfg = list((Path(__file__).parent / 'models').rglob(f'{path.stem}.yaml'))[0] # model.yaml path model = DetectionModel(cfg, channels, classes) # create model diff --git a/models/common.py b/models/common.py index 16537703e730..ada8105f6e76 100644 --- a/models/common.py +++ b/models/common.py @@ -23,6 +23,7 @@ import torch.nn as nn from PIL import Image from torch.cuda import amp +from ultralytics.nn.tasks import attempt_load_weights from utils import TryExcept from utils.dataloaders import exif_transpose, letterbox @@ -328,7 +329,7 @@ def __init__(self, weights='yolov5s.pt', device=torch.device('cpu'), dnn=False, # TensorFlow Lite: *.tflite # TensorFlow Edge TPU: *_edgetpu.tflite # PaddlePaddle: *_paddle_model - from models.experimental import attempt_download, attempt_load # scoped to avoid circular import + from models.experimental import attempt_download # scoped to avoid circular import super().__init__() w = str(weights[0] if isinstance(weights, list) else weights) @@ -341,7 +342,7 @@ def __init__(self, weights='yolov5s.pt', device=torch.device('cpu'), dnn=False, w = attempt_download(w) # download if not local if pt: # PyTorch - model = attempt_load(weights if isinstance(weights, list) else w, device=device, inplace=True, fuse=fuse) + model = attempt_load_weights(weights if isinstance(weights, list) else w, device=device, inplace=True, fuse=fuse) stride = max(int(model.stride.max()), 32) # model stride names = model.module.names if hasattr(model, 'module') else model.names # get class names model.half() if fp16 else model.float() diff --git a/models/experimental.py b/models/experimental.py index d60d1808da11..43d104419588 100644 --- a/models/experimental.py +++ b/models/experimental.py @@ -67,45 +67,4 @@ def forward(self, x, augment=False, profile=False, visualize=False): # y = torch.stack(y).max(0)[0] # max ensemble # y = torch.stack(y).mean(0) # mean ensemble y = torch.cat(y, 1) # nms ensemble - return y, None # inference, train output - - -def attempt_load(weights, device=None, inplace=True, fuse=True): - # Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a - from models.yolo import Detect, Model - - model = Ensemble() - for w in weights if isinstance(weights, list) else [weights]: - ckpt = torch.load(attempt_download(w), map_location='cpu') # load - ckpt = (ckpt.get('ema') or ckpt['model']).to(device).float() # FP32 model - - # Model compatibility updates - if not hasattr(ckpt, 'stride'): - ckpt.stride = torch.tensor([32.]) - if hasattr(ckpt, 'names') and isinstance(ckpt.names, (list, tuple)): - ckpt.names = dict(enumerate(ckpt.names)) # convert to dict - - model.append(ckpt.fuse().eval() if fuse and hasattr(ckpt, 'fuse') else ckpt.eval()) # model in eval mode - - # Module compatibility updates - for m in model.modules(): - t = type(m) - if t in (nn.Hardswish, nn.LeakyReLU, nn.ReLU, nn.ReLU6, nn.SiLU, Detect, Model): - m.inplace = inplace # torch 1.7.0 compatibility - if t is Detect and not isinstance(m.anchor_grid, list): - delattr(m, 'anchor_grid') - setattr(m, 'anchor_grid', [torch.zeros(1)] * m.nl) - elif t is nn.Upsample and not hasattr(m, 'recompute_scale_factor'): - m.recompute_scale_factor = None # torch 1.11.0 compatibility - - # Return model - if len(model) == 1: - return model[-1] - - # Return detection ensemble - print(f'Ensemble created with {weights}\n') - for k in 'names', 'nc', 'yaml': - setattr(model, k, getattr(model[0], k)) - model.stride = model[torch.argmax(torch.tensor([m.stride.max() for m in model])).int()].stride # max stride - assert all(model[0].nc == m.nc for m in model), f'Models have different class counts: {[m.nc for m in model]}' - return model + return y, None # inference, train output \ No newline at end of file diff --git a/models/tf.py b/models/tf.py index bc0a465d7edd..9ea98e08f882 100644 --- a/models/tf.py +++ b/models/tf.py @@ -26,10 +26,12 @@ import torch import torch.nn as nn from tensorflow import keras +from ultralytics.nn.tasks import attempt_load_weights + from models.common import (C3, SPP, SPPF, Bottleneck, BottleneckCSP, C3x, Concat, Conv, CrossConv, DWConv, DWConvTranspose2d, Focus, autopad) -from models.experimental import MixConv2d, attempt_load +from models.experimental import MixConv2d from models.yolo import Detect, Segment from utils.activations import SiLU from utils.general import LOGGER, make_divisible, print_args @@ -570,7 +572,7 @@ def run( ): # PyTorch model im = torch.zeros((batch_size, 3, *imgsz)) # BCHW image - model = attempt_load(weights, device=torch.device('cpu'), inplace=True, fuse=False) + model = attempt_load_weights(weights, device=torch.device('cpu'), inplace=True, fuse=False) _ = model(im) # inference model.info() diff --git a/segment/train.py b/segment/train.py index 5f1fa4a1e453..cc21385dbde3 100644 --- a/segment/train.py +++ b/segment/train.py @@ -33,6 +33,7 @@ import yaml from torch.optim import lr_scheduler from tqdm import tqdm +from ultralytics.nn.tasks import attempt_load_weights FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -41,7 +42,6 @@ ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative import segment.val as validate # for end-of-epoch mAP -from models.experimental import attempt_load from models.yolo import SegmentationModel from utils.autoanchor import check_anchors from utils.autobatch import check_train_batch_size @@ -429,7 +429,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio data_dict, batch_size=batch_size // WORLD_SIZE * 2, imgsz=imgsz, - model=attempt_load(f, device).half(), + model=attempt_load_weights(f, device).half(), iou_thres=0.65 if is_coco else 0.60, # best pycocotools at iou 0.65 single_cls=single_cls, dataloader=val_loader, diff --git a/train.py b/train.py index 48eeb09468fe..19052e7fa02c 100644 --- a/train.py +++ b/train.py @@ -33,6 +33,7 @@ import yaml from torch.optim import lr_scheduler from tqdm import tqdm +from ultralytics.nn.tasks import attempt_load_weights FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -41,7 +42,6 @@ ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative import val as validate # for end-of-epoch mAP -from models.experimental import attempt_load from models.yolo import Model from utils.autoanchor import check_anchors from utils.autobatch import check_train_batch_size @@ -415,7 +415,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio data_dict, batch_size=batch_size // WORLD_SIZE * 2, imgsz=imgsz, - model=attempt_load(f, device).half(), + model=attempt_load_weights(f, device).half(), iou_thres=0.65 if is_coco else 0.60, # best pycocotools at iou 0.65 single_cls=single_cls, dataloader=val_loader, diff --git a/utils/general.py b/utils/general.py index e95b07486619..01922b73df25 100644 --- a/utils/general.py +++ b/utils/general.py @@ -230,21 +230,6 @@ def methods(instance): return [f for f in dir(instance) if callable(getattr(instance, f)) and not f.startswith('__')] -def print_args(args: Optional[dict] = None, show_file=True, show_func=False): - # Print function arguments (optional args dict) - x = inspect.currentframe().f_back # previous frame - file, _, func, _, _ = inspect.getframeinfo(x) - if args is None: # get args automatically - args, _, _, frm = inspect.getargvalues(x) - args = {k: v for k, v in frm.items() if k in args} - try: - file = Path(file).resolve().relative_to(ROOT).with_suffix('') - except ValueError: - file = Path(file).stem - s = (f'{file}: ' if show_file else '') + (f'{func}: ' if show_func else '') - LOGGER.info(colorstr(s) + ', '.join(f'{k}={v}' for k, v in args.items())) - - def init_seeds(seed=0, deterministic=False): # Initialize random number generator (RNG) seeds https://pytorch.org/docs/stable/notes/randomness.html random.seed(seed) @@ -289,18 +274,6 @@ def file_date(path=__file__): return f'{t.year}-{t.month}-{t.day}' -def file_size(path): - # Return file/dir size (MB) - mb = 1 << 20 # bytes to MiB (1024 ** 2) - path = Path(path) - if path.is_file(): - return path.stat().st_size / mb - elif path.is_dir(): - return sum(f.stat().st_size for f in path.glob('**/*') if f.is_file()) / mb - else: - return 0.0 - - def check_online(): # Check internet connectivity import socket @@ -427,11 +400,6 @@ def check_suffix(file='yolov5s.pt', suffix=('.pt',), msg=''): assert s in suffix, f'{msg}{f} acceptable suffix is {suffix}' -def check_yaml(file, suffix=('.yaml', '.yml')): - # Search/download YAML file (if necessary) and return path, checking suffix - return check_file(file, suffix) - - def check_file(file, suffix=''): # Search/download file (if necessary) and return path check_suffix(file, suffix) # optional diff --git a/utils/torch_utils.py b/utils/torch_utils.py index d9e060ab99df..ad2d0a02c41b 100644 --- a/utils/torch_utils.py +++ b/utils/torch_utils.py @@ -105,42 +105,6 @@ def device_count(): return 0 -def select_device(device='', batch_size=0, newline=True): - # device = None or 'cpu' or 0 or '0' or '0,1,2,3' - s = f'YOLOv5 🚀 {git_describe() or file_date()} Python-{platform.python_version()} torch-{torch.__version__} ' - device = str(device).strip().lower().replace('cuda:', '').replace('none', '') # to string, 'cuda:0' to '0' - cpu = device == 'cpu' - mps = device == 'mps' # Apple Metal Performance Shaders (MPS) - if cpu or mps: - os.environ['CUDA_VISIBLE_DEVICES'] = '-1' # force torch.cuda.is_available() = False - elif device: # non-cpu device requested - os.environ['CUDA_VISIBLE_DEVICES'] = device # set environment variable - must be before assert is_available() - assert torch.cuda.is_available() and torch.cuda.device_count() >= len(device.replace(',', '')), \ - f"Invalid CUDA '--device {device}' requested, use '--device cpu' or pass valid CUDA device(s)" - - if not cpu and not mps and torch.cuda.is_available(): # prefer GPU if available - devices = device.split(',') if device else '0' # range(torch.cuda.device_count()) # i.e. 0,1,6,7 - n = len(devices) # device count - if n > 1 and batch_size > 0: # check batch_size is divisible by device_count - assert batch_size % n == 0, f'batch-size {batch_size} not multiple of GPU count {n}' - space = ' ' * (len(s) + 1) - for i, d in enumerate(devices): - p = torch.cuda.get_device_properties(i) - s += f"{'' if i == 0 else space}CUDA:{d} ({p.name}, {p.total_memory / (1 << 20):.0f}MiB)\n" # bytes to MB - arg = 'cuda:0' - elif mps and getattr(torch, 'has_mps', False) and torch.backends.mps.is_available(): # prefer MPS if available - s += 'MPS\n' - arg = 'mps' - else: # revert to CPU - s += 'CPU\n' - arg = 'cpu' - - if not newline: - s = s.rstrip() - LOGGER.info(s) - return torch.device(arg) - - def time_sync(): # PyTorch-accurate time if torch.cuda.is_available(): From 8ee268e7b6342ab25db016dec3236a8b8d60352d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 29 May 2023 09:59:06 +0000 Subject: [PATCH 02/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- benchmarks.py | 3 +-- export.py | 1 - hubconf.py | 1 + models/common.py | 5 ++++- models/experimental.py | 2 +- models/tf.py | 1 - 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/benchmarks.py b/benchmarks.py index 24549dacc388..218ed0f35d5a 100644 --- a/benchmarks.py +++ b/benchmarks.py @@ -34,8 +34,8 @@ import pandas as pd from ulralytics.yolo.utils.checks import check_yaml, print_args from ultraltics.yolo.utils import LOGGER, file_size -from ultralytics.yolo.utils.torch_utils import select_device from ultralytics.nn.tasks import attempt_load_weights +from ultralytics.yolo.utils.torch_utils import select_device FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -50,7 +50,6 @@ from val import run as val_det - def run( weights=ROOT / 'yolov5s.pt', # weights path imgsz=640, # inference size (pixels) diff --git a/export.py b/export.py index 06cb308a3201..f9d809520c1f 100644 --- a/export.py +++ b/export.py @@ -68,7 +68,6 @@ if platform.system() != 'Windows': ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative - from models.yolo import ClassificationModel, Detect, DetectionModel, SegmentationModel from utils.dataloaders import LoadImages from utils.general import (LOGGER, Profile, check_dataset, check_img_size, check_requirements, check_version, diff --git a/hubconf.py b/hubconf.py index ecaa5041475d..9f70381d1073 100644 --- a/hubconf.py +++ b/hubconf.py @@ -31,6 +31,7 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo from pathlib import Path from ultralytics.nn.tasks import attempt_load_weights + from models.common import AutoShape, DetectMultiBackend from models.yolo import ClassificationModel, DetectionModel, SegmentationModel from utils.downloads import attempt_download diff --git a/models/common.py b/models/common.py index ada8105f6e76..9ad210821f46 100644 --- a/models/common.py +++ b/models/common.py @@ -342,7 +342,10 @@ def __init__(self, weights='yolov5s.pt', device=torch.device('cpu'), dnn=False, w = attempt_download(w) # download if not local if pt: # PyTorch - model = attempt_load_weights(weights if isinstance(weights, list) else w, device=device, inplace=True, fuse=fuse) + model = attempt_load_weights(weights if isinstance(weights, list) else w, + device=device, + inplace=True, + fuse=fuse) stride = max(int(model.stride.max()), 32) # model stride names = model.module.names if hasattr(model, 'module') else model.names # get class names model.half() if fp16 else model.float() diff --git a/models/experimental.py b/models/experimental.py index 43d104419588..f8cca243cd56 100644 --- a/models/experimental.py +++ b/models/experimental.py @@ -67,4 +67,4 @@ def forward(self, x, augment=False, profile=False, visualize=False): # y = torch.stack(y).max(0)[0] # max ensemble # y = torch.stack(y).mean(0) # mean ensemble y = torch.cat(y, 1) # nms ensemble - return y, None # inference, train output \ No newline at end of file + return y, None # inference, train output diff --git a/models/tf.py b/models/tf.py index 9ea98e08f882..f39f7c2fd399 100644 --- a/models/tf.py +++ b/models/tf.py @@ -28,7 +28,6 @@ from tensorflow import keras from ultralytics.nn.tasks import attempt_load_weights - from models.common import (C3, SPP, SPPF, Bottleneck, BottleneckCSP, C3x, Concat, Conv, CrossConv, DWConv, DWConvTranspose2d, Focus, autopad) from models.experimental import MixConv2d From 3e8191f7b30ba5abaec97be096187359a53e7b72 Mon Sep 17 00:00:00 2001 From: Ayush Chaurasia Date: Mon, 29 May 2023 15:39:56 +0530 Subject: [PATCH 03/15] update --- classify/predict.py | 2 +- classify/train.py | 4 ++-- classify/val.py | 2 +- detect.py | 2 +- export.py | 2 +- hubconf.py | 2 +- segment/predict.py | 2 +- train.py | 4 ++-- utils/__init__.py | 5 ++--- utils/loggers/comet/hpo.py | 2 +- utils/torch_utils.py | 3 ++- val.py | 2 +- 12 files changed, 16 insertions(+), 16 deletions(-) diff --git a/classify/predict.py b/classify/predict.py index 9b64810d4d63..905ef77e6b5c 100644 --- a/classify/predict.py +++ b/classify/predict.py @@ -36,6 +36,7 @@ import torch import torch.nn.functional as F +from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -49,7 +50,6 @@ from utils.general import (LOGGER, Profile, check_file, check_img_size, check_imshow, check_requirements, colorstr, cv2, increment_path, print_args, strip_optimizer) from utils.plots import Annotator -from utils.torch_utils import select_device, smart_inference_mode @smart_inference_mode() diff --git a/classify/train.py b/classify/train.py index 4957f13ca46e..fd4fdce299b8 100644 --- a/classify/train.py +++ b/classify/train.py @@ -30,6 +30,7 @@ from torch.cuda import amp from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights +from ultralytics.yolo.utils.torch_utils import select_device, ModelEMA, de_parallel, model_info, torch_distributed_zero_first FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -44,8 +45,7 @@ check_requirements, colorstr, download, increment_path, init_seeds, print_args, yaml_save) from utils.loggers import GenericLogger from utils.plots import imshow_cls -from utils.torch_utils import (ModelEMA, de_parallel, model_info, reshape_classifier_output, select_device, smart_DDP, - smart_optimizer, smartCrossEntropyLoss, torch_distributed_zero_first) +from utils.torch_utils import reshape_classifier_output, smart_DDP, smart_optimizer, smartCrossEntropyLoss LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html RANK = int(os.getenv('RANK', -1)) diff --git a/classify/val.py b/classify/val.py index 4b92e9f105db..328f29d3133b 100644 --- a/classify/val.py +++ b/classify/val.py @@ -27,6 +27,7 @@ import torch from tqdm import tqdm +from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -38,7 +39,6 @@ from utils.dataloaders import create_classification_dataloader from utils.general import (LOGGER, TQDM_BAR_FORMAT, Profile, check_img_size, check_requirements, colorstr, increment_path, print_args) -from utils.torch_utils import select_device, smart_inference_mode @smart_inference_mode() diff --git a/detect.py b/detect.py index 216c9dbd5880..573498fabdc9 100644 --- a/detect.py +++ b/detect.py @@ -35,6 +35,7 @@ from pathlib import Path import torch +from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -47,7 +48,6 @@ from utils.general import (LOGGER, Profile, check_file, check_img_size, check_imshow, check_requirements, colorstr, cv2, increment_path, non_max_suppression, print_args, scale_boxes, strip_optimizer, xyxy2xywh) from utils.plots import Annotator, colors, save_one_box -from utils.torch_utils import select_device, smart_inference_mode @smart_inference_mode() diff --git a/export.py b/export.py index 06cb308a3201..9a129bc68a0a 100644 --- a/export.py +++ b/export.py @@ -60,6 +60,7 @@ import torch from torch.utils.mobile_optimizer import optimize_for_mobile from ultralytics.nn.tasks import attempt_load_weights +from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -73,7 +74,6 @@ from utils.dataloaders import LoadImages from utils.general import (LOGGER, Profile, check_dataset, check_img_size, check_requirements, check_version, check_yaml, colorstr, file_size, get_default_args, print_args, url2file, yaml_save) -from utils.torch_utils import select_device, smart_inference_mode MACOS = platform.system() == 'Darwin' # macOS environment diff --git a/hubconf.py b/hubconf.py index ecaa5041475d..294e6f2fb109 100644 --- a/hubconf.py +++ b/hubconf.py @@ -31,11 +31,11 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo from pathlib import Path from ultralytics.nn.tasks import attempt_load_weights + from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode from models.common import AutoShape, DetectMultiBackend from models.yolo import ClassificationModel, DetectionModel, SegmentationModel from utils.downloads import attempt_download from utils.general import LOGGER, ROOT, check_requirements, intersect_dicts, logging - from utils.torch_utils import select_device if not verbose: LOGGER.setLevel(logging.WARNING) diff --git a/segment/predict.py b/segment/predict.py index 6a4d5eff3fc1..d3f50b6b6f1d 100644 --- a/segment/predict.py +++ b/segment/predict.py @@ -35,6 +35,7 @@ from pathlib import Path import torch +from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -49,7 +50,6 @@ strip_optimizer) from utils.plots import Annotator, colors, save_one_box from utils.segment.general import masks2segments, process_mask, process_mask_native -from utils.torch_utils import select_device, smart_inference_mode @smart_inference_mode() diff --git a/train.py b/train.py index 19052e7fa02c..ec07f5b93871 100644 --- a/train.py +++ b/train.py @@ -34,6 +34,7 @@ from torch.optim import lr_scheduler from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights +from ultralytics.yolo.utils.torch_utils import select_device, EarlyStopping, ModelEMA, torch_distributed_zero_first FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -58,8 +59,7 @@ from utils.loss import ComputeLoss from utils.metrics import fitness from utils.plots import plot_evolve -from utils.torch_utils import (EarlyStopping, ModelEMA, de_parallel, select_device, smart_DDP, smart_optimizer, - smart_resume, torch_distributed_zero_first) +from utils.torch_utils import smart_optimizer, smart_resume LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html RANK = int(os.getenv('RANK', -1)) diff --git a/utils/__init__.py b/utils/__init__.py index 6c10857df079..804f187b7d09 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -6,6 +6,8 @@ import contextlib import platform import threading +from ultralytics.yolo.utils.torch_utils import select_device # imports +from ultralytics.yolo.utils.checks import check_font, is_colab def emojis(str=''): @@ -54,9 +56,6 @@ def notebook_init(verbose=True): import os import shutil - from utils.general import check_font, check_requirements, is_colab - from utils.torch_utils import select_device # imports - check_font() import psutil diff --git a/utils/loggers/comet/hpo.py b/utils/loggers/comet/hpo.py index fc49115c1358..63cf920199d3 100644 --- a/utils/loggers/comet/hpo.py +++ b/utils/loggers/comet/hpo.py @@ -6,6 +6,7 @@ from pathlib import Path import comet_ml +from ultralytics.yolo.utils.torch_utils import select_device logger = logging.getLogger(__name__) @@ -17,7 +18,6 @@ from train import train from utils.callbacks import Callbacks from utils.general import increment_path -from utils.torch_utils import select_device # Project Configuration config = comet_ml.config.get_config() diff --git a/utils/torch_utils.py b/utils/torch_utils.py index ad2d0a02c41b..c2104db0ccb3 100644 --- a/utils/torch_utils.py +++ b/utils/torch_utils.py @@ -12,6 +12,8 @@ from contextlib import contextmanager from copy import deepcopy from pathlib import Path +from ultralytics.yolo.utils import LOGGER, check_version, colorstr +from ultralytics.yolo.utils.torch_utils import select_device import torch import torch.distributed as dist @@ -19,7 +21,6 @@ import torch.nn.functional as F from torch.nn.parallel import DistributedDataParallel as DDP -from utils.general import LOGGER, check_version, colorstr, file_date, git_describe LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html RANK = int(os.getenv('RANK', -1)) diff --git a/val.py b/val.py index 71268651d29b..a4614eb59ef7 100644 --- a/val.py +++ b/val.py @@ -29,6 +29,7 @@ import numpy as np import torch from tqdm import tqdm +from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -44,7 +45,6 @@ print_args, scale_boxes, xywh2xyxy, xyxy2xywh) from utils.metrics import ConfusionMatrix, ap_per_class, box_iou from utils.plots import output_to_target, plot_images, plot_val_study -from utils.torch_utils import select_device, smart_inference_mode def save_one_txt(predn, save_conf, shape, file): From 9171b2d8c9d1a684a4ee21678ee95aa20a96138f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 29 May 2023 10:10:50 +0000 Subject: [PATCH 04/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- classify/train.py | 3 ++- hubconf.py | 1 + train.py | 4 ++-- utils/__init__.py | 3 ++- utils/torch_utils.py | 5 ++--- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/classify/train.py b/classify/train.py index fd4fdce299b8..39fe13ddb5ee 100644 --- a/classify/train.py +++ b/classify/train.py @@ -30,7 +30,8 @@ from torch.cuda import amp from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights -from ultralytics.yolo.utils.torch_utils import select_device, ModelEMA, de_parallel, model_info, torch_distributed_zero_first +from ultralytics.yolo.utils.torch_utils import (ModelEMA, de_parallel, model_info, select_device, + torch_distributed_zero_first) FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory diff --git a/hubconf.py b/hubconf.py index 294e6f2fb109..36573104b003 100644 --- a/hubconf.py +++ b/hubconf.py @@ -32,6 +32,7 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo from ultralytics.nn.tasks import attempt_load_weights from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode + from models.common import AutoShape, DetectMultiBackend from models.yolo import ClassificationModel, DetectionModel, SegmentationModel from utils.downloads import attempt_download diff --git a/train.py b/train.py index ec07f5b93871..08d475935d22 100644 --- a/train.py +++ b/train.py @@ -34,7 +34,7 @@ from torch.optim import lr_scheduler from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights -from ultralytics.yolo.utils.torch_utils import select_device, EarlyStopping, ModelEMA, torch_distributed_zero_first +from ultralytics.yolo.utils.torch_utils import EarlyStopping, ModelEMA, select_device, torch_distributed_zero_first FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -59,7 +59,7 @@ from utils.loss import ComputeLoss from utils.metrics import fitness from utils.plots import plot_evolve -from utils.torch_utils import smart_optimizer, smart_resume +from utils.torch_utils import smart_optimizer, smart_resume LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html RANK = int(os.getenv('RANK', -1)) diff --git a/utils/__init__.py b/utils/__init__.py index 804f187b7d09..d53e87710716 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -6,8 +6,9 @@ import contextlib import platform import threading + +from ultralytics.yolo.utils.checks import check_font, is_colab from ultralytics.yolo.utils.torch_utils import select_device # imports -from ultralytics.yolo.utils.checks import check_font, is_colab def emojis(str=''): diff --git a/utils/torch_utils.py b/utils/torch_utils.py index c2104db0ccb3..687af660362d 100644 --- a/utils/torch_utils.py +++ b/utils/torch_utils.py @@ -12,15 +12,14 @@ from contextlib import contextmanager from copy import deepcopy from pathlib import Path -from ultralytics.yolo.utils import LOGGER, check_version, colorstr -from ultralytics.yolo.utils.torch_utils import select_device import torch import torch.distributed as dist import torch.nn as nn import torch.nn.functional as F from torch.nn.parallel import DistributedDataParallel as DDP - +from ultralytics.yolo.utils import LOGGER, check_version, colorstr +from ultralytics.yolo.utils.torch_utils import select_device LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html RANK = int(os.getenv('RANK', -1)) From e979c12c79ac3ee238b4149a5292ac88a398f303 Mon Sep 17 00:00:00 2001 From: Ayush Chaurasia Date: Mon, 29 May 2023 15:53:54 +0530 Subject: [PATCH 05/15] update --- classify/train.py | 2 +- classify/val.py | 2 +- models/yolo.py | 7 ++++--- segment/train.py | 2 +- segment/val.py | 2 +- train.py | 12 ++++++------ utils/dataloaders.py | 4 ++-- utils/loggers/comet/hpo.py | 2 +- utils/torch_utils.py | 3 ++- val.py | 7 +++---- 10 files changed, 22 insertions(+), 21 deletions(-) diff --git a/classify/train.py b/classify/train.py index fd4fdce299b8..0bab242b53d5 100644 --- a/classify/train.py +++ b/classify/train.py @@ -303,7 +303,7 @@ def main(opt): check_requirements(ROOT / 'requirements.txt') # DDP mode - device = select_device(opt.device, batch_size=opt.batch_size) + device = select_device(opt.device, batch=opt.batch_size) if LOCAL_RANK != -1: assert opt.batch_size != -1, 'AutoBatch is coming soon for classification, please pass a valid --batch-size' assert opt.batch_size % WORLD_SIZE == 0, f'--batch-size {opt.batch_size} must be multiple of WORLD_SIZE' diff --git a/classify/val.py b/classify/val.py index 328f29d3133b..24039b9780d2 100644 --- a/classify/val.py +++ b/classify/val.py @@ -67,7 +67,7 @@ def run( half &= device.type != 'cpu' # half precision only supported on CUDA model.half() if half else model.float() else: # called directly - device = select_device(device, batch_size=batch_size) + device = select_device(device, batch=batch_size) # Directories save_dir = increment_path(Path(project) / name, exist_ok=exist_ok) # increment run diff --git a/models/yolo.py b/models/yolo.py index 18d2542bfb48..39a01e88684d 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -13,6 +13,8 @@ import sys from copy import deepcopy from pathlib import Path +from ultralytics.yolo.utils.checks import check_yaml, print_args +from ultralytics.yolo.utils.torch_utils import select_device FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -24,10 +26,9 @@ from models.common import * from models.experimental import * from utils.autoanchor import check_anchor_order -from utils.general import LOGGER, check_version, check_yaml, make_divisible, print_args +from utils.general import LOGGER, check_version, make_divisible from utils.plots import feature_visualization -from utils.torch_utils import (fuse_conv_and_bn, initialize_weights, model_info, profile, scale_img, select_device, - time_sync) +from utils.torch_utils import fuse_conv_and_bn, initialize_weights, model_info, profile, scale_img, time_sync try: import thop # for FLOPs computation diff --git a/segment/train.py b/segment/train.py index cc21385dbde3..8303720a3296 100644 --- a/segment/train.py +++ b/segment/train.py @@ -540,7 +540,7 @@ def main(opt, callbacks=Callbacks()): opt.save_dir = str(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok)) # DDP mode - device = select_device(opt.device, batch_size=opt.batch_size) + device = select_device(opt.device, batch=opt.batch_size) if LOCAL_RANK != -1: msg = 'is not compatible with YOLOv5 Multi-GPU DDP training' assert not opt.image_weights, f'--image-weights {msg}' diff --git a/segment/val.py b/segment/val.py index dc8081840e37..6c90d13f35a1 100644 --- a/segment/val.py +++ b/segment/val.py @@ -173,7 +173,7 @@ def run( model.half() if half else model.float() nm = de_parallel(model).model[-1].nm # number of masks else: # called directly - device = select_device(device, batch_size=batch_size) + device = select_device(device, batch=batch_size) # Directories save_dir = increment_path(Path(project) / name, exist_ok=exist_ok) # increment run diff --git a/train.py b/train.py index ec07f5b93871..9ab2fc560d77 100644 --- a/train.py +++ b/train.py @@ -34,7 +34,8 @@ from torch.optim import lr_scheduler from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights -from ultralytics.yolo.utils.torch_utils import select_device, EarlyStopping, ModelEMA, torch_distributed_zero_first +from ultralytics.yolo.utils.torch_utils import select_device, EarlyStopping, ModelEMA, torch_distributed_zero_first, de_parallel +from ultralytics.yolo.utils.checks import check_file, check_requirements, check_suffix, check_yaml, check_requirements, print_args FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -49,17 +50,16 @@ from utils.callbacks import Callbacks from utils.dataloaders import create_dataloader from utils.downloads import attempt_download, is_url -from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_info, - check_git_status, check_img_size, check_requirements, check_suffix, check_yaml, colorstr, +from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, colorstr, check_dataset, check_img_size, check_git_status, check_git_info, get_latest_run, increment_path, init_seeds, intersect_dicts, labels_to_class_weights, - labels_to_image_weights, methods, one_cycle, print_args, print_mutation, strip_optimizer, + labels_to_image_weights, methods, one_cycle, print_mutation, strip_optimizer, yaml_save) from utils.loggers import Loggers from utils.loggers.comet.comet_utils import check_comet_resume from utils.loss import ComputeLoss from utils.metrics import fitness from utils.plots import plot_evolve -from utils.torch_utils import smart_optimizer, smart_resume +from utils.torch_utils import smart_optimizer, smart_resume, smart_DDP LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html RANK = int(os.getenv('RANK', -1)) @@ -514,7 +514,7 @@ def main(opt, callbacks=Callbacks()): opt.save_dir = str(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok)) # DDP mode - device = select_device(opt.device, batch_size=opt.batch_size) + device = select_device(opt.device, batch=opt.batch_size) if LOCAL_RANK != -1: msg = 'is not compatible with YOLOv5 Multi-GPU DDP training' assert not opt.image_weights, f'--image-weights {msg}' diff --git a/utils/dataloaders.py b/utils/dataloaders.py index 26201c3c78fc..4b20f7e2ced9 100644 --- a/utils/dataloaders.py +++ b/utils/dataloaders.py @@ -27,11 +27,11 @@ from PIL import ExifTags, Image, ImageOps from torch.utils.data import DataLoader, Dataset, dataloader, distributed from tqdm import tqdm +from ultralytics.yolo.utils.checks import check_yaml, check_requirements from utils.augmentations import (Albumentations, augment_hsv, classify_albumentations, classify_transforms, copy_paste, letterbox, mixup, random_perspective) -from utils.general import (DATASETS_DIR, LOGGER, NUM_THREADS, TQDM_BAR_FORMAT, check_dataset, check_requirements, - check_yaml, clean_str, cv2, is_colab, is_kaggle, segments2boxes, unzip_file, xyn2xy, +from utils.general import (DATASETS_DIR, LOGGER, NUM_THREADS, TQDM_BAR_FORMAT, check_dataset, clean_str, cv2, is_colab, is_kaggle, segments2boxes, unzip_file, xyn2xy, xywh2xyxy, xywhn2xyxy, xyxy2xywhn) from utils.torch_utils import torch_distributed_zero_first diff --git a/utils/loggers/comet/hpo.py b/utils/loggers/comet/hpo.py index 63cf920199d3..1d8e7d28f0ca 100644 --- a/utils/loggers/comet/hpo.py +++ b/utils/loggers/comet/hpo.py @@ -87,7 +87,7 @@ def run(parameters, opt): opt.batch_size = parameters.get('batch_size') opt.epochs = parameters.get('epochs') - device = select_device(opt.device, batch_size=opt.batch_size) + device = select_device(opt.device, batch=opt.batch_size) train(hyp_dict, opt, device, callbacks=Callbacks()) diff --git a/utils/torch_utils.py b/utils/torch_utils.py index c2104db0ccb3..22e9f5b2e3ff 100644 --- a/utils/torch_utils.py +++ b/utils/torch_utils.py @@ -12,8 +12,9 @@ from contextlib import contextmanager from copy import deepcopy from pathlib import Path -from ultralytics.yolo.utils import LOGGER, check_version, colorstr +from ultralytics.yolo.utils import LOGGER, colorstr from ultralytics.yolo.utils.torch_utils import select_device +from ultralytics.yolo.utils.checks import check_version import torch import torch.distributed as dist diff --git a/val.py b/val.py index a4614eb59ef7..51b0e8b4442b 100644 --- a/val.py +++ b/val.py @@ -30,6 +30,7 @@ import torch from tqdm import tqdm from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode +from ultralytics.yolo.utils.checks import check_requirements, check_yaml, print_args FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -40,9 +41,7 @@ from models.common import DetectMultiBackend from utils.callbacks import Callbacks from utils.dataloaders import create_dataloader -from utils.general import (LOGGER, TQDM_BAR_FORMAT, Profile, check_dataset, check_img_size, check_requirements, - check_yaml, coco80_to_coco91_class, colorstr, increment_path, non_max_suppression, - print_args, scale_boxes, xywh2xyxy, xyxy2xywh) +from utils.general import (LOGGER, TQDM_BAR_FORMAT, Profile, check_dataset, check_img_size, coco80_to_coco91_class, colorstr, increment_path, non_max_suppression, scale_boxes, xywh2xyxy, xyxy2xywh) from utils.metrics import ConfusionMatrix, ap_per_class, box_iou from utils.plots import output_to_target, plot_images, plot_val_study @@ -133,7 +132,7 @@ def run( half &= device.type != 'cpu' # half precision only supported on CUDA model.half() if half else model.float() else: # called directly - device = select_device(device, batch_size=batch_size) + device = select_device(device, batch=batch_size) # Directories save_dir = increment_path(Path(project) / name, exist_ok=exist_ok) # increment run From 28c8092c337f8d88a450f2d643164009303b366e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 29 May 2023 10:27:09 +0000 Subject: [PATCH 06/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- models/yolo.py | 1 + train.py | 15 ++++++++------- utils/dataloaders.py | 6 +++--- utils/torch_utils.py | 4 +--- val.py | 5 +++-- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/models/yolo.py b/models/yolo.py index 39a01e88684d..01aa096c2594 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -13,6 +13,7 @@ import sys from copy import deepcopy from pathlib import Path + from ultralytics.yolo.utils.checks import check_yaml, print_args from ultralytics.yolo.utils.torch_utils import select_device diff --git a/train.py b/train.py index 9ab2fc560d77..fcff9686f01d 100644 --- a/train.py +++ b/train.py @@ -34,8 +34,9 @@ from torch.optim import lr_scheduler from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights -from ultralytics.yolo.utils.torch_utils import select_device, EarlyStopping, ModelEMA, torch_distributed_zero_first, de_parallel -from ultralytics.yolo.utils.checks import check_file, check_requirements, check_suffix, check_yaml, check_requirements, print_args +from ultralytics.yolo.utils.checks import check_file, check_requirements, check_suffix, check_yaml, print_args +from ultralytics.yolo.utils.torch_utils import (EarlyStopping, ModelEMA, de_parallel, select_device, + torch_distributed_zero_first) FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -50,16 +51,16 @@ from utils.callbacks import Callbacks from utils.dataloaders import create_dataloader from utils.downloads import attempt_download, is_url -from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, colorstr, check_dataset, check_img_size, check_git_status, check_git_info, - get_latest_run, increment_path, init_seeds, intersect_dicts, labels_to_class_weights, - labels_to_image_weights, methods, one_cycle, print_mutation, strip_optimizer, - yaml_save) +from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_git_info, check_git_status, + check_img_size, colorstr, get_latest_run, increment_path, init_seeds, intersect_dicts, + labels_to_class_weights, labels_to_image_weights, methods, one_cycle, print_mutation, + strip_optimizer, yaml_save) from utils.loggers import Loggers from utils.loggers.comet.comet_utils import check_comet_resume from utils.loss import ComputeLoss from utils.metrics import fitness from utils.plots import plot_evolve -from utils.torch_utils import smart_optimizer, smart_resume, smart_DDP +from utils.torch_utils import smart_DDP, smart_optimizer, smart_resume LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html RANK = int(os.getenv('RANK', -1)) diff --git a/utils/dataloaders.py b/utils/dataloaders.py index 4b20f7e2ced9..867ad8bf27c4 100644 --- a/utils/dataloaders.py +++ b/utils/dataloaders.py @@ -27,12 +27,12 @@ from PIL import ExifTags, Image, ImageOps from torch.utils.data import DataLoader, Dataset, dataloader, distributed from tqdm import tqdm -from ultralytics.yolo.utils.checks import check_yaml, check_requirements +from ultralytics.yolo.utils.checks import check_requirements, check_yaml from utils.augmentations import (Albumentations, augment_hsv, classify_albumentations, classify_transforms, copy_paste, letterbox, mixup, random_perspective) -from utils.general import (DATASETS_DIR, LOGGER, NUM_THREADS, TQDM_BAR_FORMAT, check_dataset, clean_str, cv2, is_colab, is_kaggle, segments2boxes, unzip_file, xyn2xy, - xywh2xyxy, xywhn2xyxy, xyxy2xywhn) +from utils.general import (DATASETS_DIR, LOGGER, NUM_THREADS, TQDM_BAR_FORMAT, check_dataset, clean_str, cv2, is_colab, + is_kaggle, segments2boxes, unzip_file, xyn2xy, xywh2xyxy, xywhn2xyxy, xyxy2xywhn) from utils.torch_utils import torch_distributed_zero_first # Parameters diff --git a/utils/torch_utils.py b/utils/torch_utils.py index af4a0dc1fa13..ebd1c02cd765 100644 --- a/utils/torch_utils.py +++ b/utils/torch_utils.py @@ -12,9 +12,6 @@ from contextlib import contextmanager from copy import deepcopy from pathlib import Path -from ultralytics.yolo.utils import LOGGER, colorstr -from ultralytics.yolo.utils.torch_utils import select_device -from ultralytics.yolo.utils.checks import check_version import torch import torch.distributed as dist @@ -22,6 +19,7 @@ import torch.nn.functional as F from torch.nn.parallel import DistributedDataParallel as DDP from ultralytics.yolo.utils import LOGGER, check_version, colorstr +from ultralytics.yolo.utils.checks import check_version from ultralytics.yolo.utils.torch_utils import select_device LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html diff --git a/val.py b/val.py index 51b0e8b4442b..01dc10d8cd06 100644 --- a/val.py +++ b/val.py @@ -29,8 +29,8 @@ import numpy as np import torch from tqdm import tqdm -from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode from ultralytics.yolo.utils.checks import check_requirements, check_yaml, print_args +from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -41,7 +41,8 @@ from models.common import DetectMultiBackend from utils.callbacks import Callbacks from utils.dataloaders import create_dataloader -from utils.general import (LOGGER, TQDM_BAR_FORMAT, Profile, check_dataset, check_img_size, coco80_to_coco91_class, colorstr, increment_path, non_max_suppression, scale_boxes, xywh2xyxy, xyxy2xywh) +from utils.general import (LOGGER, TQDM_BAR_FORMAT, Profile, check_dataset, check_img_size, coco80_to_coco91_class, + colorstr, increment_path, non_max_suppression, scale_boxes, xywh2xyxy, xyxy2xywh) from utils.metrics import ConfusionMatrix, ap_per_class, box_iou from utils.plots import output_to_target, plot_images, plot_val_study From f21523f16676d9fe41d54fbb971fb4b85556324a Mon Sep 17 00:00:00 2001 From: Ayush Chaurasia Date: Mon, 29 May 2023 16:00:00 +0530 Subject: [PATCH 07/15] update --- utils/torch_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/torch_utils.py b/utils/torch_utils.py index ebd1c02cd765..2f82e76cb491 100644 --- a/utils/torch_utils.py +++ b/utils/torch_utils.py @@ -18,7 +18,7 @@ import torch.nn as nn import torch.nn.functional as F from torch.nn.parallel import DistributedDataParallel as DDP -from ultralytics.yolo.utils import LOGGER, check_version, colorstr +from ultralytics.yolo.utils import LOGGER, colorstr from ultralytics.yolo.utils.checks import check_version from ultralytics.yolo.utils.torch_utils import select_device From 901822712705e91757e6e71da958c112447a5597 Mon Sep 17 00:00:00 2001 From: Ayush Chaurasia Date: Mon, 29 May 2023 16:14:24 +0530 Subject: [PATCH 08/15] update --- classify/predict.py | 5 +++-- detect.py | 3 ++- models/yolo.py | 4 ++-- segment/predict.py | 5 +++-- segment/train.py | 6 +++--- segment/val.py | 5 +++-- train.py | 4 ++-- utils/dataloaders.py | 4 ++-- utils/general.py | 4 ++++ val.py | 4 ++-- 10 files changed, 26 insertions(+), 18 deletions(-) diff --git a/classify/predict.py b/classify/predict.py index 905ef77e6b5c..c141c72759e3 100644 --- a/classify/predict.py +++ b/classify/predict.py @@ -37,6 +37,7 @@ import torch import torch.nn.functional as F from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode +from ultralytics.yolo.utils.checks import print_args, check_requirements FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -47,8 +48,8 @@ from models.common import DetectMultiBackend from utils.augmentations import classify_transforms from utils.dataloaders import IMG_FORMATS, VID_FORMATS, LoadImages, LoadScreenshots, LoadStreams -from utils.general import (LOGGER, Profile, check_file, check_img_size, check_imshow, check_requirements, colorstr, cv2, - increment_path, print_args, strip_optimizer) +from utils.general import (LOGGER, Profile, check_file, check_img_size, check_imshow, colorstr, cv2, + increment_path, strip_optimizer) from utils.plots import Annotator diff --git a/detect.py b/detect.py index 573498fabdc9..4c2719a9ef59 100644 --- a/detect.py +++ b/detect.py @@ -36,6 +36,7 @@ import torch from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode +from ultralytics.yolo.utils.checks import print_args FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -46,7 +47,7 @@ from models.common import DetectMultiBackend from utils.dataloaders import IMG_FORMATS, VID_FORMATS, LoadImages, LoadScreenshots, LoadStreams from utils.general import (LOGGER, Profile, check_file, check_img_size, check_imshow, check_requirements, colorstr, cv2, - increment_path, non_max_suppression, print_args, scale_boxes, strip_optimizer, xyxy2xywh) + increment_path, non_max_suppression, scale_boxes, strip_optimizer, xyxy2xywh) from utils.plots import Annotator, colors, save_one_box diff --git a/models/yolo.py b/models/yolo.py index 01aa096c2594..936f97d5be67 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -14,7 +14,7 @@ from copy import deepcopy from pathlib import Path -from ultralytics.yolo.utils.checks import check_yaml, print_args +from ultralytics.yolo.utils.checks import print_args from ultralytics.yolo.utils.torch_utils import select_device FILE = Path(__file__).resolve() @@ -27,7 +27,7 @@ from models.common import * from models.experimental import * from utils.autoanchor import check_anchor_order -from utils.general import LOGGER, check_version, make_divisible +from utils.general import LOGGER, check_version, make_divisible, check_yaml from utils.plots import feature_visualization from utils.torch_utils import fuse_conv_and_bn, initialize_weights, model_info, profile, scale_img, time_sync diff --git a/segment/predict.py b/segment/predict.py index d3f50b6b6f1d..323489afd27c 100644 --- a/segment/predict.py +++ b/segment/predict.py @@ -36,6 +36,7 @@ import torch from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode +from ultrlalytics.yolo.utils.checks import check_reuirements, print_args FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -45,8 +46,8 @@ from models.common import DetectMultiBackend from utils.dataloaders import IMG_FORMATS, VID_FORMATS, LoadImages, LoadScreenshots, LoadStreams -from utils.general import (LOGGER, Profile, check_file, check_img_size, check_imshow, check_requirements, colorstr, cv2, - increment_path, non_max_suppression, print_args, scale_boxes, scale_segments, +from utils.general import (LOGGER, Profile, check_file, check_img_size, check_imshow, colorstr, cv2, + increment_path, non_max_suppression, scale_boxes, scale_segments, strip_optimizer) from utils.plots import Annotator, colors, save_one_box from utils.segment.general import masks2segments, process_mask, process_mask_native diff --git a/segment/train.py b/segment/train.py index 8303720a3296..59f92723988f 100644 --- a/segment/train.py +++ b/segment/train.py @@ -34,7 +34,7 @@ from torch.optim import lr_scheduler from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights - +from ultralytics.yolo.utils.checks import check_requirements FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory if str(ROOT) not in sys.path: @@ -48,9 +48,9 @@ from utils.callbacks import Callbacks from utils.downloads import attempt_download, is_url from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_info, - check_git_status, check_img_size, check_requirements, check_suffix, check_yaml, colorstr, + check_git_status, check_img_size, check_suffix, colorstr, get_latest_run, increment_path, init_seeds, intersect_dicts, labels_to_class_weights, - labels_to_image_weights, one_cycle, print_args, print_mutation, strip_optimizer, yaml_save) + labels_to_image_weights, one_cycle, print_mutation, strip_optimizer, yaml_save, check_yaml) from utils.loggers import GenericLogger from utils.plots import plot_evolve, plot_labels from utils.segment.dataloaders import create_dataloader diff --git a/segment/val.py b/segment/val.py index 6c90d13f35a1..f9e0b51b40b3 100644 --- a/segment/val.py +++ b/segment/val.py @@ -39,13 +39,14 @@ ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative import torch.nn.functional as F +from ultralytis.yolo.utils.checks import print_args, check_requirements from models.common import DetectMultiBackend from models.yolo import SegmentationModel from utils.callbacks import Callbacks from utils.general import (LOGGER, NUM_THREADS, TQDM_BAR_FORMAT, Profile, check_dataset, check_img_size, - check_requirements, check_yaml, coco80_to_coco91_class, colorstr, increment_path, - non_max_suppression, print_args, scale_boxes, xywh2xyxy, xyxy2xywh) + check_yaml, coco80_to_coco91_class, colorstr, increment_path, + non_max_suppression, scale_boxes, xywh2xyxy, xyxy2xywh) from utils.metrics import ConfusionMatrix, box_iou from utils.plots import output_to_target, plot_val_study from utils.segment.dataloaders import create_dataloader diff --git a/train.py b/train.py index fcff9686f01d..abc90fb8b44b 100644 --- a/train.py +++ b/train.py @@ -34,7 +34,7 @@ from torch.optim import lr_scheduler from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights -from ultralytics.yolo.utils.checks import check_file, check_requirements, check_suffix, check_yaml, print_args +from ultralytics.yolo.utils.checks import check_requirements, check_suffix, print_args from ultralytics.yolo.utils.torch_utils import (EarlyStopping, ModelEMA, de_parallel, select_device, torch_distributed_zero_first) @@ -54,7 +54,7 @@ from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_git_info, check_git_status, check_img_size, colorstr, get_latest_run, increment_path, init_seeds, intersect_dicts, labels_to_class_weights, labels_to_image_weights, methods, one_cycle, print_mutation, - strip_optimizer, yaml_save) + strip_optimizer, yaml_save, check_file, check_yaml) from utils.loggers import Loggers from utils.loggers.comet.comet_utils import check_comet_resume from utils.loss import ComputeLoss diff --git a/utils/dataloaders.py b/utils/dataloaders.py index 867ad8bf27c4..c8d843c979b4 100644 --- a/utils/dataloaders.py +++ b/utils/dataloaders.py @@ -27,11 +27,11 @@ from PIL import ExifTags, Image, ImageOps from torch.utils.data import DataLoader, Dataset, dataloader, distributed from tqdm import tqdm -from ultralytics.yolo.utils.checks import check_requirements, check_yaml +from ultralytics.yolo.utils.checks import check_requirements from utils.augmentations import (Albumentations, augment_hsv, classify_albumentations, classify_transforms, copy_paste, letterbox, mixup, random_perspective) -from utils.general import (DATASETS_DIR, LOGGER, NUM_THREADS, TQDM_BAR_FORMAT, check_dataset, clean_str, cv2, is_colab, +from utils.general import (DATASETS_DIR, LOGGER, NUM_THREADS, TQDM_BAR_FORMAT, check_yaml, check_dataset, clean_str, cv2, is_colab, is_kaggle, segments2boxes, unzip_file, xyn2xy, xywh2xyxy, xywhn2xyxy, xyxy2xywhn) from utils.torch_utils import torch_distributed_zero_first diff --git a/utils/general.py b/utils/general.py index 01922b73df25..9d853dcea05b 100644 --- a/utils/general.py +++ b/utils/general.py @@ -274,6 +274,10 @@ def file_date(path=__file__): return f'{t.year}-{t.month}-{t.day}' +def check_yaml(file, suffix=('.yaml', '.yml')): + # Search/download YAML file (if necessary) and return path, checking suffix + return check_file(file, suffix) + def check_online(): # Check internet connectivity import socket diff --git a/val.py b/val.py index 01dc10d8cd06..f1d334f438ef 100644 --- a/val.py +++ b/val.py @@ -29,7 +29,7 @@ import numpy as np import torch from tqdm import tqdm -from ultralytics.yolo.utils.checks import check_requirements, check_yaml, print_args +from ultralytics.yolo.utils.checks import check_requirements, print_args from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve() @@ -42,7 +42,7 @@ from utils.callbacks import Callbacks from utils.dataloaders import create_dataloader from utils.general import (LOGGER, TQDM_BAR_FORMAT, Profile, check_dataset, check_img_size, coco80_to_coco91_class, - colorstr, increment_path, non_max_suppression, scale_boxes, xywh2xyxy, xyxy2xywh) + colorstr, increment_path, non_max_suppression, scale_boxes, xywh2xyxy, xyxy2xywh, check_yaml) from utils.metrics import ConfusionMatrix, ap_per_class, box_iou from utils.plots import output_to_target, plot_images, plot_val_study From 8509d81d1238ec84c5166792f6386170a9d8dd72 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 29 May 2023 10:45:00 +0000 Subject: [PATCH 09/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- classify/predict.py | 6 +++--- detect.py | 2 +- models/yolo.py | 2 +- segment/predict.py | 5 ++--- segment/train.py | 7 ++++--- segment/val.py | 8 ++++---- train.py | 8 ++++---- utils/dataloaders.py | 5 +++-- utils/general.py | 1 + val.py | 5 +++-- 10 files changed, 26 insertions(+), 23 deletions(-) diff --git a/classify/predict.py b/classify/predict.py index c141c72759e3..a6e190d4e274 100644 --- a/classify/predict.py +++ b/classify/predict.py @@ -36,8 +36,8 @@ import torch import torch.nn.functional as F +from ultralytics.yolo.utils.checks import check_requirements, print_args from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode -from ultralytics.yolo.utils.checks import print_args, check_requirements FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -48,8 +48,8 @@ from models.common import DetectMultiBackend from utils.augmentations import classify_transforms from utils.dataloaders import IMG_FORMATS, VID_FORMATS, LoadImages, LoadScreenshots, LoadStreams -from utils.general import (LOGGER, Profile, check_file, check_img_size, check_imshow, colorstr, cv2, - increment_path, strip_optimizer) +from utils.general import (LOGGER, Profile, check_file, check_img_size, check_imshow, colorstr, cv2, increment_path, + strip_optimizer) from utils.plots import Annotator diff --git a/detect.py b/detect.py index 4c2719a9ef59..eec9f1e7103a 100644 --- a/detect.py +++ b/detect.py @@ -35,8 +35,8 @@ from pathlib import Path import torch -from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode from ultralytics.yolo.utils.checks import print_args +from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory diff --git a/models/yolo.py b/models/yolo.py index 936f97d5be67..034a289fcd06 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -27,7 +27,7 @@ from models.common import * from models.experimental import * from utils.autoanchor import check_anchor_order -from utils.general import LOGGER, check_version, make_divisible, check_yaml +from utils.general import LOGGER, check_version, check_yaml, make_divisible from utils.plots import feature_visualization from utils.torch_utils import fuse_conv_and_bn, initialize_weights, model_info, profile, scale_img, time_sync diff --git a/segment/predict.py b/segment/predict.py index 323489afd27c..03cb96cf3069 100644 --- a/segment/predict.py +++ b/segment/predict.py @@ -46,9 +46,8 @@ from models.common import DetectMultiBackend from utils.dataloaders import IMG_FORMATS, VID_FORMATS, LoadImages, LoadScreenshots, LoadStreams -from utils.general import (LOGGER, Profile, check_file, check_img_size, check_imshow, colorstr, cv2, - increment_path, non_max_suppression, scale_boxes, scale_segments, - strip_optimizer) +from utils.general import (LOGGER, Profile, check_file, check_img_size, check_imshow, colorstr, cv2, increment_path, + non_max_suppression, scale_boxes, scale_segments, strip_optimizer) from utils.plots import Annotator, colors, save_one_box from utils.segment.general import masks2segments, process_mask, process_mask_native diff --git a/segment/train.py b/segment/train.py index 59f92723988f..3b35d44abee0 100644 --- a/segment/train.py +++ b/segment/train.py @@ -35,6 +35,7 @@ from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights from ultralytics.yolo.utils.checks import check_requirements + FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory if str(ROOT) not in sys.path: @@ -48,9 +49,9 @@ from utils.callbacks import Callbacks from utils.downloads import attempt_download, is_url from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_info, - check_git_status, check_img_size, check_suffix, colorstr, - get_latest_run, increment_path, init_seeds, intersect_dicts, labels_to_class_weights, - labels_to_image_weights, one_cycle, print_mutation, strip_optimizer, yaml_save, check_yaml) + check_git_status, check_img_size, check_suffix, check_yaml, colorstr, get_latest_run, + increment_path, init_seeds, intersect_dicts, labels_to_class_weights, + labels_to_image_weights, one_cycle, print_mutation, strip_optimizer, yaml_save) from utils.loggers import GenericLogger from utils.plots import plot_evolve, plot_labels from utils.segment.dataloaders import create_dataloader diff --git a/segment/val.py b/segment/val.py index f9e0b51b40b3..0861100d88b0 100644 --- a/segment/val.py +++ b/segment/val.py @@ -39,14 +39,14 @@ ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative import torch.nn.functional as F -from ultralytis.yolo.utils.checks import print_args, check_requirements +from ultralytis.yolo.utils.checks import check_requirements, print_args from models.common import DetectMultiBackend from models.yolo import SegmentationModel from utils.callbacks import Callbacks -from utils.general import (LOGGER, NUM_THREADS, TQDM_BAR_FORMAT, Profile, check_dataset, check_img_size, - check_yaml, coco80_to_coco91_class, colorstr, increment_path, - non_max_suppression, scale_boxes, xywh2xyxy, xyxy2xywh) +from utils.general import (LOGGER, NUM_THREADS, TQDM_BAR_FORMAT, Profile, check_dataset, check_img_size, check_yaml, + coco80_to_coco91_class, colorstr, increment_path, non_max_suppression, scale_boxes, + xywh2xyxy, xyxy2xywh) from utils.metrics import ConfusionMatrix, box_iou from utils.plots import output_to_target, plot_val_study from utils.segment.dataloaders import create_dataloader diff --git a/train.py b/train.py index abc90fb8b44b..597d991a4d9e 100644 --- a/train.py +++ b/train.py @@ -51,10 +51,10 @@ from utils.callbacks import Callbacks from utils.dataloaders import create_dataloader from utils.downloads import attempt_download, is_url -from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_git_info, check_git_status, - check_img_size, colorstr, get_latest_run, increment_path, init_seeds, intersect_dicts, - labels_to_class_weights, labels_to_image_weights, methods, one_cycle, print_mutation, - strip_optimizer, yaml_save, check_file, check_yaml) +from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_info, + check_git_status, check_img_size, check_yaml, colorstr, get_latest_run, increment_path, + init_seeds, intersect_dicts, labels_to_class_weights, labels_to_image_weights, methods, + one_cycle, print_mutation, strip_optimizer, yaml_save) from utils.loggers import Loggers from utils.loggers.comet.comet_utils import check_comet_resume from utils.loss import ComputeLoss diff --git a/utils/dataloaders.py b/utils/dataloaders.py index c8d843c979b4..24a76526963b 100644 --- a/utils/dataloaders.py +++ b/utils/dataloaders.py @@ -31,8 +31,9 @@ from utils.augmentations import (Albumentations, augment_hsv, classify_albumentations, classify_transforms, copy_paste, letterbox, mixup, random_perspective) -from utils.general import (DATASETS_DIR, LOGGER, NUM_THREADS, TQDM_BAR_FORMAT, check_yaml, check_dataset, clean_str, cv2, is_colab, - is_kaggle, segments2boxes, unzip_file, xyn2xy, xywh2xyxy, xywhn2xyxy, xyxy2xywhn) +from utils.general import (DATASETS_DIR, LOGGER, NUM_THREADS, TQDM_BAR_FORMAT, check_dataset, check_yaml, clean_str, + cv2, is_colab, is_kaggle, segments2boxes, unzip_file, xyn2xy, xywh2xyxy, xywhn2xyxy, + xyxy2xywhn) from utils.torch_utils import torch_distributed_zero_first # Parameters diff --git a/utils/general.py b/utils/general.py index 9d853dcea05b..9fb4c748d501 100644 --- a/utils/general.py +++ b/utils/general.py @@ -278,6 +278,7 @@ def check_yaml(file, suffix=('.yaml', '.yml')): # Search/download YAML file (if necessary) and return path, checking suffix return check_file(file, suffix) + def check_online(): # Check internet connectivity import socket diff --git a/val.py b/val.py index f1d334f438ef..514698490bf1 100644 --- a/val.py +++ b/val.py @@ -41,8 +41,9 @@ from models.common import DetectMultiBackend from utils.callbacks import Callbacks from utils.dataloaders import create_dataloader -from utils.general import (LOGGER, TQDM_BAR_FORMAT, Profile, check_dataset, check_img_size, coco80_to_coco91_class, - colorstr, increment_path, non_max_suppression, scale_boxes, xywh2xyxy, xyxy2xywh, check_yaml) +from utils.general import (LOGGER, TQDM_BAR_FORMAT, Profile, check_dataset, check_img_size, check_yaml, + coco80_to_coco91_class, colorstr, increment_path, non_max_suppression, scale_boxes, + xywh2xyxy, xyxy2xywh) from utils.metrics import ConfusionMatrix, ap_per_class, box_iou from utils.plots import output_to_target, plot_images, plot_val_study From 49faf87ead326362e4900b51dd9fc778304c00e2 Mon Sep 17 00:00:00 2001 From: Ayush Chaurasia Date: Thu, 1 Jun 2023 10:17:31 +0530 Subject: [PATCH 10/15] use autobatch --- segment/train.py | 2 +- train.py | 2 +- utils/autobatch.py | 72 ---------------------------------------------- 3 files changed, 2 insertions(+), 74 deletions(-) delete mode 100644 utils/autobatch.py diff --git a/segment/train.py b/segment/train.py index 3b35d44abee0..6f1dd2326eca 100644 --- a/segment/train.py +++ b/segment/train.py @@ -35,6 +35,7 @@ from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights from ultralytics.yolo.utils.checks import check_requirements +from ultralytics.yolo.utils.autobatch import check_train_batch_size FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -45,7 +46,6 @@ import segment.val as validate # for end-of-epoch mAP from models.yolo import SegmentationModel from utils.autoanchor import check_anchors -from utils.autobatch import check_train_batch_size from utils.callbacks import Callbacks from utils.downloads import attempt_download, is_url from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_info, diff --git a/train.py b/train.py index 597d991a4d9e..e32e3114a19b 100644 --- a/train.py +++ b/train.py @@ -37,6 +37,7 @@ from ultralytics.yolo.utils.checks import check_requirements, check_suffix, print_args from ultralytics.yolo.utils.torch_utils import (EarlyStopping, ModelEMA, de_parallel, select_device, torch_distributed_zero_first) +from ultralytics.yolo.utils.autobatch import check_train_batch_size FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -47,7 +48,6 @@ import val as validate # for end-of-epoch mAP from models.yolo import Model from utils.autoanchor import check_anchors -from utils.autobatch import check_train_batch_size from utils.callbacks import Callbacks from utils.dataloaders import create_dataloader from utils.downloads import attempt_download, is_url diff --git a/utils/autobatch.py b/utils/autobatch.py deleted file mode 100644 index aa763b888462..000000000000 --- a/utils/autobatch.py +++ /dev/null @@ -1,72 +0,0 @@ -# YOLOv5 🚀 by Ultralytics, AGPL-3.0 license -""" -Auto-batch utils -""" - -from copy import deepcopy - -import numpy as np -import torch - -from utils.general import LOGGER, colorstr -from utils.torch_utils import profile - - -def check_train_batch_size(model, imgsz=640, amp=True): - # Check YOLOv5 training batch size - with torch.cuda.amp.autocast(amp): - return autobatch(deepcopy(model).train(), imgsz) # compute optimal batch size - - -def autobatch(model, imgsz=640, fraction=0.8, batch_size=16): - # Automatically estimate best YOLOv5 batch size to use `fraction` of available CUDA memory - # Usage: - # import torch - # from utils.autobatch import autobatch - # model = torch.hub.load('ultralytics/yolov5', 'yolov5s', autoshape=False) - # print(autobatch(model)) - - # Check device - prefix = colorstr('AutoBatch: ') - LOGGER.info(f'{prefix}Computing optimal batch size for --imgsz {imgsz}') - device = next(model.parameters()).device # get model device - if device.type == 'cpu': - LOGGER.info(f'{prefix}CUDA not detected, using default CPU batch-size {batch_size}') - return batch_size - if torch.backends.cudnn.benchmark: - LOGGER.info(f'{prefix} ⚠️ Requires torch.backends.cudnn.benchmark=False, using default batch-size {batch_size}') - return batch_size - - # Inspect CUDA memory - gb = 1 << 30 # bytes to GiB (1024 ** 3) - d = str(device).upper() # 'CUDA:0' - properties = torch.cuda.get_device_properties(device) # device properties - t = properties.total_memory / gb # GiB total - r = torch.cuda.memory_reserved(device) / gb # GiB reserved - a = torch.cuda.memory_allocated(device) / gb # GiB allocated - f = t - (r + a) # GiB free - LOGGER.info(f'{prefix}{d} ({properties.name}) {t:.2f}G total, {r:.2f}G reserved, {a:.2f}G allocated, {f:.2f}G free') - - # Profile batch sizes - batch_sizes = [1, 2, 4, 8, 16] - try: - img = [torch.empty(b, 3, imgsz, imgsz) for b in batch_sizes] - results = profile(img, model, n=3, device=device) - except Exception as e: - LOGGER.warning(f'{prefix}{e}') - - # Fit a solution - y = [x[2] for x in results if x] # memory [2] - p = np.polyfit(batch_sizes[:len(y)], y, deg=1) # first degree polynomial fit - b = int((f * fraction - p[1]) / p[0]) # y intercept (optimal batch size) - if None in results: # some sizes failed - i = results.index(None) # first fail index - if b >= batch_sizes[i]: # y intercept above failure point - b = batch_sizes[max(i - 1, 0)] # select prior safe point - if b < 1 or b > 1024: # b outside of safe range - b = batch_size - LOGGER.warning(f'{prefix}WARNING ⚠️ CUDA anomaly detected, recommend restart environment and retry command.') - - fraction = (np.polyval(p, b) + r + a) / t # actual fraction predicted - LOGGER.info(f'{prefix}Using batch-size {b} for {d} {t * fraction:.2f}G/{t:.2f}G ({fraction * 100:.0f}%) ✅') - return b From 035534350f4d6fea6a5e0630cfeef908dd428098 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 Jun 2023 04:47:54 +0000 Subject: [PATCH 11/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- segment/train.py | 2 +- train.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/segment/train.py b/segment/train.py index 6f1dd2326eca..544ef68bb3b3 100644 --- a/segment/train.py +++ b/segment/train.py @@ -34,8 +34,8 @@ from torch.optim import lr_scheduler from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights -from ultralytics.yolo.utils.checks import check_requirements from ultralytics.yolo.utils.autobatch import check_train_batch_size +from ultralytics.yolo.utils.checks import check_requirements FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory diff --git a/train.py b/train.py index e32e3114a19b..0b60c2912b19 100644 --- a/train.py +++ b/train.py @@ -34,10 +34,10 @@ from torch.optim import lr_scheduler from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights +from ultralytics.yolo.utils.autobatch import check_train_batch_size from ultralytics.yolo.utils.checks import check_requirements, check_suffix, print_args from ultralytics.yolo.utils.torch_utils import (EarlyStopping, ModelEMA, de_parallel, select_device, torch_distributed_zero_first) -from ultralytics.yolo.utils.autobatch import check_train_batch_size FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory From 9946c687cdcb22b66b69b87c64caabf4cc05e9d8 Mon Sep 17 00:00:00 2001 From: Ayush Chaurasia Date: Thu, 1 Jun 2023 10:38:36 +0530 Subject: [PATCH 12/15] update --- classify/predict.py | 7 +++-- classify/val.py | 5 ++-- detect.py | 6 ++--- export.py | 5 ++-- segment/predict.py | 8 +++--- segment/train.py | 12 ++++----- segment/val.py | 8 +++--- train.py | 9 ++++--- utils/general.py | 66 --------------------------------------------- val.py | 4 +-- 10 files changed, 32 insertions(+), 98 deletions(-) diff --git a/classify/predict.py b/classify/predict.py index a6e190d4e274..09502b5712dc 100644 --- a/classify/predict.py +++ b/classify/predict.py @@ -36,8 +36,8 @@ import torch import torch.nn.functional as F -from ultralytics.yolo.utils.checks import check_requirements, print_args -from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode +from ultralytics.yolo.utils.checks import check_requirements, print_args, check_img_size, check_imshow +from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode, strip_optimizer FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -48,8 +48,7 @@ from models.common import DetectMultiBackend from utils.augmentations import classify_transforms from utils.dataloaders import IMG_FORMATS, VID_FORMATS, LoadImages, LoadScreenshots, LoadStreams -from utils.general import (LOGGER, Profile, check_file, check_img_size, check_imshow, colorstr, cv2, increment_path, - strip_optimizer) +from utils.general import LOGGER, Profile, check_file, colorstr, cv2, increment_path from utils.plots import Annotator diff --git a/classify/val.py b/classify/val.py index 24039b9780d2..9da547fb3c03 100644 --- a/classify/val.py +++ b/classify/val.py @@ -28,6 +28,8 @@ import torch from tqdm import tqdm from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode +from ultralytics.yolo.utils.checks import check_img_size, check_requirements, print_args +from ultralytics.yolo.utils import colorstr FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -37,8 +39,7 @@ from models.common import DetectMultiBackend from utils.dataloaders import create_classification_dataloader -from utils.general import (LOGGER, TQDM_BAR_FORMAT, Profile, check_img_size, check_requirements, colorstr, - increment_path, print_args) +from utils.general import LOGGER, TQDM_BAR_FORMAT, Profile, increment_path @smart_inference_mode() diff --git a/detect.py b/detect.py index eec9f1e7103a..0dbfa92ab5a3 100644 --- a/detect.py +++ b/detect.py @@ -35,7 +35,8 @@ from pathlib import Path import torch -from ultralytics.yolo.utils.checks import print_args +from ultralyitcs.yolo.utils import colorstr +from ultralytics.yolo.utils.checks import print_args, check_img_size, check_imshow, check_requirements from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve() @@ -46,8 +47,7 @@ from models.common import DetectMultiBackend from utils.dataloaders import IMG_FORMATS, VID_FORMATS, LoadImages, LoadScreenshots, LoadStreams -from utils.general import (LOGGER, Profile, check_file, check_img_size, check_imshow, check_requirements, colorstr, cv2, - increment_path, non_max_suppression, scale_boxes, strip_optimizer, xyxy2xywh) +from utils.general import (LOGGER, Profile, check_file, cv2, increment_path, non_max_suppression, scale_boxes, strip_optimizer, xyxy2xywh) from utils.plots import Annotator, colors, save_one_box diff --git a/export.py b/export.py index 8c465d695ac6..60a87f38c789 100644 --- a/export.py +++ b/export.py @@ -61,6 +61,8 @@ from torch.utils.mobile_optimizer import optimize_for_mobile from ultralytics.nn.tasks import attempt_load_weights from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode +from ultraltics.yolo.utils import file_size, check_requirements, colorstr +from ultralytics.yolo.utils.checks import print_args, check_img_size, check_version FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -71,8 +73,7 @@ from models.yolo import ClassificationModel, Detect, DetectionModel, SegmentationModel from utils.dataloaders import LoadImages -from utils.general import (LOGGER, Profile, check_dataset, check_img_size, check_requirements, check_version, - check_yaml, colorstr, file_size, get_default_args, print_args, url2file, yaml_save) +from utils.general import (LOGGER, Profile, check_dataset, check_yaml, get_default_args, url2file, yaml_save) MACOS = platform.system() == 'Darwin' # macOS environment diff --git a/segment/predict.py b/segment/predict.py index 03cb96cf3069..6268493c8859 100644 --- a/segment/predict.py +++ b/segment/predict.py @@ -35,8 +35,8 @@ from pathlib import Path import torch -from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode -from ultrlalytics.yolo.utils.checks import check_reuirements, print_args +from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode, strip_optimizer +from ultrlalytics.yolo.utils.checks import print_args, check_img_size, check_imshow FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -46,8 +46,8 @@ from models.common import DetectMultiBackend from utils.dataloaders import IMG_FORMATS, VID_FORMATS, LoadImages, LoadScreenshots, LoadStreams -from utils.general import (LOGGER, Profile, check_file, check_img_size, check_imshow, colorstr, cv2, increment_path, - non_max_suppression, scale_boxes, scale_segments, strip_optimizer) +from utils.general import (LOGGER, Profile, check_file, colorstr, cv2, increment_path, + non_max_suppression, scale_boxes, scale_segments) from utils.plots import Annotator, colors, save_one_box from utils.segment.general import masks2segments, process_mask, process_mask_native diff --git a/segment/train.py b/segment/train.py index 6f1dd2326eca..3a0b8ae7a3d4 100644 --- a/segment/train.py +++ b/segment/train.py @@ -34,8 +34,10 @@ from torch.optim import lr_scheduler from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights -from ultralytics.yolo.utils.checks import check_requirements +from ultralytics.yolo.utils.checks import check_requirements, check_img_size from ultralytics.yolo.utils.autobatch import check_train_batch_size +from ultralytics.yolo.utils import colorstr, increment_path +from ultralytics.yolo.utils.torch_utils import strip_optimizer, de_parallel, torch_distributed_zero_first FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -48,18 +50,14 @@ from utils.autoanchor import check_anchors from utils.callbacks import Callbacks from utils.downloads import attempt_download, is_url -from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_info, - check_git_status, check_img_size, check_suffix, check_yaml, colorstr, get_latest_run, - increment_path, init_seeds, intersect_dicts, labels_to_class_weights, - labels_to_image_weights, one_cycle, print_mutation, strip_optimizer, yaml_save) +from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_file, check_git_info, check_git_status, check_suffix, check_yaml, get_latest_run, init_seeds, intersect_dicts, labels_to_class_weights, labels_to_image_weights, one_cycle, print_mutation, yaml_save, check_dataset) from utils.loggers import GenericLogger from utils.plots import plot_evolve, plot_labels from utils.segment.dataloaders import create_dataloader from utils.segment.loss import ComputeLoss from utils.segment.metrics import KEYS, fitness from utils.segment.plots import plot_images_and_masks, plot_results_with_masks -from utils.torch_utils import (EarlyStopping, ModelEMA, de_parallel, select_device, smart_DDP, smart_optimizer, - smart_resume, torch_distributed_zero_first) +from utils.torch_utils import EarlyStopping, ModelEMA, smart_DDP, smart_optimizer, smart_resume LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html RANK = int(os.getenv('RANK', -1)) diff --git a/segment/val.py b/segment/val.py index 0861100d88b0..9892b6984011 100644 --- a/segment/val.py +++ b/segment/val.py @@ -39,21 +39,21 @@ ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative import torch.nn.functional as F -from ultralytis.yolo.utils.checks import check_requirements, print_args +from ultralytis.yolo.utils.checks import check_requirements, print_args, check_img_size +from ultralytics.yolo.utils.torch_utils import de_parallel, select_device, smart_inference_mode from models.common import DetectMultiBackend from models.yolo import SegmentationModel from utils.callbacks import Callbacks -from utils.general import (LOGGER, NUM_THREADS, TQDM_BAR_FORMAT, Profile, check_dataset, check_img_size, check_yaml, +from utils.general import (LOGGER, NUM_THREADS, TQDM_BAR_FORMAT, Profile, check_yaml, coco80_to_coco91_class, colorstr, increment_path, non_max_suppression, scale_boxes, - xywh2xyxy, xyxy2xywh) + xywh2xyxy, xyxy2xywh, check_dataset) from utils.metrics import ConfusionMatrix, box_iou from utils.plots import output_to_target, plot_val_study from utils.segment.dataloaders import create_dataloader from utils.segment.general import mask_iou, process_mask, process_mask_native, scale_image from utils.segment.metrics import Metrics, ap_per_class_box_and_mask from utils.segment.plots import plot_images_and_masks -from utils.torch_utils import de_parallel, select_device, smart_inference_mode def save_one_txt(predn, save_conf, shape, file): diff --git a/train.py b/train.py index e32e3114a19b..a45681c61ec1 100644 --- a/train.py +++ b/train.py @@ -34,10 +34,11 @@ from torch.optim import lr_scheduler from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights -from ultralytics.yolo.utils.checks import check_requirements, check_suffix, print_args -from ultralytics.yolo.utils.torch_utils import (EarlyStopping, ModelEMA, de_parallel, select_device, +from ultralytics.yolo.utils.checks import check_requirements, check_suffix, print_args, check_img_size +from ultralytics.yolo.utils.torch_utils import (EarlyStopping, ModelEMA, de_parallel, select_device, strip_optimizer, torch_distributed_zero_first) from ultralytics.yolo.utils.autobatch import check_train_batch_size +from ultralyics.yolo.utils import colorstr FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -52,9 +53,9 @@ from utils.dataloaders import create_dataloader from utils.downloads import attempt_download, is_url from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_info, - check_git_status, check_img_size, check_yaml, colorstr, get_latest_run, increment_path, + check_git_status, check_yaml, get_latest_run, increment_path, init_seeds, intersect_dicts, labels_to_class_weights, labels_to_image_weights, methods, - one_cycle, print_mutation, strip_optimizer, yaml_save) + one_cycle, print_mutation, yaml_save) from utils.loggers import Loggers from utils.loggers.comet.comet_utils import check_comet_resume from utils.loss import ComputeLoss diff --git a/utils/general.py b/utils/general.py index 9fb4c748d501..5f081f0e7436 100644 --- a/utils/general.py +++ b/utils/general.py @@ -354,46 +354,6 @@ def check_python(minimum='3.7.0'): check_version(platform.python_version(), minimum, name='Python ', hard=True) -def check_version(current='0.0.0', minimum='0.0.0', name='version ', pinned=False, hard=False, verbose=False): - # Check version vs. required version - current, minimum = (pkg.parse_version(x) for x in (current, minimum)) - result = (current == minimum) if pinned else (current >= minimum) # bool - s = f'WARNING ⚠️ {name}{minimum} is required by YOLOv5, but {name}{current} is currently installed' # string - if hard: - assert result, emojis(s) # assert min requirements met - if verbose and not result: - LOGGER.warning(s) - return result - - -def check_img_size(imgsz, s=32, floor=0): - # Verify image size is a multiple of stride s in each dimension - if isinstance(imgsz, int): # integer i.e. img_size=640 - new_size = max(make_divisible(imgsz, int(s)), floor) - else: # list i.e. img_size=[640, 480] - imgsz = list(imgsz) # convert to list if tuple - new_size = [max(make_divisible(x, int(s)), floor) for x in imgsz] - if new_size != imgsz: - LOGGER.warning(f'WARNING ⚠️ --img-size {imgsz} must be multiple of max stride {s}, updating to {new_size}') - return new_size - - -def check_imshow(warn=False): - # Check if environment supports image displays - try: - assert not is_jupyter() - assert not is_docker() - cv2.imshow('test', np.zeros((1, 1, 3))) - cv2.waitKey(1) - cv2.destroyAllWindows() - cv2.waitKey(1) - return True - except Exception as e: - if warn: - LOGGER.warning(f'WARNING ⚠️ Environment does not support cv2.imshow() or PIL Image.show()\n{e}') - return False - - def check_suffix(file='yolov5s.pt', suffix=('.pt',), msg=''): # Check file(s) for acceptable suffix if file and suffix: @@ -628,32 +588,6 @@ def one_cycle(y1=0.0, y2=1.0, steps=100): return lambda x: ((1 - math.cos(x * math.pi / steps)) / 2) * (y2 - y1) + y1 -def colorstr(*input): - # Colors a string https://en.wikipedia.org/wiki/ANSI_escape_code, i.e. colorstr('blue', 'hello world') - *args, string = input if len(input) > 1 else ('blue', 'bold', input[0]) # color arguments, string - colors = { - 'black': '\033[30m', # basic colors - 'red': '\033[31m', - 'green': '\033[32m', - 'yellow': '\033[33m', - 'blue': '\033[34m', - 'magenta': '\033[35m', - 'cyan': '\033[36m', - 'white': '\033[37m', - 'bright_black': '\033[90m', # bright colors - 'bright_red': '\033[91m', - 'bright_green': '\033[92m', - 'bright_yellow': '\033[93m', - 'bright_blue': '\033[94m', - 'bright_magenta': '\033[95m', - 'bright_cyan': '\033[96m', - 'bright_white': '\033[97m', - 'end': '\033[0m', # misc - 'bold': '\033[1m', - 'underline': '\033[4m'} - return ''.join(colors[x] for x in args) + f'{string}' + colors['end'] - - def labels_to_class_weights(labels, nc=80): # Get class weights (inverse frequency) from training labels if labels[0] is None: # no labels loaded diff --git a/val.py b/val.py index 514698490bf1..77e9255a9c5a 100644 --- a/val.py +++ b/val.py @@ -29,7 +29,7 @@ import numpy as np import torch from tqdm import tqdm -from ultralytics.yolo.utils.checks import check_requirements, print_args +from ultralytics.yolo.utils.checks import check_requirements, print_args, check_img_size from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve() @@ -41,7 +41,7 @@ from models.common import DetectMultiBackend from utils.callbacks import Callbacks from utils.dataloaders import create_dataloader -from utils.general import (LOGGER, TQDM_BAR_FORMAT, Profile, check_dataset, check_img_size, check_yaml, +from utils.general import (LOGGER, TQDM_BAR_FORMAT, Profile, check_dataset, check_yaml, coco80_to_coco91_class, colorstr, increment_path, non_max_suppression, scale_boxes, xywh2xyxy, xyxy2xywh) from utils.metrics import ConfusionMatrix, ap_per_class, box_iou From 9f32732af9cfd9da177aa5e6698fa31126f98eb1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 Jun 2023 05:09:38 +0000 Subject: [PATCH 13/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- classify/predict.py | 2 +- classify/val.py | 4 ++-- detect.py | 5 +++-- export.py | 6 +++--- segment/predict.py | 6 +++--- segment/train.py | 10 ++++++---- segment/val.py | 6 +++--- train.py | 10 +++++----- val.py | 7 +++---- 9 files changed, 29 insertions(+), 27 deletions(-) diff --git a/classify/predict.py b/classify/predict.py index 09502b5712dc..0c32a446c336 100644 --- a/classify/predict.py +++ b/classify/predict.py @@ -36,7 +36,7 @@ import torch import torch.nn.functional as F -from ultralytics.yolo.utils.checks import check_requirements, print_args, check_img_size, check_imshow +from ultralytics.yolo.utils.checks import check_img_size, check_imshow, check_requirements, print_args from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode, strip_optimizer FILE = Path(__file__).resolve() diff --git a/classify/val.py b/classify/val.py index 9da547fb3c03..547683ce8ee7 100644 --- a/classify/val.py +++ b/classify/val.py @@ -27,9 +27,9 @@ import torch from tqdm import tqdm -from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode -from ultralytics.yolo.utils.checks import check_img_size, check_requirements, print_args from ultralytics.yolo.utils import colorstr +from ultralytics.yolo.utils.checks import check_img_size, check_requirements, print_args +from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory diff --git a/detect.py b/detect.py index 0dbfa92ab5a3..adfbfefd2a03 100644 --- a/detect.py +++ b/detect.py @@ -36,7 +36,7 @@ import torch from ultralyitcs.yolo.utils import colorstr -from ultralytics.yolo.utils.checks import print_args, check_img_size, check_imshow, check_requirements +from ultralytics.yolo.utils.checks import check_img_size, check_imshow, check_requirements, print_args from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve() @@ -47,7 +47,8 @@ from models.common import DetectMultiBackend from utils.dataloaders import IMG_FORMATS, VID_FORMATS, LoadImages, LoadScreenshots, LoadStreams -from utils.general import (LOGGER, Profile, check_file, cv2, increment_path, non_max_suppression, scale_boxes, strip_optimizer, xyxy2xywh) +from utils.general import (LOGGER, Profile, check_file, cv2, increment_path, non_max_suppression, scale_boxes, + strip_optimizer, xyxy2xywh) from utils.plots import Annotator, colors, save_one_box diff --git a/export.py b/export.py index 60a87f38c789..06c428df1f17 100644 --- a/export.py +++ b/export.py @@ -59,10 +59,10 @@ import pandas as pd import torch from torch.utils.mobile_optimizer import optimize_for_mobile +from ultraltics.yolo.utils import check_requirements, colorstr, file_size from ultralytics.nn.tasks import attempt_load_weights +from ultralytics.yolo.utils.checks import check_img_size, check_version, print_args from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode -from ultraltics.yolo.utils import file_size, check_requirements, colorstr -from ultralytics.yolo.utils.checks import print_args, check_img_size, check_version FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -73,7 +73,7 @@ from models.yolo import ClassificationModel, Detect, DetectionModel, SegmentationModel from utils.dataloaders import LoadImages -from utils.general import (LOGGER, Profile, check_dataset, check_yaml, get_default_args, url2file, yaml_save) +from utils.general import LOGGER, Profile, check_dataset, check_yaml, get_default_args, url2file, yaml_save MACOS = platform.system() == 'Darwin' # macOS environment diff --git a/segment/predict.py b/segment/predict.py index 6268493c8859..813e255508a8 100644 --- a/segment/predict.py +++ b/segment/predict.py @@ -36,7 +36,7 @@ import torch from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode, strip_optimizer -from ultrlalytics.yolo.utils.checks import print_args, check_img_size, check_imshow +from ultrlalytics.yolo.utils.checks import check_img_size, check_imshow, print_args FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -46,8 +46,8 @@ from models.common import DetectMultiBackend from utils.dataloaders import IMG_FORMATS, VID_FORMATS, LoadImages, LoadScreenshots, LoadStreams -from utils.general import (LOGGER, Profile, check_file, colorstr, cv2, increment_path, - non_max_suppression, scale_boxes, scale_segments) +from utils.general import (LOGGER, Profile, check_file, colorstr, cv2, increment_path, non_max_suppression, scale_boxes, + scale_segments) from utils.plots import Annotator, colors, save_one_box from utils.segment.general import masks2segments, process_mask, process_mask_native diff --git a/segment/train.py b/segment/train.py index 3a0b8ae7a3d4..6b79215e2ed5 100644 --- a/segment/train.py +++ b/segment/train.py @@ -34,10 +34,10 @@ from torch.optim import lr_scheduler from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights -from ultralytics.yolo.utils.checks import check_requirements, check_img_size +from ultralytics.yolo.utils import colorstr, increment_path from ultralytics.yolo.utils.autobatch import check_train_batch_size -from ultralytics.yolo.utils import colorstr, increment_path -from ultralytics.yolo.utils.torch_utils import strip_optimizer, de_parallel, torch_distributed_zero_first +from ultralytics.yolo.utils.checks import check_img_size, check_requirements +from ultralytics.yolo.utils.torch_utils import de_parallel, strip_optimizer, torch_distributed_zero_first FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -50,7 +50,9 @@ from utils.autoanchor import check_anchors from utils.callbacks import Callbacks from utils.downloads import attempt_download, is_url -from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_file, check_git_info, check_git_status, check_suffix, check_yaml, get_latest_run, init_seeds, intersect_dicts, labels_to_class_weights, labels_to_image_weights, one_cycle, print_mutation, yaml_save, check_dataset) +from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_info, + check_git_status, check_suffix, check_yaml, get_latest_run, init_seeds, intersect_dicts, + labels_to_class_weights, labels_to_image_weights, one_cycle, print_mutation, yaml_save) from utils.loggers import GenericLogger from utils.plots import plot_evolve, plot_labels from utils.segment.dataloaders import create_dataloader diff --git a/segment/val.py b/segment/val.py index 9892b6984011..71c6fbf0318b 100644 --- a/segment/val.py +++ b/segment/val.py @@ -39,15 +39,15 @@ ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative import torch.nn.functional as F -from ultralytis.yolo.utils.checks import check_requirements, print_args, check_img_size from ultralytics.yolo.utils.torch_utils import de_parallel, select_device, smart_inference_mode +from ultralytis.yolo.utils.checks import check_img_size, check_requirements, print_args from models.common import DetectMultiBackend from models.yolo import SegmentationModel from utils.callbacks import Callbacks -from utils.general import (LOGGER, NUM_THREADS, TQDM_BAR_FORMAT, Profile, check_yaml, +from utils.general import (LOGGER, NUM_THREADS, TQDM_BAR_FORMAT, Profile, check_dataset, check_yaml, coco80_to_coco91_class, colorstr, increment_path, non_max_suppression, scale_boxes, - xywh2xyxy, xyxy2xywh, check_dataset) + xywh2xyxy, xyxy2xywh) from utils.metrics import ConfusionMatrix, box_iou from utils.plots import output_to_target, plot_val_study from utils.segment.dataloaders import create_dataloader diff --git a/train.py b/train.py index 57d3ce72c27b..8985b92d424b 100644 --- a/train.py +++ b/train.py @@ -34,10 +34,10 @@ from torch.optim import lr_scheduler from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights -from ultralytics.yolo.utils.checks import check_requirements, check_suffix, print_args, check_img_size +from ultralytics.yolo.utils.autobatch import check_train_batch_size +from ultralytics.yolo.utils.checks import check_img_size, check_requirements, check_suffix, print_args from ultralytics.yolo.utils.torch_utils import (EarlyStopping, ModelEMA, de_parallel, select_device, strip_optimizer, torch_distributed_zero_first) -from ultralytics.yolo.utils.autobatch import check_train_batch_size FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -52,9 +52,9 @@ from utils.dataloaders import create_dataloader from utils.downloads import attempt_download, is_url from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_info, - check_git_status, check_yaml, get_latest_run, increment_path, - init_seeds, intersect_dicts, labels_to_class_weights, labels_to_image_weights, methods, - one_cycle, print_mutation, yaml_save) + check_git_status, check_yaml, get_latest_run, increment_path, init_seeds, intersect_dicts, + labels_to_class_weights, labels_to_image_weights, methods, one_cycle, print_mutation, + yaml_save) from utils.loggers import Loggers from utils.loggers.comet.comet_utils import check_comet_resume from utils.loss import ComputeLoss diff --git a/val.py b/val.py index 77e9255a9c5a..35ec0ffb2055 100644 --- a/val.py +++ b/val.py @@ -29,7 +29,7 @@ import numpy as np import torch from tqdm import tqdm -from ultralytics.yolo.utils.checks import check_requirements, print_args, check_img_size +from ultralytics.yolo.utils.checks import check_img_size, check_requirements, print_args from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve() @@ -41,9 +41,8 @@ from models.common import DetectMultiBackend from utils.callbacks import Callbacks from utils.dataloaders import create_dataloader -from utils.general import (LOGGER, TQDM_BAR_FORMAT, Profile, check_dataset, check_yaml, - coco80_to_coco91_class, colorstr, increment_path, non_max_suppression, scale_boxes, - xywh2xyxy, xyxy2xywh) +from utils.general import (LOGGER, TQDM_BAR_FORMAT, Profile, check_dataset, check_yaml, coco80_to_coco91_class, + colorstr, increment_path, non_max_suppression, scale_boxes, xywh2xyxy, xyxy2xywh) from utils.metrics import ConfusionMatrix, ap_per_class, box_iou from utils.plots import output_to_target, plot_images, plot_val_study From 16d32a777c2e9c8c7b80f596dd4f873705eafb39 Mon Sep 17 00:00:00 2001 From: Ayush Chaurasia Date: Thu, 1 Jun 2023 10:44:26 +0530 Subject: [PATCH 14/15] udpate --- classify/predict.py | 4 ++-- classify/val.py | 4 ++-- detect.py | 4 ++-- export.py | 4 ++-- models/common.py | 4 +++- models/yolo.py | 3 ++- segment/predict.py | 4 ++-- segment/train.py | 4 ++-- segment/val.py | 4 ++-- train.py | 5 +++-- utils/augmentations.py | 4 +++- utils/general.py | 3 ++- val.py | 4 ++-- 13 files changed, 29 insertions(+), 22 deletions(-) diff --git a/classify/predict.py b/classify/predict.py index 09502b5712dc..d99b1a7b1cdb 100644 --- a/classify/predict.py +++ b/classify/predict.py @@ -36,7 +36,7 @@ import torch import torch.nn.functional as F -from ultralytics.yolo.utils.checks import check_requirements, print_args, check_img_size, check_imshow +from ultralytics.yolo.utils.checks import check_requirements, print_args, check_imgsz, check_imshow from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode, strip_optimizer FILE = Path(__file__).resolve() @@ -89,7 +89,7 @@ def run( device = select_device(device) model = DetectMultiBackend(weights, device=device, dnn=dnn, data=data, fp16=half) stride, names, pt = model.stride, model.names, model.pt - imgsz = check_img_size(imgsz, s=stride) # check image size + imgsz = check_imgsz(imgsz, s=stride) # check image size # Dataloader bs = 1 # batch_size diff --git a/classify/val.py b/classify/val.py index 9da547fb3c03..fd87aafc36b6 100644 --- a/classify/val.py +++ b/classify/val.py @@ -28,7 +28,7 @@ import torch from tqdm import tqdm from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode -from ultralytics.yolo.utils.checks import check_img_size, check_requirements, print_args +from ultralytics.yolo.utils.checks import check_imgsz, check_requirements, print_args from ultralytics.yolo.utils import colorstr FILE = Path(__file__).resolve() @@ -77,7 +77,7 @@ def run( # Load model model = DetectMultiBackend(weights, device=device, dnn=dnn, fp16=half) stride, pt, jit, engine = model.stride, model.pt, model.jit, model.engine - imgsz = check_img_size(imgsz, s=stride) # check image size + imgsz = check_imgsz(imgsz, s=stride) # check image size half = model.fp16 # FP16 supported on limited backends with CUDA if engine: batch_size = model.batch_size diff --git a/detect.py b/detect.py index 0dbfa92ab5a3..2689db78277b 100644 --- a/detect.py +++ b/detect.py @@ -36,7 +36,7 @@ import torch from ultralyitcs.yolo.utils import colorstr -from ultralytics.yolo.utils.checks import print_args, check_img_size, check_imshow, check_requirements +from ultralytics.yolo.utils.checks import print_args, check_imgsz, check_imshow, check_requirements from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve() @@ -98,7 +98,7 @@ def run( device = select_device(device) model = DetectMultiBackend(weights, device=device, dnn=dnn, data=data, fp16=half) stride, names, pt = model.stride, model.names, model.pt - imgsz = check_img_size(imgsz, s=stride) # check image size + imgsz = check_imgsz(imgsz, s=stride) # check image size # Dataloader bs = 1 # batch_size diff --git a/export.py b/export.py index 60a87f38c789..ef84200e0895 100644 --- a/export.py +++ b/export.py @@ -62,7 +62,7 @@ from ultralytics.nn.tasks import attempt_load_weights from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode from ultraltics.yolo.utils import file_size, check_requirements, colorstr -from ultralytics.yolo.utils.checks import print_args, check_img_size, check_version +from ultralytics.yolo.utils.checks import print_args, check_imgsz, check_version FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -698,7 +698,7 @@ def run( # Input gs = int(max(model.stride)) # grid size (max stride) - imgsz = [check_img_size(x, gs) for x in imgsz] # verify img_size are gs-multiples + imgsz = [check_imgsz(x, gs) for x in imgsz] # verify img_size are gs-multiples im = torch.zeros(batch_size, 3, *imgsz).to(device) # image size(1,3,320,192) BCHW iDetection # Update model diff --git a/models/common.py b/models/common.py index 9ad210821f46..52623da2be6e 100644 --- a/models/common.py +++ b/models/common.py @@ -24,10 +24,12 @@ from PIL import Image from torch.cuda import amp from ultralytics.nn.tasks import attempt_load_weights +from ultralytics.yolo.utils.checks import check_requirements, check_suffix, check_version +from ultralytics.yolo.utils import colorstr from utils import TryExcept from utils.dataloaders import exif_transpose, letterbox -from utils.general import (LOGGER, ROOT, Profile, check_requirements, check_suffix, check_version, colorstr, +from utils.general import (LOGGER, ROOT, Profile, increment_path, is_jupyter, make_divisible, non_max_suppression, scale_boxes, xywh2xyxy, xyxy2xywh, yaml_load) from utils.plots import Annotator, colors, save_one_box diff --git a/models/yolo.py b/models/yolo.py index 034a289fcd06..a61e7bfbc06d 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -16,6 +16,7 @@ from ultralytics.yolo.utils.checks import print_args from ultralytics.yolo.utils.torch_utils import select_device +from ultralytics.yolo.utils.checks import check_version FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -27,7 +28,7 @@ from models.common import * from models.experimental import * from utils.autoanchor import check_anchor_order -from utils.general import LOGGER, check_version, check_yaml, make_divisible +from utils.general import LOGGER, check_yaml, make_divisible from utils.plots import feature_visualization from utils.torch_utils import fuse_conv_and_bn, initialize_weights, model_info, profile, scale_img, time_sync diff --git a/segment/predict.py b/segment/predict.py index 6268493c8859..618e7cf26b61 100644 --- a/segment/predict.py +++ b/segment/predict.py @@ -36,7 +36,7 @@ import torch from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode, strip_optimizer -from ultrlalytics.yolo.utils.checks import print_args, check_img_size, check_imshow +from ultrlalytics.yolo.utils.checks import print_args, check_imgsz, check_imshow FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory @@ -100,7 +100,7 @@ def run( device = select_device(device) model = DetectMultiBackend(weights, device=device, dnn=dnn, data=data, fp16=half) stride, names, pt = model.stride, model.names, model.pt - imgsz = check_img_size(imgsz, s=stride) # check image size + imgsz = check_imgsz(imgsz, s=stride) # check image size # Dataloader bs = 1 # batch_size diff --git a/segment/train.py b/segment/train.py index 3a0b8ae7a3d4..6e1cd6148d80 100644 --- a/segment/train.py +++ b/segment/train.py @@ -34,7 +34,7 @@ from torch.optim import lr_scheduler from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights -from ultralytics.yolo.utils.checks import check_requirements, check_img_size +from ultralytics.yolo.utils.checks import check_requirements, check_imgsz from ultralytics.yolo.utils.autobatch import check_train_batch_size from ultralytics.yolo.utils import colorstr, increment_path from ultralytics.yolo.utils.torch_utils import strip_optimizer, de_parallel, torch_distributed_zero_first @@ -133,7 +133,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio # Image size gs = max(int(model.stride.max()), 32) # grid size (max stride) - imgsz = check_img_size(opt.imgsz, gs, floor=gs * 2) # verify imgsz is gs-multiple + imgsz = check_imgsz(opt.imgsz, gs, floor=gs * 2) # verify imgsz is gs-multiple # Batch size if RANK == -1 and batch_size == -1: # single-GPU only, estimate best batch size diff --git a/segment/val.py b/segment/val.py index 9892b6984011..03edab725622 100644 --- a/segment/val.py +++ b/segment/val.py @@ -39,7 +39,7 @@ ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative import torch.nn.functional as F -from ultralytis.yolo.utils.checks import check_requirements, print_args, check_img_size +from ultralytis.yolo.utils.checks import check_requirements, print_args, check_imgsz from ultralytics.yolo.utils.torch_utils import de_parallel, select_device, smart_inference_mode from models.common import DetectMultiBackend @@ -183,7 +183,7 @@ def run( # Load model model = DetectMultiBackend(weights, device=device, dnn=dnn, data=data, fp16=half) stride, pt, jit, engine = model.stride, model.pt, model.jit, model.engine - imgsz = check_img_size(imgsz, s=stride) # check image size + imgsz = check_imgsz(imgsz, s=stride) # check image size half = model.fp16 # FP16 supported on limited backends with CUDA nm = de_parallel(model).model.model[-1].nm if isinstance(model, SegmentationModel) else 32 # number of masks if engine: diff --git a/train.py b/train.py index 57d3ce72c27b..59732093aa0a 100644 --- a/train.py +++ b/train.py @@ -34,10 +34,11 @@ from torch.optim import lr_scheduler from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights -from ultralytics.yolo.utils.checks import check_requirements, check_suffix, print_args, check_img_size +from ultralytics.yolo.utils.checks import check_requirements, check_suffix, print_args, check_imgsz from ultralytics.yolo.utils.torch_utils import (EarlyStopping, ModelEMA, de_parallel, select_device, strip_optimizer, torch_distributed_zero_first) from ultralytics.yolo.utils.autobatch import check_train_batch_size +from ultralytics.yolo.utils import colorstr FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory @@ -144,7 +145,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio # Image size gs = max(int(model.stride.max()), 32) # grid size (max stride) - imgsz = check_img_size(opt.imgsz, gs, floor=gs * 2) # verify imgsz is gs-multiple + imgsz = check_imgsz(opt.imgsz, gs, floor=gs * 2) # verify imgsz is gs-multiple # Batch size if RANK == -1 and batch_size == -1: # single-GPU only, estimate best batch size diff --git a/utils/augmentations.py b/utils/augmentations.py index 52e2e346e36e..c0dd9c9ea719 100644 --- a/utils/augmentations.py +++ b/utils/augmentations.py @@ -11,8 +11,10 @@ import torch import torchvision.transforms as T import torchvision.transforms.functional as TF +from ultralytics.yolo.utils import colorstr +from ultralytics.yolo.utils.checks import check_version -from utils.general import LOGGER, check_version, colorstr, resample_segments, segment2box, xywhn2xyxy +from utils.general import LOGGER, resample_segments, segment2box, xywhn2xyxy from utils.metrics import bbox_ioa IMAGENET_MEAN = 0.485, 0.456, 0.406 # RGB mean diff --git a/utils/general.py b/utils/general.py index 5f081f0e7436..47a4db38344b 100644 --- a/utils/general.py +++ b/utils/general.py @@ -35,7 +35,8 @@ import torch import torchvision import yaml -from ultralytics.yolo.utils.checks import check_requirements +from ultralytics.yolo.utils.checks import check_requirements, check_version +from ultralytics.yolo.utils import colorstr from utils import TryExcept, emojis from utils.downloads import curl_download, gsutil_getsize diff --git a/val.py b/val.py index 77e9255a9c5a..0c47d6bf9111 100644 --- a/val.py +++ b/val.py @@ -29,7 +29,7 @@ import numpy as np import torch from tqdm import tqdm -from ultralytics.yolo.utils.checks import check_requirements, print_args, check_img_size +from ultralytics.yolo.utils.checks import check_requirements, print_args, check_imgsz from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve() @@ -143,7 +143,7 @@ def run( # Load model model = DetectMultiBackend(weights, device=device, dnn=dnn, data=data, fp16=half) stride, pt, jit, engine = model.stride, model.pt, model.jit, model.engine - imgsz = check_img_size(imgsz, s=stride) # check image size + imgsz = check_imgsz(imgsz, s=stride) # check image size half = model.fp16 # FP16 supported on limited backends with CUDA if engine: batch_size = model.batch_size From 9c358a5818b4240b5a05214c2ee7c9d4af4a22a3 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 1 Jun 2023 05:15:51 +0000 Subject: [PATCH 15/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- classify/predict.py | 2 +- classify/val.py | 4 ++-- detect.py | 2 +- export.py | 4 +--- models/common.py | 7 +++---- models/yolo.py | 3 +-- segment/predict.py | 2 +- segment/train.py | 3 +-- segment/val.py | 3 +-- train.py | 6 +++--- utils/augmentations.py | 2 +- utils/general.py | 2 +- val.py | 2 +- 13 files changed, 18 insertions(+), 24 deletions(-) diff --git a/classify/predict.py b/classify/predict.py index d99b1a7b1cdb..942ee09592b2 100644 --- a/classify/predict.py +++ b/classify/predict.py @@ -36,7 +36,7 @@ import torch import torch.nn.functional as F -from ultralytics.yolo.utils.checks import check_requirements, print_args, check_imgsz, check_imshow +from ultralytics.yolo.utils.checks import check_imgsz, check_imshow, check_requirements, print_args from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode, strip_optimizer FILE = Path(__file__).resolve() diff --git a/classify/val.py b/classify/val.py index fd87aafc36b6..fba638cef0bf 100644 --- a/classify/val.py +++ b/classify/val.py @@ -27,9 +27,9 @@ import torch from tqdm import tqdm -from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode -from ultralytics.yolo.utils.checks import check_imgsz, check_requirements, print_args from ultralytics.yolo.utils import colorstr +from ultralytics.yolo.utils.checks import check_imgsz, check_requirements, print_args +from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory diff --git a/detect.py b/detect.py index 4adfc90f8eec..3609d1e0f2dc 100644 --- a/detect.py +++ b/detect.py @@ -36,7 +36,7 @@ import torch from ultralyitcs.yolo.utils import colorstr -from ultralytics.yolo.utils.checks import print_args, check_imgsz, check_imshow, check_requirements +from ultralytics.yolo.utils.checks import check_imgsz, check_imshow, check_requirements, print_args from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve() diff --git a/export.py b/export.py index 06dd5c4cc88e..82b647bd0bb3 100644 --- a/export.py +++ b/export.py @@ -61,10 +61,8 @@ from torch.utils.mobile_optimizer import optimize_for_mobile from ultraltics.yolo.utils import check_requirements, colorstr, file_size from ultralytics.nn.tasks import attempt_load_weights -from ultralytics.yolo.utils.checks import check_img_size, check_version, print_args +from ultralytics.yolo.utils.checks import check_img_size, check_imgsz, check_version, print_args from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode -from ultraltics.yolo.utils import file_size, check_requirements, colorstr -from ultralytics.yolo.utils.checks import print_args, check_imgsz, check_version FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory diff --git a/models/common.py b/models/common.py index 52623da2be6e..deb11cf3575e 100644 --- a/models/common.py +++ b/models/common.py @@ -24,14 +24,13 @@ from PIL import Image from torch.cuda import amp from ultralytics.nn.tasks import attempt_load_weights -from ultralytics.yolo.utils.checks import check_requirements, check_suffix, check_version from ultralytics.yolo.utils import colorstr +from ultralytics.yolo.utils.checks import check_requirements, check_suffix, check_version from utils import TryExcept from utils.dataloaders import exif_transpose, letterbox -from utils.general import (LOGGER, ROOT, Profile, - increment_path, is_jupyter, make_divisible, non_max_suppression, scale_boxes, xywh2xyxy, - xyxy2xywh, yaml_load) +from utils.general import (LOGGER, ROOT, Profile, increment_path, is_jupyter, make_divisible, non_max_suppression, + scale_boxes, xywh2xyxy, xyxy2xywh, yaml_load) from utils.plots import Annotator, colors, save_one_box from utils.torch_utils import copy_attr, smart_inference_mode diff --git a/models/yolo.py b/models/yolo.py index a61e7bfbc06d..c5a3c620fc5a 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -14,9 +14,8 @@ from copy import deepcopy from pathlib import Path -from ultralytics.yolo.utils.checks import print_args +from ultralytics.yolo.utils.checks import check_version, print_args from ultralytics.yolo.utils.torch_utils import select_device -from ultralytics.yolo.utils.checks import check_version FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory diff --git a/segment/predict.py b/segment/predict.py index 70b754acc419..ec87967f5bb3 100644 --- a/segment/predict.py +++ b/segment/predict.py @@ -36,7 +36,7 @@ import torch from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode, strip_optimizer -from ultrlalytics.yolo.utils.checks import print_args, check_imgsz, check_imshow +from ultrlalytics.yolo.utils.checks import check_imgsz, check_imshow, print_args FILE = Path(__file__).resolve() ROOT = FILE.parents[1] # YOLOv5 root directory diff --git a/segment/train.py b/segment/train.py index f32471b612fb..27e9bdc7e69d 100644 --- a/segment/train.py +++ b/segment/train.py @@ -34,9 +34,8 @@ from torch.optim import lr_scheduler from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights -from ultralytics.yolo.utils.checks import check_requirements, check_imgsz from ultralytics.yolo.utils.autobatch import check_train_batch_size -from ultralytics.yolo.utils.checks import check_img_size, check_requirements +from ultralytics.yolo.utils.checks import check_img_size, check_imgsz, check_requirements from ultralytics.yolo.utils.torch_utils import de_parallel, strip_optimizer, torch_distributed_zero_first FILE = Path(__file__).resolve() diff --git a/segment/val.py b/segment/val.py index 57919b50fee6..b280c2cc08bb 100644 --- a/segment/val.py +++ b/segment/val.py @@ -39,9 +39,8 @@ ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative import torch.nn.functional as F -from ultralytis.yolo.utils.checks import check_requirements, print_args, check_imgsz from ultralytics.yolo.utils.torch_utils import de_parallel, select_device, smart_inference_mode -from ultralytis.yolo.utils.checks import check_img_size, check_requirements, print_args +from ultralytis.yolo.utils.checks import check_img_size, check_imgsz, check_requirements, print_args from models.common import DetectMultiBackend from models.yolo import SegmentationModel diff --git a/train.py b/train.py index d9f157bb178f..519b3958eb2e 100644 --- a/train.py +++ b/train.py @@ -34,11 +34,11 @@ from torch.optim import lr_scheduler from tqdm import tqdm from ultralytics.nn.tasks import attempt_load_weights -from ultralytics.yolo.utils.checks import check_requirements, check_suffix, print_args, check_imgsz +from ultralytics.yolo.utils import colorstr +from ultralytics.yolo.utils.autobatch import check_train_batch_size +from ultralytics.yolo.utils.checks import check_imgsz, check_requirements, check_suffix, print_args from ultralytics.yolo.utils.torch_utils import (EarlyStopping, ModelEMA, de_parallel, select_device, strip_optimizer, torch_distributed_zero_first) -from ultralytics.yolo.utils.autobatch import check_train_batch_size -from ultralytics.yolo.utils import colorstr FILE = Path(__file__).resolve() ROOT = FILE.parents[0] # YOLOv5 root directory diff --git a/utils/augmentations.py b/utils/augmentations.py index c0dd9c9ea719..c76a91e0086c 100644 --- a/utils/augmentations.py +++ b/utils/augmentations.py @@ -12,7 +12,7 @@ import torchvision.transforms as T import torchvision.transforms.functional as TF from ultralytics.yolo.utils import colorstr -from ultralytics.yolo.utils.checks import check_version +from ultralytics.yolo.utils.checks import check_version from utils.general import LOGGER, resample_segments, segment2box, xywhn2xyxy from utils.metrics import bbox_ioa diff --git a/utils/general.py b/utils/general.py index 47a4db38344b..946bd34b9d67 100644 --- a/utils/general.py +++ b/utils/general.py @@ -35,8 +35,8 @@ import torch import torchvision import yaml -from ultralytics.yolo.utils.checks import check_requirements, check_version from ultralytics.yolo.utils import colorstr +from ultralytics.yolo.utils.checks import check_requirements, check_version from utils import TryExcept, emojis from utils.downloads import curl_download, gsutil_getsize diff --git a/val.py b/val.py index 67d6aeb3c1c2..d53adb7fa4b3 100644 --- a/val.py +++ b/val.py @@ -29,7 +29,7 @@ import numpy as np import torch from tqdm import tqdm -from ultralytics.yolo.utils.checks import check_requirements, print_args, check_imgsz +from ultralytics.yolo.utils.checks import check_imgsz, check_requirements, print_args from ultralytics.yolo.utils.torch_utils import select_device, smart_inference_mode FILE = Path(__file__).resolve()