diff --git a/utils/general.py b/utils/general.py index 9a882715f0ad..996060dd510e 100755 --- a/utils/general.py +++ b/utils/general.py @@ -173,12 +173,18 @@ def check_imshow(): def check_file(file): - # Search for file if not found - if Path(file).is_file() or file == '': + # Search/download file (if necessary) and return path + file = str(file) # convert to str() + if Path(file).is_file() or file == '': # exists return file - else: + elif file.startswith(('http://', 'https://')): # download + url, file = file, Path(file).name + torch.hub.download_url_to_file(url, file) + assert Path(file).is_file(), f'File download failed: {url}' + return file + else: # search files = glob.glob('./**/' + file, recursive=True) # find file - assert len(files), f'File Not Found: {file}' # assert file was found + assert len(files), f'File not found: {file}' # assert file was found assert len(files) == 1, f"Multiple files match '{file}', specify exact path: {files}" # assert unique return files[0] # return file