Skip to content

Commit

Permalink
Simplify check_requirements() usage (ultralytics#4855)
Browse files Browse the repository at this point in the history
* Simplify `check_requirements()` usage

* remove assert, print()
  • Loading branch information
glenn-jocher authored and CesarBazanAV committed Sep 29, 2021
1 parent e682e4d commit 40f424e
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def parse_opt():


def main(opt):
check_requirements(requirements=ROOT / 'requirements.txt', exclude=('tensorboard', 'thop'))
check_requirements(exclude=('tensorboard', 'thop'))
run(**vars(opt))


Expand Down
2 changes: 1 addition & 1 deletion hubconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo
from utils.torch_utils import select_device

file = Path(__file__).resolve()
check_requirements(requirements=file.parent / 'requirements.txt', exclude=('tensorboard', 'thop', 'opencv-python'))
check_requirements(exclude=('tensorboard', 'thop', 'opencv-python'))
set_logging(verbose=verbose)

save_dir = Path('') if str(name).endswith('.pt') else file.parent
Expand Down
2 changes: 1 addition & 1 deletion train.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def main(opt, callbacks=Callbacks()):
if RANK in [-1, 0]:
print_args(FILE.stem, opt)
check_git_status()
check_requirements(requirements=ROOT / 'requirements.txt', exclude=['thop'])
check_requirements(exclude=['thop'])

# Resume
if opt.resume and not check_wandb_resume(opt) and not opt.evolve: # resume an interrupted run
Expand Down
2 changes: 1 addition & 1 deletion utils/autoanchor.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def print_results(k):
print(f'{prefix}Running kmeans for {n} anchors on {len(wh)} points...')
s = wh.std(0) # sigmas for whitening
k, dist = kmeans(wh / s, n, iter=30) # points, mean distance
assert len(k) == n, print(f'{prefix}ERROR: scipy.cluster.vq.kmeans requested {n} points but returned only {len(k)}')
assert len(k) == n, f'{prefix}ERROR: scipy.cluster.vq.kmeans requested {n} points but returned only {len(k)}'
k *= s
wh = torch.tensor(wh, dtype=torch.float32) # filtered
wh0 = torch.tensor(wh0, dtype=torch.float32) # unfiltered
Expand Down
5 changes: 4 additions & 1 deletion utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
cv2.setNumThreads(0) # prevent OpenCV from multithreading (incompatible with PyTorch DataLoader)
os.environ['NUMEXPR_MAX_THREADS'] = str(min(os.cpu_count(), 8)) # NumExpr max threads

FILE = Path(__file__).resolve()
ROOT = FILE.parents[1] # YOLOv5 root directory


class Profile(contextlib.ContextDecorator):
# Usage: @Profile() decorator or 'with Profile():' context manager
Expand Down Expand Up @@ -222,7 +225,7 @@ def check_version(current='0.0.0', minimum='0.0.0', name='version ', pinned=Fals


@try_except
def check_requirements(requirements='requirements.txt', exclude=(), install=True):
def check_requirements(requirements=ROOT / 'requirements.txt', exclude=(), install=True):
# Check installed dependencies meet requirements (pass *.txt file or list of packages)
prefix = colorstr('red', 'bold', 'requirements:')
check_python() # check python version
Expand Down
2 changes: 1 addition & 1 deletion val.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def parse_opt():

def main(opt):
set_logging()
check_requirements(requirements=ROOT / 'requirements.txt', exclude=('tensorboard', 'thop'))
check_requirements(exclude=('tensorboard', 'thop'))

if opt.task in ('train', 'val', 'test'): # run normally
run(**vars(opt))
Expand Down

0 comments on commit 40f424e

Please sign in to comment.