Add notebook_init() to utils/__init__.py (#5488)

* Update __init__.py

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

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

* notebook_init

* notebook_init

* notebook_init

* notebook_init

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

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

* notebook_init

* Created using Colaboratory

* [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>
This commit is contained in:
Glenn Jocherandpre-commit-ci[bot] authored and GitHub committed 2021-11-09 23:03:19 +01:00
1 parent 7207fe95e5
commit 7ebb5e5da6
3 files changed
+35 -17

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
"""
utils/initialization
"""
def notebook_init():
# For YOLOv5 notebooks
print('Checking setup...')
from IPython import display # to display images and clear console output
from utils.general import emojis
from utils.torch_utils import select_device # YOLOv5 imports
display.clear_output()
select_device(newline=False)
print(emojis('Setup complete ✅'))
return display
+3 -1
View File
@@ -53,7 +53,7 @@ def git_describe(path=Path(__file__).parent): # path must be a directory
return '' # not a git repository
def select_device(device='', batch_size=None):
def select_device(device='', batch_size=None, newline=True):
# device = 'cpu' or '0' or '0,1,2,3'
s = f'YOLOv5 🚀 {git_describe() or date_modified()} torch {torch.__version__} ' # string
device = str(device).strip().lower().replace('cuda:', '') # to string, 'cuda:0' to '0'
@@ -77,6 +77,8 @@ def select_device(device='', batch_size=None):
else:
s += 'CPU\n'
if not newline:
s = s.rstrip()
LOGGER.info(s.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else s) # emoji-safe
return torch.device('cuda:0' if cuda else 'cpu')