Skip to content

Commit

Permalink
Update check_requirements() with cmds=() argument (ultralytics#7543)
Browse files Browse the repository at this point in the history
  • Loading branch information
glenn-jocher committed Apr 22, 2022
1 parent 94a0d8b commit f387ffc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
10 changes: 2 additions & 8 deletions export.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,8 @@ def export_engine(model, im, file, train, half, simplify, workspace=4, verbose=F
# YOLOv5 TensorRT export https://developer.nvidia.com/tensorrt
try:
assert im.device.type != 'cpu', 'export running on CPU but must be on GPU, i.e. `python export.py --device 0`'
try:
import tensorrt as trt
except Exception:
s = f"\n{prefix} tensorrt not found and is required by YOLOv5"
LOGGER.info(f"{s}, attempting auto-update...")
r = '-U nvidia-tensorrt --index-url https://pypi.ngc.nvidia.com'
LOGGER.info(subprocess.check_output(f"pip install {r}", shell=True).decode())
import tensorrt as trt
check_requirements(('nvidia-tensorrt',), cmds=('-U --index-url https://pypi.ngc.nvidia.com',))
import tensorrt as trt

if trt.__version__[0] == '7': # TensorRT 7 handling https://github.com/ultralytics/yolov5/issues/6012
grid = model.model[-1].anchor_grid
Expand Down
6 changes: 3 additions & 3 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def check_version(current='0.0.0', minimum='0.0.0', name='version ', pinned=Fals


@try_except
def check_requirements(requirements=ROOT / 'requirements.txt', exclude=(), install=True):
def check_requirements(requirements=ROOT / 'requirements.txt', exclude=(), install=True, cmds=()):
# Check installed dependencies meet requirements (pass *.txt file or list of packages)
prefix = colorstr('red', 'bold', 'requirements:')
check_python() # check python version
Expand All @@ -334,7 +334,7 @@ def check_requirements(requirements=ROOT / 'requirements.txt', exclude=(), insta
requirements = [x for x in requirements if x not in exclude]

n = 0 # number of packages updates
for r in requirements:
for i, r in enumerate(requirements):
try:
pkg.require(r)
except Exception: # DistributionNotFound or VersionConflict if requirements not met
Expand All @@ -343,7 +343,7 @@ def check_requirements(requirements=ROOT / 'requirements.txt', exclude=(), insta
LOGGER.info(f"{s}, attempting auto-update...")
try:
assert check_online(), f"'pip install {r}' skipped (offline)"
LOGGER.info(check_output(f"pip install '{r}'", shell=True).decode())
LOGGER.info(check_output(f"pip install '{r}' {cmds[i] if cmds else ''}", shell=True).decode())
n += 1
except Exception as e:
LOGGER.warning(f'{prefix} {e}')
Expand Down

0 comments on commit f387ffc

Please sign in to comment.