mirror of
https://github.com/ultralytics/yolov5.git
synced 2025-06-03 14:49:29 +08:00
Create date_modified() (#2616)
Updated device selection string with fallback for non-git directories.
```python
def select_device(device='', batch_size=None):
# device = 'cpu' or '0' or '0,1,2,3'
s = f'YOLOv5 🚀 {git_describe() or date_modified()} torch {torch.__version__} ' # string
...
```
This commit is contained in:
parent
196bf10603
commit
0ff5aeca61
@ -1,4 +1,6 @@
|
|||||||
# PyTorch utils
|
# YOLOv5 PyTorch utils
|
||||||
|
|
||||||
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
@ -43,9 +45,15 @@ def init_torch_seeds(seed=0):
|
|||||||
cudnn.benchmark, cudnn.deterministic = True, False
|
cudnn.benchmark, cudnn.deterministic = True, False
|
||||||
|
|
||||||
|
|
||||||
def git_describe():
|
def date_modified(path=__file__):
|
||||||
|
# return human-readable file modification date, i.e. '2021-3-26'
|
||||||
|
t = datetime.datetime.fromtimestamp(Path(path).stat().st_mtime)
|
||||||
|
return f'{t.year}-{t.month}-{t.day}'
|
||||||
|
|
||||||
|
|
||||||
|
def git_describe(path=Path(__file__).parent): # path must be a directory
|
||||||
# return human-readable git description, i.e. v5.0-5-g3e25f1e https://git-scm.com/docs/git-describe
|
# return human-readable git description, i.e. v5.0-5-g3e25f1e https://git-scm.com/docs/git-describe
|
||||||
s = f'git -C {Path(__file__).resolve().parent} describe --tags --long --always'
|
s = f'git -C {path} describe --tags --long --always'
|
||||||
try:
|
try:
|
||||||
return subprocess.check_output(s, shell=True).decode()[:-1]
|
return subprocess.check_output(s, shell=True).decode()[:-1]
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
@ -54,7 +62,7 @@ def git_describe():
|
|||||||
|
|
||||||
def select_device(device='', batch_size=None):
|
def select_device(device='', batch_size=None):
|
||||||
# device = 'cpu' or '0' or '0,1,2,3'
|
# device = 'cpu' or '0' or '0,1,2,3'
|
||||||
s = f'YOLOv5 🚀 {git_describe()} torch {torch.__version__} ' # string
|
s = f'YOLOv5 🚀 {git_describe() or date_modified()} torch {torch.__version__} ' # string
|
||||||
cpu = device.lower() == 'cpu'
|
cpu = device.lower() == 'cpu'
|
||||||
if cpu:
|
if cpu:
|
||||||
os.environ['CUDA_VISIBLE_DEVICES'] = '-1' # force torch.cuda.is_available() = False
|
os.environ['CUDA_VISIBLE_DEVICES'] = '-1' # force torch.cuda.is_available() = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user