Skip to content

Commit

Permalink
Add ultralytics pip package (#11529)
Browse files Browse the repository at this point in the history
* Add ultralytics pip package

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

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

* Add requirements.txt locations

* Update requirements.txt

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>

---------

Signed-off-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
glenn-jocher and pre-commit-ci[bot] committed May 14, 2023
1 parent 54e9515 commit 5deff14
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 55 deletions.
2 changes: 1 addition & 1 deletion classify/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def main(opt):
if RANK in {-1, 0}:
print_args(vars(opt))
check_git_status()
check_requirements()
check_requirements(ROOT / 'requirements.txt')

# DDP mode
device = select_device(opt.device, batch_size=opt.batch_size)
Expand Down
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.100
# 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
2 changes: 1 addition & 1 deletion segment/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def main(opt, callbacks=Callbacks()):
if RANK in {-1, 0}:
print_args(vars(opt))
check_git_status()
check_requirements()
check_requirements(ROOT / 'requirements.txt')

# Resume
if opt.resume and not opt.evolve: # resume from specified or most recent last.pt
Expand Down
2 changes: 1 addition & 1 deletion train.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def main(opt, callbacks=Callbacks()):
if RANK in {-1, 0}:
print_args(vars(opt))
check_git_status()
check_requirements()
check_requirements(ROOT / 'requirements.txt')

# Resume (from specified or most recent last.pt)
if opt.resume and not check_comet_resume(opt) and not opt.evolve:
Expand Down
52 changes: 1 addition & 51 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import torch
import torchvision
import yaml
from ultralytics.yolo.utils.checks import check_requirements

from utils import TryExcept, emojis
from utils.downloads import curl_download, gsutil_getsize
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 5deff14

Please sign in to comment.