Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create date_modified() #2616

Merged
merged 1 commit into from
Mar 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Create date_modified()
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
...
```
  • Loading branch information
glenn-jocher authored Mar 26, 2021
commit 97114b8ba469fd936914c181d31d0851b63a1047
16 changes: 12 additions & 4 deletions utils/torch_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# PyTorch utils
# YOLOv5 PyTorch utils

import datetime
import logging
import math
import os
Expand Down Expand Up @@ -43,9 +45,15 @@ def init_torch_seeds(seed=0):
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
s = f'git -C {Path(__file__).resolve().parent} describe --tags --long --always'
s = f'git -C {path} describe --tags --long --always'
try:
return subprocess.check_output(s, shell=True).decode()[:-1]
except subprocess.CalledProcessError as e:
Expand All @@ -54,7 +62,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() or date_modified()} torch {torch.__version__} ' # string
cpu = device.lower() == 'cpu'
if cpu:
os.environ['CUDA_VISIBLE_DEVICES'] = '-1' # force torch.cuda.is_available() = False
Expand Down