From f820e4d130982592c85f80406236b52af05da57e Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 29 Sep 2022 22:43:44 +0200 Subject: [PATCH 1/8] Add git status on train checkpoints --- requirements.txt | 1 + utils/general.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/requirements.txt b/requirements.txt index 0436f415c642..8f77ad04777b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,7 @@ # Usage: pip install -r requirements.txt # Base ---------------------------------------- +gitpython matplotlib>=3.2.2 numpy>=1.18.5 opencv-python>=4.1.1 diff --git a/utils/general.py b/utils/general.py index d31b043a113e..857fcfbfeeae 100644 --- a/utils/general.py +++ b/utils/general.py @@ -27,6 +27,7 @@ from zipfile import ZipFile import cv2 +import git import numpy as np import pandas as pd import pkg_resources as pkg @@ -319,6 +320,19 @@ def check_git_status(repo='ultralytics/yolov5', branch='master'): LOGGER.info(s) +@WorkingDirectory(ROOT) +def check_git_local(path='.'): + # YOLOv5 git check + try: + repo = git.Repo(path) + remote = repo.remotes.origin.url.replace('.git', '') # i.e. 'https://github.com/ultralytics/yolov5' + branch = repo.active_branch.name # i.e. 'main' + commit = repo.active_branch.commit.hexsha # i.e. '3134699c73af83aac2a481435550b968d5792c0d' + return remote, branch, commit + except git.exc.InvalidGitRepositoryError: # path is not a git dir + return '', '', '' # branch, commit, remote + + def check_python(minimum='3.7.0'): # Check current python version vs. required python version check_version(platform.python_version(), minimum, name='Python ', hard=True) From 1b817a5dbe50de51200098c55db4df7d77284809 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 29 Sep 2022 22:49:52 +0200 Subject: [PATCH 2/8] Update --- utils/general.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/general.py b/utils/general.py index 857fcfbfeeae..745ac73e20ea 100644 --- a/utils/general.py +++ b/utils/general.py @@ -321,7 +321,7 @@ def check_git_status(repo='ultralytics/yolov5', branch='master'): @WorkingDirectory(ROOT) -def check_git_local(path='.'): +def check_git(path='.'): # YOLOv5 git check try: repo = git.Repo(path) From c00e39611946468bc9b92ea4bb2a7b1d92cf71f4 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 29 Sep 2022 22:52:15 +0200 Subject: [PATCH 3/8] Update --- utils/general.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/general.py b/utils/general.py index 745ac73e20ea..bbd4f27fc224 100644 --- a/utils/general.py +++ b/utils/general.py @@ -328,9 +328,9 @@ def check_git(path='.'): remote = repo.remotes.origin.url.replace('.git', '') # i.e. 'https://github.com/ultralytics/yolov5' branch = repo.active_branch.name # i.e. 'main' commit = repo.active_branch.commit.hexsha # i.e. '3134699c73af83aac2a481435550b968d5792c0d' - return remote, branch, commit + return {'remote': remote, 'branch': branch, 'commit': commit} except git.exc.InvalidGitRepositoryError: # path is not a git dir - return '', '', '' # branch, commit, remote + return {'remote': None, 'branch': None, 'commit': None} def check_python(minimum='3.7.0'): From e34e380b8838407138d64a1ce061953d3c69b84f Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Thu, 29 Sep 2022 23:30:35 +0200 Subject: [PATCH 4/8] Update --- train.py | 3 ++- utils/general.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/train.py b/train.py index 9efece250581..c3cff2045780 100644 --- a/train.py +++ b/train.py @@ -47,7 +47,7 @@ from utils.callbacks import Callbacks from utils.dataloaders import create_dataloader from utils.downloads import attempt_download, is_url -from utils.general import (LOGGER, check_amp, check_dataset, check_file, check_git_status, check_img_size, +from utils.general import (LOGGER, GIT, check_amp, check_dataset, check_file, check_git_status, check_img_size, check_requirements, check_suffix, check_yaml, colorstr, get_latest_run, increment_path, init_seeds, intersect_dicts, labels_to_class_weights, labels_to_image_weights, methods, one_cycle, print_args, print_mutation, strip_optimizer, yaml_save) @@ -377,6 +377,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio 'optimizer': optimizer.state_dict(), 'wandb_id': loggers.wandb.wandb_run.id if loggers.wandb else None, 'opt': vars(opt), + 'git': GIT, 'date': datetime.now().isoformat()} # Save last, best and delete diff --git a/utils/general.py b/utils/general.py index bbd4f27fc224..7578ee80685a 100644 --- a/utils/general.py +++ b/utils/general.py @@ -1095,4 +1095,4 @@ def imshow(path, im): cv2.imread, cv2.imwrite, cv2.imshow = imread, imwrite, imshow # redefine # Variables ------------------------------------------------------------------------------------------------------------ -NCOLS = 0 if is_docker() else shutil.get_terminal_size().columns # terminal window size for tqdm +GIT = check_git() # repo, branch, commit From 6e66cc4125c3b1c2e643b9f702b11a0ae5ea6539 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 30 Sep 2022 00:19:44 +0200 Subject: [PATCH 5/8] Update --- utils/general.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/utils/general.py b/utils/general.py index 7578ee80685a..4d42ecf1309c 100644 --- a/utils/general.py +++ b/utils/general.py @@ -326,8 +326,11 @@ def check_git(path='.'): try: repo = git.Repo(path) remote = repo.remotes.origin.url.replace('.git', '') # i.e. 'https://github.com/ultralytics/yolov5' - branch = repo.active_branch.name # i.e. 'main' - commit = repo.active_branch.commit.hexsha # i.e. '3134699c73af83aac2a481435550b968d5792c0d' + commit = repo.head.commit.hexsha # i.e. '3134699c73af83aac2a481435550b968d5792c0d' + try: + branch = repo.active_branch.name # i.e. 'main' + except TypeError: # not on any branch + branch = None # i.e. 'detached HEAD' state return {'remote': remote, 'branch': branch, 'commit': commit} except git.exc.InvalidGitRepositoryError: # path is not a git dir return {'remote': None, 'branch': None, 'commit': None} From fef3616ba01e47a3977d1f650597441763e35992 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 29 Sep 2022 22:20:10 +0000 Subject: [PATCH 6/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- train.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/train.py b/train.py index c3cff2045780..159e8f8e6442 100644 --- a/train.py +++ b/train.py @@ -47,7 +47,7 @@ from utils.callbacks import Callbacks from utils.dataloaders import create_dataloader from utils.downloads import attempt_download, is_url -from utils.general import (LOGGER, GIT, check_amp, check_dataset, check_file, check_git_status, check_img_size, +from utils.general import (GIT, LOGGER, check_amp, check_dataset, check_file, check_git_status, check_img_size, check_requirements, check_suffix, check_yaml, colorstr, get_latest_run, increment_path, init_seeds, intersect_dicts, labels_to_class_weights, labels_to_image_weights, methods, one_cycle, print_args, print_mutation, strip_optimizer, yaml_save) From 9d27a95a447c9df70dfa1508780481611a4cbd73 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 19 Nov 2022 03:03:30 +0100 Subject: [PATCH 7/8] Update general.py Signed-off-by: Glenn Jocher --- utils/general.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/general.py b/utils/general.py index 6bf05e440d72..733016a1b361 100644 --- a/utils/general.py +++ b/utils/general.py @@ -347,7 +347,7 @@ def check_git_status(repo='ultralytics/yolov5', branch='master'): @WorkingDirectory(ROOT) def check_git(path='.'): - # YOLOv5 git check + # YOLOv5 git check, return git directory remote, branch and commit try: repo = git.Repo(path) remote = repo.remotes.origin.url.replace('.git', '') # i.e. 'https://github.com/ultralytics/yolov5' From 24dd4c9a0cbdb7c0f2fc05cca9baaf1fc4ea2118 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sat, 19 Nov 2022 03:04:27 +0100 Subject: [PATCH 8/8] Update general.py Signed-off-by: Glenn Jocher --- utils/general.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/general.py b/utils/general.py index 733016a1b361..57b6e4e78166 100644 --- a/utils/general.py +++ b/utils/general.py @@ -347,7 +347,7 @@ def check_git_status(repo='ultralytics/yolov5', branch='master'): @WorkingDirectory(ROOT) def check_git(path='.'): - # YOLOv5 git check, return git directory remote, branch and commit + # YOLOv5 git check, return git {remote, branch, commit} try: repo = git.Repo(path) remote = repo.remotes.origin.url.replace('.git', '') # i.e. 'https://github.com/ultralytics/yolov5'