Description
🐛 Describe the bug
datasets phototour.py gives errors.
https://github.com/pytorch/vision/blob/main/torchvision/datasets/phototour.py
import torch
from torchvision.datasets import PhotoTour
from torchvision.transforms import ToTensor
def test_phototour_torchvision():
# Define the root directory where datasets will be stored
root = "./datasets"
# List of datasets to test
datasets = ["notredame", "yosemite", "liberty"]
for dataset_name in datasets:
print(f"\nTesting dataset: {dataset_name}")
# Initialize the dataset
dataset = PhotoTour(
root=root,
name=dataset_name,
train=True,
transform=ToTensor(),
download=True, # Download the datasets if not already present
)
# Check if the dataset has been loaded successfully
assert len(dataset) > 0, f"Dataset {dataset_name} is empty!"
print(f"Number of patches in {dataset_name}: {len(dataset)}")
# Retrieve a sample
sample = dataset[0]
print(f"Sample type for {dataset_name}: {type(sample)}")
if isinstance(sample, torch.Tensor):
print(f"Sample shape: {sample.shape}")
elif isinstance(sample, tuple):
print(f"Sample components shapes: {[s.shape if isinstance(s, torch.Tensor) else type(s) for s in sample]}")
# Print the mean and standard deviation of the dataset
print(f"Mean: {dataset.mean}, Std: {dataset.std}")
# Access a few samples to verify functionality
for i in range(min(5, len(dataset))): # Test first 5 samples
try:
data = dataset[i]
print(f"Sample {i}: {data.shape if isinstance(data, torch.Tensor) else type(data)}")
except Exception as e:
print(f"Error accessing sample {i}: {e}")
if __name__ == "__main__":
test_phototour_torchvision()
Testing dataset: notredame
Traceback (most recent call last):
File "/opt/homebrew/Cellar/[email protected]/3.12.7/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 1344, in do_open
h.request(req.get_method(), req.selector, req.data, headers,
File "/opt/homebrew/Cellar/[email protected]/3.12.7/Frameworks/Python.framework/Versions/3.12/lib/python3.12/http/client.py", line 1336, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/opt/homebrew/Cellar/[email protected]/3.12.7/Frameworks/Python.framework/Versions/3.12/lib/python3.12/http/client.py", line 1382, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/opt/homebrew/Cellar/[email protected]/3.12.7/Frameworks/Python.framework/Versions/3.12/lib/python3.12/http/client.py", line 1331, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/opt/homebrew/Cellar/[email protected]/3.12.7/Frameworks/Python.framework/Versions/3.12/lib/python3.12/http/client.py", line 1091, in _send_output
self.send(msg)
File "/opt/homebrew/Cellar/[email protected]/3.12.7/Frameworks/Python.framework/Versions/3.12/lib/python3.12/http/client.py", line 1035, in send
self.connect()
File "/opt/homebrew/Cellar/[email protected]/3.12.7/Frameworks/Python.framework/Versions/3.12/lib/python3.12/http/client.py", line 1001, in connect
self.sock = self._create_connection(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.12.7/Frameworks/Python.framework/Versions/3.12/lib/python3.12/socket.py", line 865, in create_connection
raise exceptions[0]
File "/opt/homebrew/Cellar/[email protected]/3.12.7/Frameworks/Python.framework/Versions/3.12/lib/python3.12/socket.py", line 850, in create_connection
sock.connect(sa)
TimeoutError: [Errno 60] Operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/users/pho.py", line 48, in
test_phototour_torchvision()
File "/users/pho.py", line 16, in test_phototour_torchvision
dataset = PhotoTour(
^^^^^^^^^^
File "/users/venv/lib/python3.12/site-packages/torchvision/datasets/phototour.py", line 109, in init
self.download()
File "/users/venv/lib/python3.12/site-packages/torchvision/datasets/phototour.py", line 158, in download
download_url(url, self.root, filename, md5)
File "/users/venv/lib/python3.12/site-packages/torchvision/datasets/utils.py", line 122, in download_url
url = _get_redirect_url(url, max_hops=max_redirect_hops)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/users/venv/lib/python3.12/site-packages/torchvision/datasets/utils.py", line 66, in _get_redirect_url
with urllib.request.urlopen(urllib.request.Request(url, headers=headers)) as response:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.12.7/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 215, in urlopen
return opener.open(url, data, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.12.7/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 515, in open
response = self._open(req, data)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.12.7/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 532, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.12.7/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 492, in _call_chain
result = func(*args)
^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.12.7/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 1373, in http_open
return self.do_open(http.client.HTTPConnection, req)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/homebrew/Cellar/[email protected]/3.12.7/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 1347, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 60] Operation timed out>
Versions
Name: torch
Version: 2.5.1
Name: torchvision
Version: 0.20.1