Skip to content

Commit 40bb803

Browse files
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>
1 parent 6992dde commit 40bb803

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

classify/train.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from models.experimental import attempt_load
4141
from models.yolo import ClassificationModel, DetectionModel
4242
from utils.dataloaders import create_classification_dataloader
43-
from utils.general import (DATASETS_DIR, GIT, LOGGER, TQDM_BAR_FORMAT, WorkingDirectory, check_git_status,
43+
from utils.general import (DATASETS_DIR, LOGGER, TQDM_BAR_FORMAT, WorkingDirectory, check_git_info, check_git_status,
4444
check_requirements, colorstr, download, increment_path, init_seeds, print_args, yaml_save)
4545
from utils.loggers import GenericLogger
4646
from utils.plots import imshow_cls
@@ -50,6 +50,7 @@
5050
LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html
5151
RANK = int(os.getenv('RANK', -1))
5252
WORLD_SIZE = int(os.getenv('WORLD_SIZE', 1))
53+
GIT_INFO = check_git_info()
5354

5455

5556
def train(opt, device):
@@ -237,7 +238,7 @@ def train(opt, device):
237238
'updates': ema.updates,
238239
'optimizer': None, # optimizer.state_dict(),
239240
'opt': vars(opt),
240-
'git': GIT, # {remote, branch, commit} if a git repo
241+
'git': GIT_INFO, # {remote, branch, commit} if a git repo
241242
'date': datetime.now().isoformat()}
242243

243244
# Save last, best and delete

segment/train.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
from utils.autobatch import check_train_batch_size
4747
from utils.callbacks import Callbacks
4848
from utils.downloads import attempt_download, is_url
49-
from utils.general import (GIT, LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_status,
50-
check_img_size, check_requirements, check_suffix, check_yaml, colorstr, get_latest_run,
51-
increment_path, init_seeds, intersect_dicts, labels_to_class_weights,
49+
from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_info,
50+
check_git_status, check_img_size, check_requirements, check_suffix, check_yaml, colorstr,
51+
get_latest_run, increment_path, init_seeds, intersect_dicts, labels_to_class_weights,
5252
labels_to_image_weights, one_cycle, print_args, print_mutation, strip_optimizer, yaml_save)
5353
from utils.loggers import GenericLogger
5454
from utils.plots import plot_evolve, plot_labels
@@ -62,6 +62,7 @@
6262
LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html
6363
RANK = int(os.getenv('RANK', -1))
6464
WORLD_SIZE = int(os.getenv('WORLD_SIZE', 1))
65+
GIT_INFO = check_git_info()
6566

6667

6768
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
390391
'updates': ema.updates,
391392
'optimizer': optimizer.state_dict(),
392393
'opt': vars(opt),
393-
'git': GIT, # {remote, branch, commit} if a git repo
394+
'git': GIT_INFO, # {remote, branch, commit} if a git repo
394395
'date': datetime.now().isoformat()}
395396

396397
# Save last, best and delete

train.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
from utils.callbacks import Callbacks
4848
from utils.dataloaders import create_dataloader
4949
from utils.downloads import attempt_download, is_url
50-
from utils.general import (GIT, LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_status,
51-
check_img_size, check_requirements, check_suffix, check_yaml, colorstr, get_latest_run,
52-
increment_path, init_seeds, intersect_dicts, labels_to_class_weights,
50+
from utils.general import (LOGGER, TQDM_BAR_FORMAT, check_amp, check_dataset, check_file, check_git_info,
51+
check_git_status, check_img_size, check_requirements, check_suffix, check_yaml, colorstr,
52+
get_latest_run, increment_path, init_seeds, intersect_dicts, labels_to_class_weights,
5353
labels_to_image_weights, methods, one_cycle, print_args, print_mutation, strip_optimizer,
5454
yaml_save)
5555
from utils.loggers import Loggers
@@ -63,6 +63,7 @@
6363
LOCAL_RANK = int(os.getenv('LOCAL_RANK', -1)) # https://pytorch.org/docs/stable/elastic/run.html
6464
RANK = int(os.getenv('RANK', -1))
6565
WORLD_SIZE = int(os.getenv('WORLD_SIZE', 1))
66+
GIT_INFO = check_git_info()
6667

6768

6869
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
376377
'updates': ema.updates,
377378
'optimizer': optimizer.state_dict(),
378379
'opt': vars(opt),
379-
'git': GIT, # {remote, branch, commit} if a git repo
380+
'git': GIT_INFO, # {remote, branch, commit} if a git repo
380381
'date': datetime.now().isoformat()}
381382

382383
# Save last, best and delete

utils/general.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import platform
1414
import random
1515
import re
16-
import shutil
1716
import signal
1817
import sys
1918
import time
@@ -29,7 +28,6 @@
2928
from zipfile import ZipFile, is_zipfile
3029

3130
import cv2
32-
import git
3331
import IPython
3432
import numpy as np
3533
import pandas as pd
@@ -346,8 +344,10 @@ def check_git_status(repo='ultralytics/yolov5', branch='master'):
346344

347345

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

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

0 commit comments

Comments
 (0)