Skip to content

Fix broken download URLs for Caltech101 and Caltech256 datasets #9098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions torchvision/datasets/caltech.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import os
import os.path
import shutil
from pathlib import Path
from typing import Any, Callable, Optional, Union

from PIL import Image

from .utils import download_and_extract_archive, verify_str_arg
from .utils import download_and_extract_archive, extract_archive, verify_str_arg
from .vision import VisionDataset


Expand Down Expand Up @@ -131,19 +132,36 @@ def __len__(self) -> int:
def download(self) -> None:
if self._check_integrity():
return

# Download and unzip the single ZIP containing both .tar files
download_and_extract_archive(
"https://drive.google.com/file/d/137RyRjvTBkBiIfeYBNZBtViDHQ6_Ewsp",
"https://data.caltech.edu/records/mzrjq-6wc02/files/caltech-101.zip?download=1",
self.root,
filename="101_ObjectCategories.tar.gz",
md5="b224c7392d521a49829488ab0f1120d9",
)
download_and_extract_archive(
"https://drive.google.com/file/d/175kQy3UsZ0wUEHZjqkUDdNVssr7bgh_m",
self.root,
filename="Annotations.tar",
md5="6f83eeb1f24d99cab4eb377263132c91",
filename="caltech-101.zip",
md5="3138e1922a9193bfa496528edbbc45d0",
)
archive_folder = os.path.join(self.root, "caltech-101")
category_archive = os.path.join(archive_folder, "101_ObjectCategories.tar.gz")
annotation_archive = os.path.join(archive_folder, "Annotations.tar")
macos_meta = os.path.join(archive_folder, "__MACOSX")

# Remove macOS metadata folder if it exists
if os.path.isdir(macos_meta):
shutil.rmtree(macos_meta)

# Extract '101_ObjectCategories.tar.gz' into self.root
extract_archive(category_archive, self.root, remove_finished=True)

# Extract 'Annotations.tar' into self.root
extract_archive(annotation_archive, self.root, remove_finished=True)

# Delete the 'caltech-101' folder (which may now be empty or contain only other hidden files)
if os.path.isdir(archive_folder):
shutil.rmtree(archive_folder)

# Remove the ZIP file itself
zip_path = os.path.join(self.root, "caltech-101.zip")
if os.path.isfile(zip_path):
os.remove(zip_path)

def extra_repr(self) -> str:
return "Target type: {target_type}".format(**self.__dict__)
Expand Down Expand Up @@ -231,9 +249,8 @@ def __len__(self) -> int:
def download(self) -> None:
if self._check_integrity():
return

download_and_extract_archive(
"https://drive.google.com/file/d/1r6o0pSROcV1_VwT4oSjA2FBUSCWGuxLK",
"https://data.caltech.edu/records/nyy15-4j048/files/256_ObjectCategories.tar",
self.root,
filename="256_ObjectCategories.tar",
md5="67b4f42ca05d46448c6bb8ecd2220f6d",
Expand Down