Scope gitpyhon import in `check_git_info()` (#10221)

* Scope gitpyhon import in `check_git_info()`

* [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>
pull/10222/head
Glenn Jocher 2022-11-19 14:22:07 +01:00 committed by GitHub
parent 6992dde4bd
commit 40bb8030f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 15 deletions

View File

@ -40,7 +40,7 @@ from classify import val as validate
from models.experimental import attempt_load from models.experimental import attempt_load
from models.yolo import ClassificationModel, DetectionModel from models.yolo import ClassificationModel, DetectionModel
from utils.dataloaders import create_classification_dataloader from utils.dataloaders import create_classification_dataloader
from utils.general import (DATASETS_DIR, GIT, LOGGER, TQDM_BAR_FORMAT, WorkingDirectory, check_git_status, from utils.general import (DATASETS_DIR, LOGGER, TQDM_BAR_FORMAT, WorkingDirectory, check_git_info, check_git_status,
check_requirements, colorstr, download, increment_path, init_seeds, print_args, yaml_save) check_requirements, colorstr, download, increment_path, init_seeds, print_args, yaml_save)
from utils.loggers import GenericLogger from utils.loggers import GenericLogger
from utils.plots import imshow_cls from utils.plots import imshow_cls
@ -50,6 +50,7 @@ from utils.torch_utils import (ModelEMA, model_info, reshape_classifier_output,
LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html
RANK = int(os.getenv('RANK', -1)) RANK = int(os.getenv('RANK', -1))
WORLD_SIZE = int(os.getenv('WORLD_SIZE', 1)) WORLD_SIZE = int(os.getenv('WORLD_SIZE', 1))
GIT_INFO = check_git_info()
def train(opt, device): def train(opt, device):
@ -237,7 +238,7 @@ def train(opt, device):
'updates': ema.updates, 'updates': ema.updates,
'optimizer': None, # optimizer.state_dict(), 'optimizer': None, # optimizer.state_dict(),
'opt': vars(opt), 'opt': vars(opt),
'git': GIT, # {remote, branch, commit} if a git repo 'git': GIT_INFO, # {remote, branch, commit} if a git repo
'date': datetime.now().isoformat()} 'date': datetime.now().isoformat()}
# Save last, best and delete # Save last, best and delete

View File

@ -46,9 +46,9 @@ from utils.autoanchor import check_anchors
from utils.autobatch import check_train_batch_size from utils.autobatch import check_train_batch_size
from utils.callbacks import Callbacks from utils.callbacks import Callbacks
from utils.downloads import attempt_download, is_url from utils.downloads import attempt_download, is_url
from utils.general import (GIT, LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_status, from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_info,
check_img_size, check_requirements, check_suffix, check_yaml, colorstr, get_latest_run, check_git_status, check_img_size, check_requirements, check_suffix, check_yaml, colorstr,
increment_path, init_seeds, intersect_dicts, labels_to_class_weights, get_latest_run, increment_path, init_seeds, intersect_dicts, labels_to_class_weights,
labels_to_image_weights, one_cycle, print_args, print_mutation, strip_optimizer, yaml_save) labels_to_image_weights, one_cycle, print_args, print_mutation, strip_optimizer, yaml_save)
from utils.loggers import GenericLogger from utils.loggers import GenericLogger
from utils.plots import plot_evolve, plot_labels from utils.plots import plot_evolve, plot_labels
@ -62,6 +62,7 @@ from utils.torch_utils import (EarlyStopping, ModelEMA, de_parallel, select_devi
LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html
RANK = int(os.getenv('RANK', -1)) RANK = int(os.getenv('RANK', -1))
WORLD_SIZE = int(os.getenv('WORLD_SIZE', 1)) WORLD_SIZE = int(os.getenv('WORLD_SIZE', 1))
GIT_INFO = check_git_info()
def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictionary def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictionary
@ -390,7 +391,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio
'updates': ema.updates, 'updates': ema.updates,
'optimizer': optimizer.state_dict(), 'optimizer': optimizer.state_dict(),
'opt': vars(opt), 'opt': vars(opt),
'git': GIT, # {remote, branch, commit} if a git repo 'git': GIT_INFO, # {remote, branch, commit} if a git repo
'date': datetime.now().isoformat()} 'date': datetime.now().isoformat()}
# Save last, best and delete # Save last, best and delete

View File

@ -47,9 +47,9 @@ from utils.autobatch import check_train_batch_size
from utils.callbacks import Callbacks from utils.callbacks import Callbacks
from utils.dataloaders import create_dataloader from utils.dataloaders import create_dataloader
from utils.downloads import attempt_download, is_url from utils.downloads import attempt_download, is_url
from utils.general import (GIT, LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_status, from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_info,
check_img_size, check_requirements, check_suffix, check_yaml, colorstr, get_latest_run, check_git_status, check_img_size, check_requirements, check_suffix, check_yaml, colorstr,
increment_path, init_seeds, intersect_dicts, labels_to_class_weights, 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, labels_to_image_weights, methods, one_cycle, print_args, print_mutation, strip_optimizer,
yaml_save) yaml_save)
from utils.loggers import Loggers from utils.loggers import Loggers
@ -63,6 +63,7 @@ from utils.torch_utils import (EarlyStopping, ModelEMA, de_parallel, select_devi
LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html
RANK = int(os.getenv('RANK', -1)) RANK = int(os.getenv('RANK', -1))
WORLD_SIZE = int(os.getenv('WORLD_SIZE', 1)) WORLD_SIZE = int(os.getenv('WORLD_SIZE', 1))
GIT_INFO = check_git_info()
def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictionary def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictionary
@ -376,7 +377,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio
'updates': ema.updates, 'updates': ema.updates,
'optimizer': optimizer.state_dict(), 'optimizer': optimizer.state_dict(),
'opt': vars(opt), 'opt': vars(opt),
'git': GIT, # {remote, branch, commit} if a git repo 'git': GIT_INFO, # {remote, branch, commit} if a git repo
'date': datetime.now().isoformat()} 'date': datetime.now().isoformat()}
# Save last, best and delete # Save last, best and delete

View File

@ -13,7 +13,6 @@ import os
import platform import platform
import random import random
import re import re
import shutil
import signal import signal
import sys import sys
import time import time
@ -29,7 +28,6 @@ from typing import Optional
from zipfile import ZipFile, is_zipfile from zipfile import ZipFile, is_zipfile
import cv2 import cv2
import git
import IPython import IPython
import numpy as np import numpy as np
import pandas as pd import pandas as pd
@ -346,8 +344,10 @@ def check_git_status(repo='ultralytics/yolov5', branch='master'):
@WorkingDirectory(ROOT) @WorkingDirectory(ROOT)
def check_git(path='.'): def check_git_info(path='.'):
# YOLOv5 git check, return git {remote, branch, commit} # YOLOv5 git info check, return {remote, branch, commit}
check_requirements('gitpython')
import git
try: try:
repo = git.Repo(path) repo = git.Repo(path)
remote = repo.remotes.origin.url.replace('.git', '') # i.e. 'https://github.com/ultralytics/yolov5' remote = repo.remotes.origin.url.replace('.git', '') # i.e. 'https://github.com/ultralytics/yolov5'
@ -1138,4 +1138,3 @@ def imshow(path, im):
cv2.imread, cv2.imwrite, cv2.imshow = imread, imwrite, imshow # redefine cv2.imread, cv2.imwrite, cv2.imshow = imread, imwrite, imshow # redefine
# Variables ------------------------------------------------------------------------------------------------------------ # Variables ------------------------------------------------------------------------------------------------------------
GIT = check_git() # repo, branch, commit