Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Kalen Michael <kalenmike@gmail.com>
This commit is contained in:
Glenn Jocher
2023-01-09 23:22:33 +01:00
committed by GitHub
parent 6feba17760
commit 422c49d439
97 changed files with 224 additions and 757 deletions

View File

@ -1,6 +1,9 @@
__version__ = "8.0.0.dev0"
# Ultralytics YOLO 🚀, GPL-3.0 license
__version__ = "8.0.0"
from ultralytics.hub import checks
from ultralytics.yolo.engine.model import YOLO
from ultralytics.yolo.utils import ops
__all__ = ["__version__", "YOLO", "hub"] # allow simpler import
__all__ = ["__version__", "YOLO", "hub", "checks"] # allow simpler import

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import os
import shutil

View File

@ -1,7 +1,8 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import requests
from ultralytics.hub.config import HUB_API_ROOT
from ultralytics.hub.utils import request_with_credentials
from ultralytics.hub.utils import HUB_API_ROOT, request_with_credentials
from ultralytics.yolo.utils import is_colab
API_KEY_PATH = "https://hub.ultralytics.com/settings?tab=api+keys"

View File

@ -1,12 +0,0 @@
import os
# Global variables
REPO_URL = "https://github.com/ultralytics/yolov5.git"
REPO_BRANCH = "ultralytics/HUB" # "master"
ENVIRONMENT = os.environ.get("ULTRALYTICS_ENV", "production")
if ENVIRONMENT == 'production':
HUB_API_ROOT = "https://api.ultralytics.com"
else:
HUB_API_ROOT = "http://127.0.0.1:8000"
print(f'Connected to development server on {HUB_API_ROOT}')

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import signal
import sys
from pathlib import Path
@ -6,8 +8,7 @@ from time import sleep
import requests
from ultralytics import __version__
from ultralytics.hub.config import HUB_API_ROOT
from ultralytics.hub.utils import check_dataset_disk_space, smart_request
from ultralytics.hub.utils import HUB_API_ROOT, check_dataset_disk_space, smart_request
from ultralytics.yolo.utils import LOGGER, is_colab, threaded
AGENT_NAME = f'python-{__version__}-colab' if is_colab() else f'python-{__version__}-local'

View File

@ -1,14 +1,17 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import os
import shutil
import threading
import time
import requests
from ultralytics.hub.config import HUB_API_ROOT
from ultralytics.yolo.utils import DEFAULT_CONFIG_DICT, LOGGER, RANK, SETTINGS, colorstr, emojis
from ultralytics.yolo.utils import DEFAULT_CONFIG_DICT, LOGGER, RANK, SETTINGS, TryExcept, colorstr, emojis
PREFIX = colorstr('Ultralytics: ')
HELP_MSG = 'If this issue persists please visit https://github.com/ultralytics/hub/issues for assistance.'
HUB_API_ROOT = os.environ.get("ULTRALYTICS_HUB_API", "https://api.ultralytics.com")
def check_dataset_disk_space(url='https://github.com/ultralytics/yolov5/releases/download/v1.0/coco128.zip', sf=2.0):
@ -90,7 +93,6 @@ def smart_request(*args, retry=3, timeout=30, thread=True, code=-1, method="post
requests.Response: The HTTP response object. If the request is executed in a separate thread, returns None.
"""
retry_codes = (408, 500) # retry only these codes
methods = {'post': requests.post, 'get': requests.get} # request methods
def func(*func_args, **func_kwargs):
r = None # response
@ -98,7 +100,10 @@ def smart_request(*args, retry=3, timeout=30, thread=True, code=-1, method="post
for i in range(retry + 1):
if (time.time() - t0) > timeout:
break
r = methods[method](*func_args, **func_kwargs) # i.e. post(url, data, json, files)
if method == 'post':
r = requests.post(*func_args, **func_kwargs) # i.e. post(url, data, json, files)
elif method == 'get':
r = requests.get(*func_args, **func_kwargs) # i.e. get(url, data, json, files)
if r.status_code == 200:
break
try:
@ -125,7 +130,8 @@ def smart_request(*args, retry=3, timeout=30, thread=True, code=-1, method="post
return func(*args, **kwargs)
def sync_analytics(cfg, all_keys=False, enabled=False):
@TryExcept()
def sync_analytics(cfg, all_keys=False, enabled=True):
"""
Sync analytics data if enabled in the global settings
@ -137,8 +143,8 @@ def sync_analytics(cfg, all_keys=False, enabled=False):
if SETTINGS['sync'] and RANK in {-1, 0} and enabled:
cfg = dict(cfg) # convert type from DictConfig to dict
if not all_keys:
cfg = {k: v for k, v in cfg.items() if v != DEFAULT_CONFIG_DICT[k]} # retain only non-default values
cfg = {k: v for k, v in cfg.items() if v != DEFAULT_CONFIG_DICT.get(k, None)} # retain non-default values
cfg['uuid'] = SETTINGS['uuid'] # add the device UUID to the configuration data
# Send a request to the HUB API to sync the analytics data
smart_request(f'{HUB_API_ROOT}/v1/usage/anonymous', data=cfg, headers=None, code=3, retry=0, verbose=False)
# Send a request to the HUB API to sync analytics
smart_request(f'{HUB_API_ROOT}/v1/usage/anonymous', json=cfg, headers=None, code=3, retry=0, verbose=False)

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import json
import platform
from collections import OrderedDict, namedtuple
@ -65,6 +67,7 @@ class AutoBackend(nn.Module):
names = model.module.names if hasattr(model, 'module') else model.names # get class names
model.half() if fp16 else model.float()
self.model = model # explicitly assign for to(), cpu(), cuda(), half()
pt = True
elif pt: # PyTorch
from ultralytics.nn.tasks import attempt_load_weights
model = attempt_load_weights(weights if isinstance(weights, list) else w,

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
"""
Common modules
"""

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import contextlib
from copy import deepcopy

View File

@ -1 +1,3 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
from . import v8

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import shutil
from pathlib import Path

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
from pathlib import Path
from typing import Dict, Union

View File

@ -1,4 +1,4 @@
# YOLO 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Default training settings and hyperparameters for medium-augmentation COCO training
task: "detect" # choices=['detect', 'segment', 'classify', 'init'] # init is a special case. Specify task to run.

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import sys
from difflib import get_close_matches
from textwrap import dedent

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
from .base import BaseDataset
from .build import build_classification_dataloader, build_dataloader
from .dataset import ClassificationDataset, SemanticDataset, YOLODataset

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import math
import random
from copy import deepcopy

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import glob
import math
import os

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import os
import random

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import glob
import math
import os

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
"""
Image augmentation functions
"""

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
"""
Dataloaders and dataset utils
"""

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
from itertools import repeat
from multiprocessing.pool import Pool
from pathlib import Path

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import collections
from copy import deepcopy

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# COCO 2017 dataset http://cocodataset.org by Microsoft
# Example usage: python train.py --data coco.yaml
# parent

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# COCO128-seg dataset https://www.kaggle.com/ultralytics/coco128 (first 128 images from COCO train2017) by Ultralytics
# Example usage: python train.py --data coco128.yaml
# parent

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# COCO128 dataset https://www.kaggle.com/ultralytics/coco128 (first 128 images from COCO train2017) by Ultralytics
# Example usage: python train.py --data coco128.yaml
# parent

View File

@ -1,5 +1,5 @@
#!/bin/bash
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Download latest models from https://github.com/ultralytics/yolov5/releases
# Example usage: bash data/scripts/download_weights.sh
# parent

View File

@ -1,5 +1,5 @@
#!/bin/bash
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Download COCO 2017 dataset http://cocodataset.org
# Example usage: bash data/scripts/get_coco.sh
# parent

View File

@ -1,5 +1,5 @@
#!/bin/bash
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Download COCO128 dataset https://www.kaggle.com/ultralytics/coco128 (first 128 images from COCO train2017)
# Example usage: bash data/scripts/get_coco128.sh
# parent

View File

@ -1,5 +1,5 @@
#!/bin/bash
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Download ILSVRC2012 ImageNet dataset https://image-net.org
# Example usage: bash data/scripts/get_imagenet.sh
# parent

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import contextlib
import hashlib
import os

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
"""
Export a YOLOv5 PyTorch model to other formats. TensorFlow exports authored by https://github.com/zldrobit

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
from pathlib import Path
from ultralytics import yolo # noqa

View File

@ -1,4 +1,4 @@
# predictor engine by Ultralytics
# Ultralytics YOLO 🚀, GPL-3.0 license
"""
Run prediction on images, videos, directories, globs, YouTube, webcam, streams, etc.
Usage - sources:

View File

@ -1,3 +1,4 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
"""
Simple training loop; Boilerplate that could apply to any arbitrary neural network,
"""

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import json
from collections import defaultdict
from pathlib import Path
@ -86,6 +88,7 @@ class BaseValidator:
self.model = model
self.loss = torch.zeros_like(trainer.loss_items, device=trainer.device)
self.args.plots = trainer.epoch == trainer.epochs - 1 # always plot final epoch
model.eval()
else:
callbacks.add_integration_callbacks(self)
self.run_callbacks('on_val_start')
@ -106,17 +109,17 @@ class BaseValidator:
f'Forcing --batch-size 1 square inference (1,3,{imgsz},{imgsz}) for non-PyTorch models')
if isinstance(self.args.data, str) and self.args.data.endswith(".yaml"):
data = check_dataset_yaml(self.args.data)
self.data = check_dataset_yaml(self.args.data)
else:
data = check_dataset(self.args.data)
self.data = check_dataset(self.args.data)
if self.device.type == 'cpu':
self.args.workers = 0 # faster CPU val as time dominated by inference, not dataloading
self.dataloader = self.dataloader or \
self.get_dataloader(data.get("val") or data.set("test"), self.args.batch)
self.data = data
self.get_dataloader(self.data.get("val") or self.data.set("test"), self.args.batch)
model.eval()
model.eval()
model.warmup(imgsz=(1 if pt else self.args.batch, 3, imgsz, imgsz)) # warmup
dt = Profile(), Profile(), Profile(), Profile()
n_batches = len(self.dataloader)

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import contextlib
import inspect
import logging.config

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
"""
Auto-batch utils
"""

View File

@ -1,4 +1,7 @@
# Ultralytics YOLO base callbacks
# Ultralytics YOLO 🚀, GPL-3.0 license
"""
Base callbacks
"""
# Trainer callbacks ----------------------------------------------------------------------------------------------------

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
from ultralytics.yolo.utils.torch_utils import get_flops, get_num_params
try:

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
from ultralytics.yolo.utils.torch_utils import get_flops, get_num_params
try:

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import json
from time import time

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
from torch.utils.tensorboard import SummaryWriter
writer = None # TensorBoard SummaryWriter instance

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
from ultralytics.yolo.utils.torch_utils import get_flops, get_num_params
try:

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import glob
import inspect
import math
@ -62,8 +64,7 @@ def check_imgsz(imgsz, stride=32, min_dim=1, floor=0):
LOGGER.warning(f'WARNING ⚠️ --img-size {imgsz} must be multiple of max stride {stride}, updating to {sz}')
# Add missing dimensions if necessary
if min_dim == 2 and len(sz) == 1:
sz = [sz[0], sz[0]]
sz = [sz[0], sz[0]] if min_dim == 2 and len(sz) == 1 else sz[0] if min_dim == 1 and len(sz) == 1 else sz
return sz

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import os
import shutil
import socket

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import logging
import os
import subprocess

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import contextlib
import glob
import os

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
from collections import abc
from itertools import repeat
from numbers import Number

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import torch
import torch.nn as nn
import torch.nn.functional as F

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
"""
Model validation metrics
"""

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import contextlib
import math
import re

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import contextlib
import math
from pathlib import Path

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import torch
import torch.nn as nn
import torch.nn.functional as F

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import math
import os
import platform
@ -59,7 +61,7 @@ def DDP_model(model):
def select_device(device='', batch_size=0, newline=False):
# device = None or 'cpu' or 0 or '0' or '0,1,2,3'
ver = git_describe() or ultralytics.__version__ # git commit or pip package version
s = f'Ultralytics YOLO 🚀 {ver} Python-{platform.python_version()} torch-{torch.__version__} '
s = f'Ultralytics YOLOv{ver} 🚀 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)

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
from pathlib import Path
from ultralytics.yolo.v8 import classify, detect, segment

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
from ultralytics.yolo.v8.classify.predict import ClassificationPredictor, predict
from ultralytics.yolo.v8.classify.train import ClassificationTrainer, train
from ultralytics.yolo.v8.classify.val import ClassificationValidator, val

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import hydra
import torch

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import hydra
import torch
import torchvision

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import hydra
from ultralytics.yolo.data import build_classification_dataloader

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
from .predict import DetectionPredictor, predict
from .train import DetectionTrainer, train
from .val import DetectionValidator, val

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import hydra
import torch

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
from copy import copy
import hydra

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import os
from pathlib import Path

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Parameters
nc: 1000 # number of classes

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Parameters
nc: 1000 # number of classes

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Parameters
nc: 1000 # number of classes

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Parameters
nc: 1000 # number of classes

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Parameters
nc: 1000 # number of classes

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Parameters
nc: 80 # number of classes

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Parameters
nc: 80 # number of classes

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Parameters
nc: 80 # number of classes

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Parameters
nc: 80 # number of classes

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Parameters
nc: 80 # number of classes

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Parameters
nc: 80 # number of classes

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Parameters
nc: 80 # number of classes

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Parameters
nc: 80 # number of classes

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Parameters
nc: 80 # number of classes

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Parameters
nc: 80 # number of classes

View File

@ -1,4 +1,4 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Ultralytics YOLO 🚀, GPL-3.0 license
# Parameters
nc: 80 # number of classes

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
from .predict import SegmentationPredictor, predict
from .train import SegmentationTrainer, train
from .val import SegmentationValidator, val

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import hydra
import torch

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
from copy import copy
import hydra

View File

@ -1,3 +1,5 @@
# Ultralytics YOLO 🚀, GPL-3.0 license
import os
from multiprocessing.pool import ThreadPool
from pathlib import Path