Commit
•
56c2c34
1
Parent(s):
0892c44
Fix list paths (#721)
Browse files* Add list paths on check_dataset
* missing raise statement
* Update general.py
Co-authored-by: Glenn Jocher <[email protected]>
- utils/general.py +22 -18
utils/general.py
CHANGED
@@ -9,7 +9,7 @@ import logging
|
|
9 |
from contextlib import contextmanager
|
10 |
from copy import copy
|
11 |
from pathlib import Path
|
12 |
-
|
13 |
|
14 |
import cv2
|
15 |
import matplotlib
|
@@ -66,7 +66,7 @@ def get_latest_run(search_dir='./runs'):
|
|
66 |
|
67 |
def check_git_status():
|
68 |
# Suggest 'git pull' if repo is out of date
|
69 |
-
if platform in ['
|
70 |
s = subprocess.check_output('if [ -d .git ]; then git fetch && git status -uno; fi', shell=True).decode('utf-8')
|
71 |
if 'Your branch is behind' in s:
|
72 |
print(s[s.find('Your branch is behind'):s.find('\n\n')] + '\n')
|
@@ -126,7 +126,7 @@ def check_anchor_order(m):
|
|
126 |
|
127 |
|
128 |
def check_file(file):
|
129 |
-
#
|
130 |
if os.path.isfile(file) or file == '':
|
131 |
return file
|
132 |
else:
|
@@ -137,21 +137,25 @@ def check_file(file):
|
|
137 |
|
138 |
def check_dataset(dict):
|
139 |
# Download dataset if not found
|
140 |
-
|
141 |
-
if
|
142 |
-
|
143 |
-
if
|
144 |
-
s
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
|
|
|
|
|
|
|
|
155 |
|
156 |
|
157 |
def make_divisible(x, divisor):
|
|
|
9 |
from contextlib import contextmanager
|
10 |
from copy import copy
|
11 |
from pathlib import Path
|
12 |
+
import platform
|
13 |
|
14 |
import cv2
|
15 |
import matplotlib
|
|
|
66 |
|
67 |
def check_git_status():
|
68 |
# Suggest 'git pull' if repo is out of date
|
69 |
+
if platform.system() in ['Linux', 'Darwin'] and not os.path.isfile('/.dockerenv'):
|
70 |
s = subprocess.check_output('if [ -d .git ]; then git fetch && git status -uno; fi', shell=True).decode('utf-8')
|
71 |
if 'Your branch is behind' in s:
|
72 |
print(s[s.find('Your branch is behind'):s.find('\n\n')] + '\n')
|
|
|
126 |
|
127 |
|
128 |
def check_file(file):
|
129 |
+
# Search for file if not found
|
130 |
if os.path.isfile(file) or file == '':
|
131 |
return file
|
132 |
else:
|
|
|
137 |
|
138 |
def check_dataset(dict):
|
139 |
# Download dataset if not found
|
140 |
+
val, s = dict.get('val'), dict.get('download')
|
141 |
+
if val and len(val):
|
142 |
+
val = [os.path.abspath(x) for x in (val if isinstance(val, list) else [val])] # val path
|
143 |
+
if not all(os.path.exists(x) for x in val):
|
144 |
+
print('\nWARNING: Dataset not found, nonexistant paths: %s' % [*val])
|
145 |
+
if s and len(s): # download script
|
146 |
+
print('Attempting autodownload from: %s' % s)
|
147 |
+
if s.startswith('http') and s.endswith('.zip'): # URL
|
148 |
+
f = Path(s).name # filename
|
149 |
+
if platform.system() == 'Darwin': # avoid MacOS python requests certificate error
|
150 |
+
os.system('curl -L %s -o %s' % (s, f))
|
151 |
+
else:
|
152 |
+
torch.hub.download_url_to_file(s, f)
|
153 |
+
r = os.system('unzip -q %s -d ../ && rm %s' % (f, f)) # unzip
|
154 |
+
else: # bash script
|
155 |
+
r = os.system(s)
|
156 |
+
print('Dataset autodownload %s\n' % ('success' if r == 0 else 'failure')) # analyze return value
|
157 |
+
else:
|
158 |
+
raise Exception('Dataset not found.')
|
159 |
|
160 |
|
161 |
def make_divisible(x, divisor):
|