Simplify `check_requirements()` usage (#4855)
Browse files* Simplify `check_requirements()` usage
* remove assert, print()
- detect.py +1 -1
- hubconf.py +1 -1
- train.py +1 -1
- utils/autoanchor.py +1 -1
- utils/general.py +4 -1
- val.py +1 -1
detect.py
CHANGED
@@ -286,7 +286,7 @@ def parse_opt():
|
|
286 |
|
287 |
|
288 |
def main(opt):
|
289 |
-
check_requirements(
|
290 |
run(**vars(opt))
|
291 |
|
292 |
|
|
|
286 |
|
287 |
|
288 |
def main(opt):
|
289 |
+
check_requirements(exclude=('tensorboard', 'thop'))
|
290 |
run(**vars(opt))
|
291 |
|
292 |
|
hubconf.py
CHANGED
@@ -34,7 +34,7 @@ def _create(name, pretrained=True, channels=3, classes=80, autoshape=True, verbo
|
|
34 |
from utils.torch_utils import select_device
|
35 |
|
36 |
file = Path(__file__).resolve()
|
37 |
-
check_requirements(
|
38 |
set_logging(verbose=verbose)
|
39 |
|
40 |
save_dir = Path('') if str(name).endswith('.pt') else file.parent
|
|
|
34 |
from utils.torch_utils import select_device
|
35 |
|
36 |
file = Path(__file__).resolve()
|
37 |
+
check_requirements(exclude=('tensorboard', 'thop', 'opencv-python'))
|
38 |
set_logging(verbose=verbose)
|
39 |
|
40 |
save_dir = Path('') if str(name).endswith('.pt') else file.parent
|
train.py
CHANGED
@@ -476,7 +476,7 @@ def main(opt, callbacks=Callbacks()):
|
|
476 |
if RANK in [-1, 0]:
|
477 |
print_args(FILE.stem, opt)
|
478 |
check_git_status()
|
479 |
-
check_requirements(
|
480 |
|
481 |
# Resume
|
482 |
if opt.resume and not check_wandb_resume(opt) and not opt.evolve: # resume an interrupted run
|
|
|
476 |
if RANK in [-1, 0]:
|
477 |
print_args(FILE.stem, opt)
|
478 |
check_git_status()
|
479 |
+
check_requirements(exclude=['thop'])
|
480 |
|
481 |
# Resume
|
482 |
if opt.resume and not check_wandb_resume(opt) and not opt.evolve: # resume an interrupted run
|
utils/autoanchor.py
CHANGED
@@ -127,7 +127,7 @@ def kmean_anchors(dataset='./data/coco128.yaml', n=9, img_size=640, thr=4.0, gen
|
|
127 |
print(f'{prefix}Running kmeans for {n} anchors on {len(wh)} points...')
|
128 |
s = wh.std(0) # sigmas for whitening
|
129 |
k, dist = kmeans(wh / s, n, iter=30) # points, mean distance
|
130 |
-
assert len(k) == n,
|
131 |
k *= s
|
132 |
wh = torch.tensor(wh, dtype=torch.float32) # filtered
|
133 |
wh0 = torch.tensor(wh0, dtype=torch.float32) # unfiltered
|
|
|
127 |
print(f'{prefix}Running kmeans for {n} anchors on {len(wh)} points...')
|
128 |
s = wh.std(0) # sigmas for whitening
|
129 |
k, dist = kmeans(wh / s, n, iter=30) # points, mean distance
|
130 |
+
assert len(k) == n, f'{prefix}ERROR: scipy.cluster.vq.kmeans requested {n} points but returned only {len(k)}'
|
131 |
k *= s
|
132 |
wh = torch.tensor(wh, dtype=torch.float32) # filtered
|
133 |
wh0 = torch.tensor(wh0, dtype=torch.float32) # unfiltered
|
utils/general.py
CHANGED
@@ -37,6 +37,9 @@ pd.options.display.max_columns = 10
|
|
37 |
cv2.setNumThreads(0) # prevent OpenCV from multithreading (incompatible with PyTorch DataLoader)
|
38 |
os.environ['NUMEXPR_MAX_THREADS'] = str(min(os.cpu_count(), 8)) # NumExpr max threads
|
39 |
|
|
|
|
|
|
|
40 |
|
41 |
class Profile(contextlib.ContextDecorator):
|
42 |
# 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
|
|
222 |
|
223 |
|
224 |
@try_except
|
225 |
-
def check_requirements(requirements='requirements.txt', exclude=(), install=True):
|
226 |
# Check installed dependencies meet requirements (pass *.txt file or list of packages)
|
227 |
prefix = colorstr('red', 'bold', 'requirements:')
|
228 |
check_python() # check python version
|
|
|
37 |
cv2.setNumThreads(0) # prevent OpenCV from multithreading (incompatible with PyTorch DataLoader)
|
38 |
os.environ['NUMEXPR_MAX_THREADS'] = str(min(os.cpu_count(), 8)) # NumExpr max threads
|
39 |
|
40 |
+
FILE = Path(__file__).resolve()
|
41 |
+
ROOT = FILE.parents[1] # YOLOv5 root directory
|
42 |
+
|
43 |
|
44 |
class Profile(contextlib.ContextDecorator):
|
45 |
# Usage: @Profile() decorator or 'with Profile():' context manager
|
|
|
225 |
|
226 |
|
227 |
@try_except
|
228 |
+
def check_requirements(requirements=ROOT / 'requirements.txt', exclude=(), install=True):
|
229 |
# Check installed dependencies meet requirements (pass *.txt file or list of packages)
|
230 |
prefix = colorstr('red', 'bold', 'requirements:')
|
231 |
check_python() # check python version
|
val.py
CHANGED
@@ -327,7 +327,7 @@ def parse_opt():
|
|
327 |
|
328 |
def main(opt):
|
329 |
set_logging()
|
330 |
-
check_requirements(
|
331 |
|
332 |
if opt.task in ('train', 'val', 'test'): # run normally
|
333 |
run(**vars(opt))
|
|
|
327 |
|
328 |
def main(opt):
|
329 |
set_logging()
|
330 |
+
check_requirements(exclude=('tensorboard', 'thop'))
|
331 |
|
332 |
if opt.task in ('train', 'val', 'test'): # run normally
|
333 |
run(**vars(opt))
|