Update check_file() (#3622)

* Update `check_file()`

* Update datasets.py
This commit is contained in:
Glenn Jocher authored and GitHub committed 2021-06-15 13:21:04 +02:00
1 parent 4c5d9bff80
commit 7d3686a686
2 files changed
+4 -4

No files matched your search

+1 -1
View File
@@ -1095,7 +1095,7 @@ def dataset_stats(path='coco128.yaml', autodownload=False, verbose=False):
autodownload: Attempt to download dataset if not found locally autodownload: Attempt to download dataset if not found locally
verbose: Print stats dictionary verbose: Print stats dictionary
""" """
with open(check_file(Path(path))) as f: with open(check_file(path)) as f:
data = yaml.safe_load(f) # data dict data = yaml.safe_load(f) # data dict
check_dataset(data, autodownload) # download dataset if missing check_dataset(data, autodownload) # download dataset if missing
nc = data['nc'] # number of classes nc = data['nc'] # number of classes
+3 -3
View File
@@ -206,9 +206,9 @@ def check_file(file):
file = str(file) # convert to str() file = str(file) # convert to str()
if Path(file).is_file() or file == '': # exists if Path(file).is_file() or file == '': # exists
return file return file
elif file.startswith(('http://', 'https://')): # download elif file.startswith(('http:/', 'https:/')): # download
url, file = file, Path(urllib.parse.unquote(str(file))).name # url, file (decode '%2F' to '/' etc.) url = str(Path(file)).replace(':/', '://') # Pathlib turns :// -> :/
file = file.split('?')[0] # parse authentication https://url.com/file.txt?auth... file = Path(urllib.parse.unquote(file)).name.split('?')[0] # '%2F' to '/', split https://url.com/file.txt?auth
print(f'Downloading {url} to {file}...') print(f'Downloading {url} to {file}...')
torch.hub.download_url_to_file(url, file) torch.hub.download_url_to_file(url, file)
assert Path(file).exists() and Path(file).stat().st_size > 0, f'File download failed: {url}' # check assert Path(file).exists() and Path(file).stat().st_size > 0, f'File download failed: {url}' # check