Skip to content

Connection timed out for VOCSegmentation dataset #9269

@harshitAgr

Description

@harshitAgr

🐛 Describe the bug

from torchvision import datasets

data_path = './PascalVOCDataset'
train_dataset = datasets.VOCSegmentation(
    root=data_path,
    year='2012',
    image_set='train',
    download=True,
    transforms=None,
)

This throws the following error:

---------------------------------------------------------------------------
TimeoutError                              Traceback (most recent call last)
File ~/micromamba/envs/libt/lib/python3.10/urllib/request.py:1348, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args)
   1347 try:
-> 1348     h.request(req.get_method(), req.selector, req.data, headers,
   1349               encode_chunked=req.has_header('Transfer-encoding'))
   1350 except OSError as err: # timeout error

File ~/micromamba/envs/libt/lib/python3.10/http/client.py:1276, in HTTPConnection.request(self, method, url, body, headers, encode_chunked)
   1275 """Send a complete request to the server."""
-> 1276 self._send_request(method, url, body, headers, encode_chunked)

File ~/micromamba/envs/libt/lib/python3.10/http/client.py:1322, in HTTPConnection._send_request(self, method, url, body, headers, encode_chunked)
   1321     body = _encode(body, 'body')
-> 1322 self.endheaders(body, encode_chunked=encode_chunked)

File ~/micromamba/envs/libt/lib/python3.10/http/client.py:1271, in HTTPConnection.endheaders(self, message_body, encode_chunked)
   1270     raise CannotSendHeader()
-> 1271 self._send_output(message_body, encode_chunked=encode_chunked)

File ~/micromamba/envs/libt/lib/python3.10/http/client.py:1031, in HTTPConnection._send_output(self, message_body, encode_chunked)
   1030 del self._buffer[:]
-> 1031 self.send(msg)
   1033 if message_body is not None:
   1034 
   1035     # create a consistent interface to message_body

File ~/micromamba/envs/libt/lib/python3.10/http/client.py:969, in HTTPConnection.send(self, data)
    968 if self.auto_open:
--> 969     self.connect()
    970 else:

File ~/micromamba/envs/libt/lib/python3.10/http/client.py:940, in HTTPConnection.connect(self)
    939 sys.audit("http.client.connect", self, self.host, self.port)
--> 940 self.sock = self._create_connection(
    941     (self.host,self.port), self.timeout, self.source_address)
    942 self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)

File ~/micromamba/envs/libt/lib/python3.10/socket.py:845, in create_connection(address, timeout, source_address)
    844 try:
--> 845     raise err
    846 finally:
    847     # Break explicitly a reference cycle

File ~/micromamba/envs/libt/lib/python3.10/socket.py:833, in create_connection(address, timeout, source_address)
    832     sock.bind(source_address)
--> 833 sock.connect(sa)
    834 # Break explicitly a reference cycle

TimeoutError: [Errno 110] Connection timed out

During handling of the above exception, another exception occurred:

URLError                                  Traceback (most recent call last)
Cell In[3], line 3
      1 from torchvision import datasets
----> 3 train_dataset = datasets.VOCSegmentation(
      4     root=data_path,
      5     year='2012',
      6     image_set='train',
      7     download=True,
      8     transforms=None,
      9 )

File ~/micromamba/envs/libt/lib/python3.10/site-packages/torchvision/datasets/voc.py:98, in _VOCBase.__init__(self, root, year, image_set, download, transform, target_transform, transforms)
     95 voc_root = os.path.join(self.root, base_dir)
     97 if download:
---> 98     download_and_extract_archive(self.url, self.root, filename=self.filename, md5=self.md5)
    100 if not os.path.isdir(voc_root):
    101     raise RuntimeError("Dataset not found or corrupted. You can use download=True to download it")

File ~/micromamba/envs/libt/lib/python3.10/site-packages/torchvision/datasets/utils.py:388, in download_and_extract_archive(url, download_root, extract_root, filename, md5, remove_finished)
    385 if not filename:
    386     filename = os.path.basename(url)
--> 388 download_url(url, download_root, filename, md5)
    390 archive = os.path.join(download_root, filename)
    391 extract_archive(archive, extract_root, remove_finished)

File ~/micromamba/envs/libt/lib/python3.10/site-packages/torchvision/datasets/utils.py:118, in download_url(url, root, filename, md5, max_redirect_hops)
    115     _download_file_from_remote_location(fpath, url)
    116 else:
    117     # expand redirect chain if needed
--> 118     url = _get_redirect_url(url, max_hops=max_redirect_hops)
    120     # check if file is located on Google Drive
    121     file_id = _get_google_drive_file_id(url)

File ~/micromamba/envs/libt/lib/python3.10/site-packages/torchvision/datasets/utils.py:63, in _get_redirect_url(url, max_hops)
     60 headers = {"Method": "HEAD", "User-Agent": USER_AGENT}
     62 for _ in range(max_hops + 1):
---> 63     with urllib.request.urlopen(urllib.request.Request(url, headers=headers)) as response:
     64         if response.url == url or response.url is None:
     65             return url

File ~/micromamba/envs/libt/lib/python3.10/urllib/request.py:216, in urlopen(url, data, timeout, cafile, capath, cadefault, context)
    214 else:
    215     opener = _opener
--> 216 return opener.open(url, data, timeout)

File ~/micromamba/envs/libt/lib/python3.10/urllib/request.py:519, in OpenerDirector.open(self, fullurl, data, timeout)
    516     req = meth(req)
    518 sys.audit('urllib.Request', req.full_url, req.data, req.headers, req.get_method())
--> 519 response = self._open(req, data)
    521 # post-process response
    522 meth_name = protocol+"_response"

File ~/micromamba/envs/libt/lib/python3.10/urllib/request.py:536, in OpenerDirector._open(self, req, data)
    533     return result
    535 protocol = req.type
--> 536 result = self._call_chain(self.handle_open, protocol, protocol +
    537                           '_open', req)
    538 if result:
    539     return result

File ~/micromamba/envs/libt/lib/python3.10/urllib/request.py:496, in OpenerDirector._call_chain(self, chain, kind, meth_name, *args)
    494 for handler in handlers:
    495     func = getattr(handler, meth_name)
--> 496     result = func(*args)
    497     if result is not None:
    498         return result

File ~/micromamba/envs/libt/lib/python3.10/urllib/request.py:1377, in HTTPHandler.http_open(self, req)
   1376 def http_open(self, req):
-> 1377     return self.do_open(http.client.HTTPConnection, req)

File ~/micromamba/envs/libt/lib/python3.10/urllib/request.py:1351, in AbstractHTTPHandler.do_open(self, http_class, req, **http_conn_args)
   1348         h.request(req.get_method(), req.selector, req.data, headers,
   1349                   encode_chunked=req.has_header('Transfer-encoding'))
   1350     except OSError as err: # timeout error
-> 1351         raise URLError(err)
   1352     r = h.getresponse()
   1353 except:

URLError: <urlopen error [Errno 110] Connection timed out>

Versions

torch 2.9.1
torchvision 0.24.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions