glenn-jocher
commited on
Commit
•
7d3686a
1
Parent(s):
4c5d9bf
Update `check_file()` (#3622)
Browse files* Update `check_file()`
* Update datasets.py
- utils/datasets.py +1 -1
- utils/general.py +3 -3
utils/datasets.py
CHANGED
@@ -1095,7 +1095,7 @@ def dataset_stats(path='coco128.yaml', autodownload=False, verbose=False):
|
|
1095 |
autodownload: Attempt to download dataset if not found locally
|
1096 |
verbose: Print stats dictionary
|
1097 |
"""
|
1098 |
-
with open(check_file(
|
1099 |
data = yaml.safe_load(f) # data dict
|
1100 |
check_dataset(data, autodownload) # download dataset if missing
|
1101 |
nc = data['nc'] # number of classes
|
|
|
1095 |
autodownload: Attempt to download dataset if not found locally
|
1096 |
verbose: Print stats dictionary
|
1097 |
"""
|
1098 |
+
with open(check_file(path)) as f:
|
1099 |
data = yaml.safe_load(f) # data dict
|
1100 |
check_dataset(data, autodownload) # download dataset if missing
|
1101 |
nc = data['nc'] # number of classes
|
utils/general.py
CHANGED
@@ -206,9 +206,9 @@ def check_file(file):
|
|
206 |
file = str(file) # convert to str()
|
207 |
if Path(file).is_file() or file == '': # exists
|
208 |
return file
|
209 |
-
elif file.startswith(('http
|
210 |
-
url
|
211 |
-
file = file.split('?')[0] #
|
212 |
print(f'Downloading {url} to {file}...')
|
213 |
torch.hub.download_url_to_file(url, file)
|
214 |
assert Path(file).exists() and Path(file).stat().st_size > 0, f'File download failed: {url}' # check
|
|
|
206 |
file = str(file) # convert to str()
|
207 |
if Path(file).is_file() or file == '': # exists
|
208 |
return file
|
209 |
+
elif file.startswith(('http:/', 'https:/')): # download
|
210 |
+
url = str(Path(file)).replace(':/', '://') # Pathlib turns :// -> :/
|
211 |
+
file = Path(urllib.parse.unquote(file)).name.split('?')[0] # '%2F' to '/', split https://url.com/file.txt?auth
|
212 |
print(f'Downloading {url} to {file}...')
|
213 |
torch.hub.download_url_to_file(url, file)
|
214 |
assert Path(file).exists() and Path(file).stat().st_size > 0, f'File download failed: {url}' # check
|