From e1278c6dffab2dd880c958a7facff51516d032b1 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 12 Jan 2021 19:56:08 -0800 Subject: [PATCH 1/9] check_online() --- utils/general.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/utils/general.py b/utils/general.py index fc358a49a105..7de05c163320 100755 --- a/utils/general.py +++ b/utils/general.py @@ -4,7 +4,6 @@ import logging import math import os -import platform import random import re import subprocess @@ -46,10 +45,20 @@ def get_latest_run(search_dir='.'): return max(last_list, key=os.path.getctime) if last_list else '' +def check_online(): + # Check internet connectivity + import socket + try: + socket.create_connection(("1.1.1.1", 53)) # check host accesability + return True + except OSError: + return False + + def check_git_status(): # Suggest 'git pull' if repo is out of date - if Path('.git').exists() and platform.system() in ['Linux', 'Darwin'] and not Path('/.dockerenv').is_file(): - s = subprocess.check_output('if [ -d .git ]; then git fetch && git status -uno; fi', shell=True).decode('utf-8') + if Path('.git').exists() and check_online(): + s = subprocess.check_output('git fetch && git status -uno', shell=True).decode('utf-8') if 'Your branch is behind' in s: print(s[s.find('Your branch is behind'):s.find('\n\n')] + '\n') From aa9855f5914d40b873b98939a2d1282492d15350 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 12 Jan 2021 19:57:09 -0800 Subject: [PATCH 2/9] Update general.py --- utils/general.py | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/general.py b/utils/general.py index 7de05c163320..7638570a1122 100755 --- a/utils/general.py +++ b/utils/general.py @@ -34,6 +34,7 @@ def set_logging(rank=-1): def init_seeds(seed=0): + # Initialize random number generator (RNG) seeds random.seed(seed) np.random.seed(seed) init_torch_seeds(seed) From 4e3e14724566d2dec8d9a2b0f4f14f5202d0885d Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 12 Jan 2021 21:23:14 -0800 Subject: [PATCH 3/9] update check_git_status() --- train.py | 2 +- utils/general.py | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/train.py b/train.py index 3c35f9534df2..967efbcae322 100644 --- a/train.py +++ b/train.py @@ -38,7 +38,7 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): - logger.info(colorstr('Hyperparameters: ') + ', '.join(f'{k}={v}' for k, v in hyp.items())) + logger.info(colorstr('hyperparameters: ') + ', '.join(f'{k}={v}' for k, v in hyp.items())) save_dir, epochs, batch_size, total_batch_size, weights, rank = \ Path(opt.save_dir), opt.epochs, opt.batch_size, opt.total_batch_size, opt.weights, opt.global_rank diff --git a/utils/general.py b/utils/general.py index 7de05c163320..680920d91649 100755 --- a/utils/general.py +++ b/utils/general.py @@ -57,10 +57,20 @@ def check_online(): def check_git_status(): # Suggest 'git pull' if repo is out of date - if Path('.git').exists() and check_online(): - s = subprocess.check_output('git fetch && git status -uno', shell=True).decode('utf-8') - if 'Your branch is behind' in s: - print(s[s.find('Your branch is behind'):s.find('\n\n')] + '\n') + s = colorstr('github: ') + try: + if Path('.git').exists() and check_online(): + url = subprocess.check_output('git config --get remote.origin.url', shell=True).decode('utf-8')[:-1] + cmd = 'git rev-list origin/master..$(git rev-parse --abbrev-ref HEAD) --count' + n = int(subprocess.check_output(cmd, shell=True)) + if n > 0: + s += f"⚠️ WARNING: code is out of date by {n} {'commits' if n > 1 else 'commmit'}. " \ + f"Use 'git pull' to update or 'git clone {url}' to download latest." + else: + s += f'up to date with {url} ✅' + except Exception as e: + s += str(e) + print(s) def check_requirements(file='requirements.txt'): From 3ee44870af88f4a9b065d2fbf4ddb78c9f483020 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 12 Jan 2021 21:26:35 -0800 Subject: [PATCH 4/9] reverse rev-parse order --- utils/general.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/general.py b/utils/general.py index 5d23613bc955..499b9d49051a 100755 --- a/utils/general.py +++ b/utils/general.py @@ -62,7 +62,7 @@ def check_git_status(): try: if Path('.git').exists() and check_online(): url = subprocess.check_output('git config --get remote.origin.url', shell=True).decode('utf-8')[:-1] - cmd = 'git rev-list origin/master..$(git rev-parse --abbrev-ref HEAD) --count' + cmd = 'git rev-list $(git rev-parse --abbrev-ref HEAD)..origin/master --count' # commits behind n = int(subprocess.check_output(cmd, shell=True)) if n > 0: s += f"⚠️ WARNING: code is out of date by {n} {'commits' if n > 1 else 'commmit'}. " \ From cba713a6b1b6af1f032eacd6f21334ac57d5814c Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 12 Jan 2021 21:31:50 -0800 Subject: [PATCH 5/9] fetch --- utils/general.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/utils/general.py b/utils/general.py index 499b9d49051a..9195c458b4a8 100755 --- a/utils/general.py +++ b/utils/general.py @@ -61,9 +61,10 @@ def check_git_status(): s = colorstr('github: ') try: if Path('.git').exists() and check_online(): - url = subprocess.check_output('git config --get remote.origin.url', shell=True).decode('utf-8')[:-1] - cmd = 'git rev-list $(git rev-parse --abbrev-ref HEAD)..origin/master --count' # commits behind - n = int(subprocess.check_output(cmd, shell=True)) + url = subprocess.check_output( + 'git fetch && git config --get remote.origin.url', shell=True).decode('utf-8')[:-1] + n = int(subprocess.check_output( + 'git rev-list $(git rev-parse --abbrev-ref HEAD)..origin/master --count', shell=True)) # commits behind if n > 0: s += f"⚠️ WARNING: code is out of date by {n} {'commits' if n > 1 else 'commmit'}. " \ f"Use 'git pull' to update or 'git clone {url}' to download latest." From c19e2b8de942231f12eaa943e75ee8094df17c62 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 12 Jan 2021 21:33:56 -0800 Subject: [PATCH 6/9] improved responsiveness --- utils/general.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/utils/general.py b/utils/general.py index 9195c458b4a8..466c804a52ab 100755 --- a/utils/general.py +++ b/utils/general.py @@ -58,7 +58,7 @@ def check_online(): def check_git_status(): # Suggest 'git pull' if repo is out of date - s = colorstr('github: ') + print(colorstr('github: '), end='') try: if Path('.git').exists() and check_online(): url = subprocess.check_output( @@ -66,12 +66,12 @@ def check_git_status(): n = int(subprocess.check_output( 'git rev-list $(git rev-parse --abbrev-ref HEAD)..origin/master --count', shell=True)) # commits behind if n > 0: - s += f"⚠️ WARNING: code is out of date by {n} {'commits' if n > 1 else 'commmit'}. " \ - f"Use 'git pull' to update or 'git clone {url}' to download latest." + s = f"⚠️ WARNING: code is out of date by {n} {'commits' if n > 1 else 'commmit'}. " \ + f"Use 'git pull' to update or 'git clone {url}' to download latest." else: - s += f'up to date with {url} ✅' + s = f'up to date with {url} ✅' except Exception as e: - s += str(e) + s = str(e) print(s) From 09804f7820448843304e7a1ef70cb88798ab7202 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 12 Jan 2021 21:34:47 -0800 Subject: [PATCH 7/9] comment --- utils/general.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/general.py b/utils/general.py index 466c804a52ab..95aeda8d3f25 100755 --- a/utils/general.py +++ b/utils/general.py @@ -57,7 +57,7 @@ def check_online(): def check_git_status(): - # Suggest 'git pull' if repo is out of date + # Suggest 'git pull' if code is out of date print(colorstr('github: '), end='') try: if Path('.git').exists() and check_online(): From 241f1202e780814a8a0fa1775150f72f59760dd7 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 12 Jan 2021 21:35:06 -0800 Subject: [PATCH 8/9] comment --- utils/general.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/general.py b/utils/general.py index 95aeda8d3f25..5126a45ac096 100755 --- a/utils/general.py +++ b/utils/general.py @@ -57,7 +57,7 @@ def check_online(): def check_git_status(): - # Suggest 'git pull' if code is out of date + # Suggest 'git pull' if YOLOv5 is out of date print(colorstr('github: '), end='') try: if Path('.git').exists() and check_online(): From d3515b929ccc3d77ce0ba8c714e641bfa3e1afc5 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Tue, 12 Jan 2021 21:46:14 -0800 Subject: [PATCH 9/9] remove hyp['giou'] compat warning --- train.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/train.py b/train.py index 967efbcae322..459c81c6130d 100644 --- a/train.py +++ b/train.py @@ -6,7 +6,6 @@ import time from pathlib import Path from threading import Thread -from warnings import warn import numpy as np import torch.distributed as dist @@ -502,10 +501,6 @@ def train(hyp, opt, device, tb_writer=None, wandb=None): # Hyperparameters with open(opt.hyp) as f: hyp = yaml.load(f, Loader=yaml.FullLoader) # load hyps - if 'box' not in hyp: - warn('Compatibility: %s missing "box" which was renamed from "giou" in %s' % - (opt.hyp, 'https://github.com/ultralytics/yolov5/pull/1120')) - hyp['box'] = hyp.pop('giou') # Train logger.info(opt)