Simplify `check_requirements()` usage (#4855)

* Simplify `check_requirements()` usage

* remove assert, print()
pull/4856/head
Glenn Jocher 2021-09-18 18:34:30 +02:00 committed by GitHub
parent 4d1a2ac87e
commit 4c839eeb10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 6 deletions

View File

@ -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))

View File

@ -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

View File

@ -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

View File

@ -127,7 +127,7 @@ def kmean_anchors(dataset='./data/coco128.yaml', n=9, img_size=640, thr=4.0, gen
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

View File

@ -37,6 +37,9 @@ pd.options.display.max_columns = 10
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
@ -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

2
val.py
View File

@ -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))