PyTorch Hub models default to CUDA:0 if available (#2472)
* PyTorch Hub models default to CUDA:0 if available * device as string bug fix
This commit is contained in:
1 parent
2d41e70e82
commit
9b11f0c58b
4 files changed
+9
-7
No files matched your search
@@ -1,8 +1,8 @@
|
||||
# PyTorch utils
|
||||
|
||||
import logging
|
||||
import math
|
||||
import os
|
||||
import platform
|
||||
import subprocess
|
||||
import time
|
||||
from contextlib import contextmanager
|
||||
@@ -53,7 +53,7 @@ def git_describe():
|
||||
|
||||
def select_device(device='', batch_size=None):
|
||||
# device = 'cpu' or '0' or '0,1,2,3'
|
||||
s = f'YOLOv5 {git_describe()} torch {torch.__version__} ' # string
|
||||
s = f'YOLOv5 🚀 {git_describe()} torch {torch.__version__} ' # string
|
||||
cpu = device.lower() == 'cpu'
|
||||
if cpu:
|
||||
os.environ['CUDA_VISIBLE_DEVICES'] = '-1' # force torch.cuda.is_available() = False
|
||||
@@ -73,7 +73,7 @@ def select_device(device='', batch_size=None):
|
||||
else:
|
||||
s += 'CPU\n'
|
||||
|
||||
logger.info(s) # skip a line
|
||||
logger.info(s.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else s) # emoji-safe
|
||||
return torch.device('cuda:0' if cuda else 'cpu')
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user