Skip to content

Commit

Permalink
Scope gitpyhon import in check_git_info() (#10221)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
glenn-jocher and pre-commit-ci[bot] authored Nov 19, 2022
1 parent 6992dde commit 40bb803
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
5 changes: 3 additions & 2 deletions classify/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from models.experimental import attempt_load
from models.yolo import ClassificationModel, DetectionModel
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)
from utils.loggers import GenericLogger
from utils.plots import imshow_cls
Expand All @@ -50,6 +50,7 @@
LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html
RANK = int(os.getenv('RANK', -1))
WORLD_SIZE = int(os.getenv('WORLD_SIZE', 1))
GIT_INFO = check_git_info()


def train(opt, device):
Expand Down Expand Up @@ -237,7 +238,7 @@ def train(opt, device):
'updates': ema.updates,
'optimizer': None, # optimizer.state_dict(),
'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()}

# Save last, best and delete
Expand Down
9 changes: 5 additions & 4 deletions segment/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
from utils.autobatch import check_train_batch_size
from utils.callbacks import Callbacks
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,
check_img_size, check_requirements, check_suffix, check_yaml, colorstr, get_latest_run,
increment_path, init_seeds, intersect_dicts, labels_to_class_weights,
from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_info,
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, one_cycle, print_args, print_mutation, strip_optimizer, yaml_save)
from utils.loggers import GenericLogger
from utils.plots import plot_evolve, plot_labels
Expand All @@ -62,6 +62,7 @@
LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html
RANK = int(os.getenv('RANK', -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
Expand Down Expand Up @@ -390,7 +391,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio
'updates': ema.updates,
'optimizer': optimizer.state_dict(),
'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()}

# Save last, best and delete
Expand Down
9 changes: 5 additions & 4 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
from utils.callbacks import Callbacks
from utils.dataloaders import create_dataloader
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,
check_img_size, check_requirements, check_suffix, check_yaml, colorstr, get_latest_run,
increment_path, init_seeds, intersect_dicts, labels_to_class_weights,
from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_info,
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 utils.loggers import Loggers
Expand All @@ -63,6 +63,7 @@
LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html
RANK = int(os.getenv('RANK', -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
Expand Down Expand Up @@ -376,7 +377,7 @@ def train(hyp, opt, device, callbacks): # hyp is path/to/hyp.yaml or hyp dictio
'updates': ema.updates,
'optimizer': optimizer.state_dict(),
'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()}

# Save last, best and delete
Expand Down
9 changes: 4 additions & 5 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import platform
import random
import re
import shutil
import signal
import sys
import time
Expand All @@ -29,7 +28,6 @@
from zipfile import ZipFile, is_zipfile

import cv2
import git
import IPython
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -346,8 +344,10 @@ def check_git_status(repo='ultralytics/yolov5', branch='master'):


@WorkingDirectory(ROOT)
def check_git(path='.'):
# YOLOv5 git check, return git {remote, branch, commit}
def check_git_info(path='.'):
# YOLOv5 git info check, return {remote, branch, commit}
check_requirements('gitpython')
import git
try:
repo = git.Repo(path)
remote = repo.remotes.origin.url.replace('.git', '') # i.e. 'https://github.com/ultralytics/yolov5'
Expand Down Expand Up @@ -1138,4 +1138,3 @@ def imshow(path, im):
cv2.imread, cv2.imwrite, cv2.imshow = imread, imwrite, imshow # redefine

# Variables ------------------------------------------------------------------------------------------------------------
GIT = check_git() # repo, branch, commit

0 comments on commit 40bb803

Please sign in to comment.