Skip to content

Commit

Permalink
Add ultralytics pip package
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher committed May 14, 2023
1 parent e382d4c commit 37f4a29
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 54 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ thop>=0.1.1 # FLOPs computation
torch>=1.7.0 # see https://pytorch.org/get-started/locally (recommended)
torchvision>=0.8.1
tqdm>=4.64.0
ultralytics>=8.0.99
# protobuf<=3.20.1 # https://github.com/ultralytics/yolov5/issues/8012

# Logging ---------------------------------------------------------------------
Expand Down Expand Up @@ -46,4 +47,3 @@ setuptools>=65.5.1 # Snyk vulnerability fix
# mss # screenshots
# albumentations>=1.0.3
# pycocotools>=2.0.6 # COCO mAP
# ultralytics # HUB https://hub.ultralytics.com
56 changes: 3 additions & 53 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from tarfile import is_tarfile
from typing import Optional
from zipfile import ZipFile, is_zipfile
from ultralytics.yolo.utils.checks import check_requirements

import cv2
import numpy as np
Expand Down Expand Up @@ -138,12 +139,12 @@ def set_logging(name=LOGGING_NAME, verbose=True):
name: {
'class': 'logging.StreamHandler',
'formatter': name,
'level': level,}},
'level': level, }},
'loggers': {
name: {
'level': level,
'handlers': [name],
'propagate': False,}}})
'propagate': False, }}})


set_logging(LOGGING_NAME) # run before defining LOGGER
Expand Down Expand Up @@ -387,57 +388,6 @@ def check_version(current='0.0.0', minimum='0.0.0', name='version ', pinned=Fals
return result


@TryExcept()
def check_requirements(requirements=ROOT / 'requirements.txt', exclude=(), install=True, cmds=''):
"""
Check if installed dependencies meet YOLOv5 requirements and attempt to auto-update if needed.
Args:
requirements (Union[Path, str, List[str]]): Path to a requirements.txt file, a single package requirement as a
string, or a list of package requirements as strings.
exclude (Tuple[str]): Tuple of package names to exclude from checking.
install (bool): If True, attempt to auto-update packages that don't meet requirements.
cmds (str): Additional commands to pass to the pip install command when auto-updating.
Returns:
None
"""
prefix = colorstr('red', 'bold', 'requirements:')
check_python() # check python version
file = None
if isinstance(requirements, Path): # requirements.txt file
file = requirements.resolve()
assert file.exists(), f'{prefix} {file} not found, check failed.'
with file.open() as f:
requirements = [f'{x.name}{x.specifier}' for x in pkg.parse_requirements(f) if x.name not in exclude]
elif isinstance(requirements, str):
requirements = [requirements]

s = '' # console string
n = 0 # number of packages updates
for r in requirements:
try:
pkg.require(r)
except (pkg.VersionConflict, pkg.DistributionNotFound): # exception if requirements not met
try: # attempt to import (slower but more accurate)
import importlib
importlib.import_module(next(pkg.parse_requirements(r)).name)
except ImportError:
s += f'"{r}" '
n += 1

if s and install and AUTOINSTALL: # check environment variable
LOGGER.info(f"{prefix} YOLOv5 requirement{'s' * (n > 1)} {s}not found, attempting AutoUpdate...")
try:
assert check_online(), 'AutoUpdate skipped (offline)'
LOGGER.info(subprocess.check_output(f'pip install {s} {cmds}', shell=True).decode())
s = f"{prefix} {n} package{'s' * (n > 1)} updated per {file or requirements}\n" \
f"{prefix} ⚠️ {colorstr('bold', 'Restart runtime or rerun command for updates to take effect')}\n"
LOGGER.info(s)
except Exception as e:
LOGGER.warning(f'{prefix}{e}')


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
Expand Down

0 comments on commit 37f4a29

Please sign in to comment.