glenn-jocher pre-commit-ci[bot] commited on
Commit
7d56d45
β€’
1 Parent(s): 581dc30

Add hardware checks to `notebook_init()` (#5919)

Browse files

* Update notebook

* Update notebook

* update string

* update string

* Updates

* Updates

* Updates

* check both ipython and psutil

* remove sample_data if is_colab

* cleanup

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

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

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

Files changed (2) hide show
  1. tutorial.ipynb +2 -1
  2. utils/__init__.py +25 -6
tutorial.ipynb CHANGED
@@ -409,6 +409,7 @@
409
  "%cd yolov5\n",
410
  "%pip install -qr requirements.txt # install\n",
411
  "\n",
 
412
  "from yolov5 import utils\n",
413
  "display = utils.notebook_init() # checks"
414
  ],
@@ -983,7 +984,7 @@
983
  "source": [
984
  "# Reproduce\n",
985
  "for x in 'yolov5s', 'yolov5m', 'yolov5l', 'yolov5x':\n",
986
- " !python val.py --weights {x}.pt --data coco.yaml --img 640 --conf 0.25 --iou 0.45 # speed\n",
987
  " !python val.py --weights {x}.pt --data coco.yaml --img 640 --conf 0.001 --iou 0.65 # mAP"
988
  ],
989
  "execution_count": null,
 
409
  "%cd yolov5\n",
410
  "%pip install -qr requirements.txt # install\n",
411
  "\n",
412
+ "import torch\n",
413
  "from yolov5 import utils\n",
414
  "display = utils.notebook_init() # checks"
415
  ],
 
984
  "source": [
985
  "# Reproduce\n",
986
  "for x in 'yolov5s', 'yolov5m', 'yolov5l', 'yolov5x':\n",
987
+ " !python val.py --weights {x}.pt --data coco.yaml --img 640 --task speed # speed\n",
988
  " !python val.py --weights {x}.pt --data coco.yaml --img 640 --conf 0.001 --iou 0.65 # mAP"
989
  ],
990
  "execution_count": null,
utils/__init__.py CHANGED
@@ -4,15 +4,34 @@ utils/initialization
4
  """
5
 
6
 
7
- def notebook_init():
8
- # For YOLOv5 notebooks
9
  print('Checking setup...')
 
 
 
 
 
 
 
 
 
10
  from IPython import display # to display images and clear console output
11
 
12
- from utils.general import emojis
13
- from utils.torch_utils import select_device # YOLOv5 imports
 
 
 
 
 
 
 
 
 
 
 
14
 
15
- display.clear_output()
16
  select_device(newline=False)
17
- print(emojis('Setup complete βœ…'))
18
  return display
 
4
  """
5
 
6
 
7
+ def notebook_init(verbose=True):
8
+ # Check system software and hardware
9
  print('Checking setup...')
10
+
11
+ import os
12
+ import shutil
13
+
14
+ from utils.general import check_requirements, emojis, is_colab
15
+ from utils.torch_utils import select_device # imports
16
+
17
+ check_requirements(('psutil', 'IPython'))
18
+ import psutil
19
  from IPython import display # to display images and clear console output
20
 
21
+ if is_colab():
22
+ shutil.rmtree('sample_data', ignore_errors=True) # remove colab /sample_data directory
23
+
24
+ if verbose:
25
+ # System info
26
+ # gb = 1 / 1000 ** 3 # bytes to GB
27
+ gib = 1 / 1024 ** 3 # bytes to GiB
28
+ ram = psutil.virtual_memory().total
29
+ total, used, free = shutil.disk_usage("/")
30
+ display.clear_output()
31
+ s = f'({os.cpu_count()} CPUs, {ram * gib:.1f} GB RAM, {(total - free) * gib:.1f}/{total * gib:.1f} GB disk)'
32
+ else:
33
+ s = ''
34
 
 
35
  select_device(newline=False)
36
+ print(emojis(f'Setup complete βœ… {s}'))
37
  return display