From e56d342af6a51dbcd7576d32e66deea245f5e5e0 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Wed, 22 Dec 2021 15:47:22 +0100 Subject: [PATCH 1/3] Bump pytorch version --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 010e560..741e766 100644 --- a/setup.py +++ b/setup.py @@ -31,8 +31,8 @@ keywords=['meta-learning', 'pytorch', 'few-shot', 'few-shot learning'], packages=find_packages(exclude=['data', 'contrib', 'docs', 'tests', 'examples']), install_requires=[ - 'torch>=1.4.0,<1.10.0', - 'torchvision>=0.5.0,<0.11.0', + 'torch>=1.4.0,<1.11.0', + 'torchvision>=0.5.0,<0.12.0', 'numpy>=1.14.0', 'Pillow>=7.0.0', 'h5py', From 8e117e3de37e82a7c665c52b3b7d10502a4bffa9 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sat, 24 Dec 2022 01:04:21 +0100 Subject: [PATCH 2/3] Bump pytorch version --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 741e766..c0f279c 100644 --- a/setup.py +++ b/setup.py @@ -31,8 +31,8 @@ keywords=['meta-learning', 'pytorch', 'few-shot', 'few-shot learning'], packages=find_packages(exclude=['data', 'contrib', 'docs', 'tests', 'examples']), install_requires=[ - 'torch>=1.4.0,<1.11.0', - 'torchvision>=0.5.0,<0.12.0', + 'torch>=1.4.0,<1.15.0', + 'torchvision>=0.5.0,<0.16.0', 'numpy>=1.14.0', 'Pillow>=7.0.0', 'h5py', From ef53cc17c9f645902c96ffc611ce3d2b5cd08e99 Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Sat, 24 Dec 2022 02:06:47 +0100 Subject: [PATCH 3/3] Use upstream download_file_from_google_drive for recent versions of torchvision If _get_confirm_token does not exist, it is somewhat safe to assume they probably fixed the original issue. --- torchmeta/datasets/utils.py | 87 ++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 40 deletions(-) diff --git a/torchmeta/datasets/utils.py b/torchmeta/datasets/utils.py index 5f763ba..583908c 100644 --- a/torchmeta/datasets/utils.py +++ b/torchmeta/datasets/utils.py @@ -30,58 +30,65 @@ def get_asset(*args, dtype=None): # is currently no protection against exceeded quotas. If you get an integrity error in Torchmeta # (e.g. "MiniImagenet integrity check failed" for MiniImagenet), then this means that the quota # has exceeded for this dataset. See also: https://github.com/tristandeleu/pytorch-meta/issues/54 -# +# # See also: https://github.com/pytorch/vision/issues/2992 -# +# # The following functions are taken from # https://github.com/pytorch/vision/blob/cd0268cd408d19d91f870e36fdffd031085abe13/torchvision/datasets/utils.py -from torchvision.datasets.utils import _get_confirm_token, _save_response_content +try: + from torchvision.datasets.utils import _get_confirm_token, _save_response_content -def _quota_exceeded(response: "requests.models.Response"): - return False - # See https://github.com/pytorch/vision/issues/2992 for details - # return "Google Drive - Quota exceeded" in response.text +except ImportError: # `_get_confirm_token` does not exist in torchvision 0.14.0 + # assume it is fixed upstream, and use it + from torchvision.datasets.utils import download_file_from_google_drive +else: -def download_file_from_google_drive(file_id, root, filename=None, md5=None): - """Download a Google Drive file from and place it in root. + def _quota_exceeded(response: "requests.models.Response"): + return False + # See https://github.com/pytorch/vision/issues/2992 for details + # return "Google Drive - Quota exceeded" in response.text - Args: - file_id (str): id of file to be downloaded - root (str): Directory to place downloaded file in - filename (str, optional): Name to save the file under. If None, use the id of the file. - md5 (str, optional): MD5 checksum of the download. If None, do not check - """ - # Based on https://stackoverflow.com/questions/38511444/python-download-files-from-google-drive-using-url - import requests - url = "https://docs.google.com/uc?export=download" - root = os.path.expanduser(root) - if not filename: - filename = file_id - fpath = os.path.join(root, filename) + def download_file_from_google_drive(file_id, root, filename=None, md5=None): + """Download a Google Drive file from and place it in root. - os.makedirs(root, exist_ok=True) + Args: + file_id (str): id of file to be downloaded + root (str): Directory to place downloaded file in + filename (str, optional): Name to save the file under. If None, use the id of the file. + md5 (str, optional): MD5 checksum of the download. If None, do not check + """ + # Based on https://stackoverflow.com/questions/38511444/python-download-files-from-google-drive-using-url + import requests + url = "https://docs.google.com/uc?export=download" - if os.path.isfile(fpath) and check_integrity(fpath, md5): - print('Using downloaded and verified file: ' + fpath) - else: - session = requests.Session() + root = os.path.expanduser(root) + if not filename: + filename = file_id + fpath = os.path.join(root, filename) + + os.makedirs(root, exist_ok=True) + + if os.path.isfile(fpath) and check_integrity(fpath, md5): + print('Using downloaded and verified file: ' + fpath) + else: + session = requests.Session() - response = session.get(url, params={'id': file_id}, stream=True) - token = _get_confirm_token(response) + response = session.get(url, params={'id': file_id}, stream=True) + token = _get_confirm_token(response) - if token: - params = {'id': file_id, 'confirm': token} - response = session.get(url, params=params, stream=True) + if token: + params = {'id': file_id, 'confirm': token} + response = session.get(url, params=params, stream=True) - if _quota_exceeded(response): - msg = ( - f"The daily quota of the file {filename} is exceeded and it " - f"can't be downloaded. This is a limitation of Google Drive " - f"and can only be overcome by trying again later." - ) - raise RuntimeError(msg) + if _quota_exceeded(response): + msg = ( + f"The daily quota of the file {filename} is exceeded and it " + f"can't be downloaded. This is a limitation of Google Drive " + f"and can only be overcome by trying again later." + ) + raise RuntimeError(msg) - _save_response_content(response, fpath) + _save_response_content(response, fpath)