We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
WIDERFace download fails with zip error
Originally from https://github.com/pytorch/vision/pull/4614#issuecomment-943468223

```py
In [4]: torchvision.datasets.WIDERFace(root='/tmp/lol', split='train', download=True)
```

```
91473it [00:00, 9168293.30it/s]
---------------------------------------------------------------------------
BadZipFile                                Traceback (most recent call last)
<ipython-input-4-61c4acdeef4e> in <module>
----> 1 torchvision.datasets.WIDERFace(root='/tmp/lol', split='train', download=True)

~/dev/vision/torchvision/datasets/widerface.py in __init__(self, root, split, transform, target_transform, download)
     70
     71         if download:
---> 72             self.download()
     73
     74         if not self._check_integrity():

~/dev/vision/torchvision/datasets/widerface.py in download(self)
    191             download_file_from_google_drive(file_id, self.root, filename, md5)
    192             filepath = os.path.join(self.root, filename)
--> 193             extract_archive(filepath)
    194
    195         # download and extract annotation files

~/dev/vision/torchvision/datasets/utils.py in extract_archive(from_path, to_path, remove_finished)
    407     extractor = _ARCHIVE_EXTRACTORS[archive_type]
    408
--> 409     extractor(from_path, to_path, compression)
    410
    411     return to_path

~/dev/vision/torchvision/datasets/utils.py in _extract_zip(from_path, to_path, compression)
    281
    282 def _extract_zip(from_path: str, to_path: str, compression: Optional[str]) -> None:
--> 283     with zipfile.ZipFile(
    284         from_path, "r", compression=_ZIP_COMPRESSION_MAP[compression] if compression else zipfile.ZIP_STORED
    285     ) as zip:

~/opt/miniconda3/envs/pt/lib/python3.8/zipfile.py in __init__(self, file, mode, compression, allowZip64, compresslevel, strict_timestamps)
   1267         try:
   1268             if mode == 'r':
-> 1269                 self._RealGetContents()
   1270             elif mode in ('w', 'x'):
   1271                 # set the modified flag so central directory gets written

~/opt/miniconda3/envs/pt/lib/python3.8/zipfile.py in _RealGetContents(self)
   1334             raise BadZipFile("File is not a zip file")
   1335         if not endrec:
-> 1336             raise BadZipFile("File is not a zip file")
   1337         if self.debug > 1:
   1338             print(endrec)

BadZipFile: File is not a zip file
```

cc @pmeier

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `torchvision/datasets/widerface.py`
Content:
```
1 import os
2 from os.path import abspath, expanduser
3 from typing import Any, Callable, List, Dict, Optional, Tuple, Union
4 
5 import torch
6 from PIL import Image
7 
8 from .utils import (
9     download_file_from_google_drive,
10     download_and_extract_archive,
11     extract_archive,
12     verify_str_arg,
13 )
14 from .vision import VisionDataset
15 
16 
17 class WIDERFace(VisionDataset):
18     """`WIDERFace <http://shuoyang1213.me/WIDERFACE/>`_ Dataset.
19 
20     Args:
21         root (string): Root directory where images and annotations are downloaded to.
22             Expects the following folder structure if download=False:
23 
24             .. code::
25 
26                 <root>
27                     └── widerface
28                         ├── wider_face_split ('wider_face_split.zip' if compressed)
29                         ├── WIDER_train ('WIDER_train.zip' if compressed)
30                         ├── WIDER_val ('WIDER_val.zip' if compressed)
31                         └── WIDER_test ('WIDER_test.zip' if compressed)
32         split (string): The dataset split to use. One of {``train``, ``val``, ``test``}.
33             Defaults to ``train``.
34         transform (callable, optional): A function/transform that  takes in a PIL image
35             and returns a transformed version. E.g, ``transforms.RandomCrop``
36         target_transform (callable, optional): A function/transform that takes in the
37             target and transforms it.
38         download (bool, optional): If true, downloads the dataset from the internet and
39             puts it in root directory. If dataset is already downloaded, it is not
40             downloaded again.
41 
42     """
43 
44     BASE_FOLDER = "widerface"
45     FILE_LIST = [
46         # File ID                             MD5 Hash                          Filename
47         ("0B6eKvaijfFUDQUUwd21EckhUbWs", "3fedf70df600953d25982bcd13d91ba2", "WIDER_train.zip"),
48         ("0B6eKvaijfFUDd3dIRmpvSk8tLUk", "dfa7d7e790efa35df3788964cf0bbaea", "WIDER_val.zip"),
49         ("0B6eKvaijfFUDbW4tdGpaYjgzZkU", "e5d8f4248ed24c334bbd12f49c29dd40", "WIDER_test.zip"),
50     ]
51     ANNOTATIONS_FILE = (
52         "http://mmlab.ie.cuhk.edu.hk/projects/WIDERFace/support/bbx_annotation/wider_face_split.zip",
53         "0e3767bcf0e326556d407bf5bff5d27c",
54         "wider_face_split.zip",
55     )
56 
57     def __init__(
58         self,
59         root: str,
60         split: str = "train",
61         transform: Optional[Callable] = None,
62         target_transform: Optional[Callable] = None,
63         download: bool = False,
64     ) -> None:
65         super(WIDERFace, self).__init__(
66             root=os.path.join(root, self.BASE_FOLDER), transform=transform, target_transform=target_transform
67         )
68         # check arguments
69         self.split = verify_str_arg(split, "split", ("train", "val", "test"))
70 
71         if download:
72             self.download()
73 
74         if not self._check_integrity():
75             raise RuntimeError(
76                 "Dataset not found or corrupted. " + "You can use download=True to download and prepare it"
77             )
78 
79         self.img_info: List[Dict[str, Union[str, Dict[str, torch.Tensor]]]] = []
80         if self.split in ("train", "val"):
81             self.parse_train_val_annotations_file()
82         else:
83             self.parse_test_annotations_file()
84 
85     def __getitem__(self, index: int) -> Tuple[Any, Any]:
86         """
87         Args:
88             index (int): Index
89 
90         Returns:
91             tuple: (image, target) where target is a dict of annotations for all faces in the image.
92             target=None for the test split.
93         """
94 
95         # stay consistent with other datasets and return a PIL Image
96         img = Image.open(self.img_info[index]["img_path"])
97 
98         if self.transform is not None:
99             img = self.transform(img)
100 
101         target = None if self.split == "test" else self.img_info[index]["annotations"]
102         if self.target_transform is not None:
103             target = self.target_transform(target)
104 
105         return img, target
106 
107     def __len__(self) -> int:
108         return len(self.img_info)
109 
110     def extra_repr(self) -> str:
111         lines = ["Split: {split}"]
112         return "\n".join(lines).format(**self.__dict__)
113 
114     def parse_train_val_annotations_file(self) -> None:
115         filename = "wider_face_train_bbx_gt.txt" if self.split == "train" else "wider_face_val_bbx_gt.txt"
116         filepath = os.path.join(self.root, "wider_face_split", filename)
117 
118         with open(filepath, "r") as f:
119             lines = f.readlines()
120             file_name_line, num_boxes_line, box_annotation_line = True, False, False
121             num_boxes, box_counter = 0, 0
122             labels = []
123             for line in lines:
124                 line = line.rstrip()
125                 if file_name_line:
126                     img_path = os.path.join(self.root, "WIDER_" + self.split, "images", line)
127                     img_path = abspath(expanduser(img_path))
128                     file_name_line = False
129                     num_boxes_line = True
130                 elif num_boxes_line:
131                     num_boxes = int(line)
132                     num_boxes_line = False
133                     box_annotation_line = True
134                 elif box_annotation_line:
135                     box_counter += 1
136                     line_split = line.split(" ")
137                     line_values = [int(x) for x in line_split]
138                     labels.append(line_values)
139                     if box_counter >= num_boxes:
140                         box_annotation_line = False
141                         file_name_line = True
142                         labels_tensor = torch.tensor(labels)
143                         self.img_info.append(
144                             {
145                                 "img_path": img_path,
146                                 "annotations": {
147                                     "bbox": labels_tensor[:, 0:4],  # x, y, width, height
148                                     "blur": labels_tensor[:, 4],
149                                     "expression": labels_tensor[:, 5],
150                                     "illumination": labels_tensor[:, 6],
151                                     "occlusion": labels_tensor[:, 7],
152                                     "pose": labels_tensor[:, 8],
153                                     "invalid": labels_tensor[:, 9],
154                                 },
155                             }
156                         )
157                         box_counter = 0
158                         labels.clear()
159                 else:
160                     raise RuntimeError("Error parsing annotation file {}".format(filepath))
161 
162     def parse_test_annotations_file(self) -> None:
163         filepath = os.path.join(self.root, "wider_face_split", "wider_face_test_filelist.txt")
164         filepath = abspath(expanduser(filepath))
165         with open(filepath, "r") as f:
166             lines = f.readlines()
167             for line in lines:
168                 line = line.rstrip()
169                 img_path = os.path.join(self.root, "WIDER_test", "images", line)
170                 img_path = abspath(expanduser(img_path))
171                 self.img_info.append({"img_path": img_path})
172 
173     def _check_integrity(self) -> bool:
174         # Allow original archive to be deleted (zip). Only need the extracted images
175         all_files = self.FILE_LIST.copy()
176         all_files.append(self.ANNOTATIONS_FILE)
177         for (_, md5, filename) in all_files:
178             file, ext = os.path.splitext(filename)
179             extracted_dir = os.path.join(self.root, file)
180             if not os.path.exists(extracted_dir):
181                 return False
182         return True
183 
184     def download(self) -> None:
185         if self._check_integrity():
186             print("Files already downloaded and verified")
187             return
188 
189         # download and extract image data
190         for (file_id, md5, filename) in self.FILE_LIST:
191             download_file_from_google_drive(file_id, self.root, filename, md5)
192             filepath = os.path.join(self.root, filename)
193             extract_archive(filepath)
194 
195         # download and extract annotation files
196         download_and_extract_archive(
197             url=self.ANNOTATIONS_FILE[0], download_root=self.root, md5=self.ANNOTATIONS_FILE[1]
198         )
199
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/torchvision/datasets/widerface.py b/torchvision/datasets/widerface.py
--- a/torchvision/datasets/widerface.py
+++ b/torchvision/datasets/widerface.py
@@ -43,13 +43,13 @@
 
     BASE_FOLDER = "widerface"
     FILE_LIST = [
-        # File ID                             MD5 Hash                          Filename
-        ("0B6eKvaijfFUDQUUwd21EckhUbWs", "3fedf70df600953d25982bcd13d91ba2", "WIDER_train.zip"),
-        ("0B6eKvaijfFUDd3dIRmpvSk8tLUk", "dfa7d7e790efa35df3788964cf0bbaea", "WIDER_val.zip"),
-        ("0B6eKvaijfFUDbW4tdGpaYjgzZkU", "e5d8f4248ed24c334bbd12f49c29dd40", "WIDER_test.zip"),
+        # File ID                             MD5 Hash                            Filename
+        ("15hGDLhsx8bLgLcIRD5DhYt5iBxnjNF1M", "3fedf70df600953d25982bcd13d91ba2", "WIDER_train.zip"),
+        ("1GUCogbp16PMGa39thoMMeWxp7Rp5oM8Q", "dfa7d7e790efa35df3788964cf0bbaea", "WIDER_val.zip"),
+        ("1HIfDbVEWKmsYKJZm4lchTBDLW5N7dY5T", "e5d8f4248ed24c334bbd12f49c29dd40", "WIDER_test.zip"),
     ]
     ANNOTATIONS_FILE = (
-        "http://mmlab.ie.cuhk.edu.hk/projects/WIDERFace/support/bbx_annotation/wider_face_split.zip",
+        "http://shuoyang1213.me/WIDERFACE/support/bbx_annotation/wider_face_split.zip",
         "0e3767bcf0e326556d407bf5bff5d27c",
         "wider_face_split.zip",
     )

{"golden_diff": "diff --git a/torchvision/datasets/widerface.py b/torchvision/datasets/widerface.py\n--- a/torchvision/datasets/widerface.py\n+++ b/torchvision/datasets/widerface.py\n@@ -43,13 +43,13 @@\n \n     BASE_FOLDER = \"widerface\"\n     FILE_LIST = [\n-        # File ID                             MD5 Hash                          Filename\n-        (\"0B6eKvaijfFUDQUUwd21EckhUbWs\", \"3fedf70df600953d25982bcd13d91ba2\", \"WIDER_train.zip\"),\n-        (\"0B6eKvaijfFUDd3dIRmpvSk8tLUk\", \"dfa7d7e790efa35df3788964cf0bbaea\", \"WIDER_val.zip\"),\n-        (\"0B6eKvaijfFUDbW4tdGpaYjgzZkU\", \"e5d8f4248ed24c334bbd12f49c29dd40\", \"WIDER_test.zip\"),\n+        # File ID                             MD5 Hash                            Filename\n+        (\"15hGDLhsx8bLgLcIRD5DhYt5iBxnjNF1M\", \"3fedf70df600953d25982bcd13d91ba2\", \"WIDER_train.zip\"),\n+        (\"1GUCogbp16PMGa39thoMMeWxp7Rp5oM8Q\", \"dfa7d7e790efa35df3788964cf0bbaea\", \"WIDER_val.zip\"),\n+        (\"1HIfDbVEWKmsYKJZm4lchTBDLW5N7dY5T\", \"e5d8f4248ed24c334bbd12f49c29dd40\", \"WIDER_test.zip\"),\n     ]\n     ANNOTATIONS_FILE = (\n-        \"http://mmlab.ie.cuhk.edu.hk/projects/WIDERFace/support/bbx_annotation/wider_face_split.zip\",\n+        \"http://shuoyang1213.me/WIDERFACE/support/bbx_annotation/wider_face_split.zip\",\n         \"0e3767bcf0e326556d407bf5bff5d27c\",\n         \"wider_face_split.zip\",\n     )\n", "issue": "WIDERFace download fails with zip error\nOriginally from https://github.com/pytorch/vision/pull/4614#issuecomment-943468223\r\n\r\n```py\r\nIn [4]: torchvision.datasets.WIDERFace(root='/tmp/lol', split='train', download=True)\r\n```\r\n\r\n```\r\n91473it [00:00, 9168293.30it/s]\r\n---------------------------------------------------------------------------\r\nBadZipFile                                Traceback (most recent call last)\r\n<ipython-input-4-61c4acdeef4e> in <module>\r\n----> 1 torchvision.datasets.WIDERFace(root='/tmp/lol', split='train', download=True)\r\n\r\n~/dev/vision/torchvision/datasets/widerface.py in __init__(self, root, split, transform, target_transform, download)\r\n     70\r\n     71         if download:\r\n---> 72             self.download()\r\n     73\r\n     74         if not self._check_integrity():\r\n\r\n~/dev/vision/torchvision/datasets/widerface.py in download(self)\r\n    191             download_file_from_google_drive(file_id, self.root, filename, md5)\r\n    192             filepath = os.path.join(self.root, filename)\r\n--> 193             extract_archive(filepath)\r\n    194\r\n    195         # download and extract annotation files\r\n\r\n~/dev/vision/torchvision/datasets/utils.py in extract_archive(from_path, to_path, remove_finished)\r\n    407     extractor = _ARCHIVE_EXTRACTORS[archive_type]\r\n    408\r\n--> 409     extractor(from_path, to_path, compression)\r\n    410\r\n    411     return to_path\r\n\r\n~/dev/vision/torchvision/datasets/utils.py in _extract_zip(from_path, to_path, compression)\r\n    281\r\n    282 def _extract_zip(from_path: str, to_path: str, compression: Optional[str]) -> None:\r\n--> 283     with zipfile.ZipFile(\r\n    284         from_path, \"r\", compression=_ZIP_COMPRESSION_MAP[compression] if compression else zipfile.ZIP_STORED\r\n    285     ) as zip:\r\n\r\n~/opt/miniconda3/envs/pt/lib/python3.8/zipfile.py in __init__(self, file, mode, compression, allowZip64, compresslevel, strict_timestamps)\r\n   1267         try:\r\n   1268             if mode == 'r':\r\n-> 1269                 self._RealGetContents()\r\n   1270             elif mode in ('w', 'x'):\r\n   1271                 # set the modified flag so central directory gets written\r\n\r\n~/opt/miniconda3/envs/pt/lib/python3.8/zipfile.py in _RealGetContents(self)\r\n   1334             raise BadZipFile(\"File is not a zip file\")\r\n   1335         if not endrec:\r\n-> 1336             raise BadZipFile(\"File is not a zip file\")\r\n   1337         if self.debug > 1:\r\n   1338             print(endrec)\r\n\r\nBadZipFile: File is not a zip file\r\n```\n\ncc @pmeier\n", "before_files": [{"content": "import os\nfrom os.path import abspath, expanduser\nfrom typing import Any, Callable, List, Dict, Optional, Tuple, Union\n\nimport torch\nfrom PIL import Image\n\nfrom .utils import (\n    download_file_from_google_drive,\n    download_and_extract_archive,\n    extract_archive,\n    verify_str_arg,\n)\nfrom .vision import VisionDataset\n\n\nclass WIDERFace(VisionDataset):\n    \"\"\"`WIDERFace <http://shuoyang1213.me/WIDERFACE/>`_ Dataset.\n\n    Args:\n        root (string): Root directory where images and annotations are downloaded to.\n            Expects the following folder structure if download=False:\n\n            .. code::\n\n                <root>\n                    \u2514\u2500\u2500 widerface\n                        \u251c\u2500\u2500 wider_face_split ('wider_face_split.zip' if compressed)\n                        \u251c\u2500\u2500 WIDER_train ('WIDER_train.zip' if compressed)\n                        \u251c\u2500\u2500 WIDER_val ('WIDER_val.zip' if compressed)\n                        \u2514\u2500\u2500 WIDER_test ('WIDER_test.zip' if compressed)\n        split (string): The dataset split to use. One of {``train``, ``val``, ``test``}.\n            Defaults to ``train``.\n        transform (callable, optional): A function/transform that  takes in a PIL image\n            and returns a transformed version. E.g, ``transforms.RandomCrop``\n        target_transform (callable, optional): A function/transform that takes in the\n            target and transforms it.\n        download (bool, optional): If true, downloads the dataset from the internet and\n            puts it in root directory. If dataset is already downloaded, it is not\n            downloaded again.\n\n    \"\"\"\n\n    BASE_FOLDER = \"widerface\"\n    FILE_LIST = [\n        # File ID                             MD5 Hash                          Filename\n        (\"0B6eKvaijfFUDQUUwd21EckhUbWs\", \"3fedf70df600953d25982bcd13d91ba2\", \"WIDER_train.zip\"),\n        (\"0B6eKvaijfFUDd3dIRmpvSk8tLUk\", \"dfa7d7e790efa35df3788964cf0bbaea\", \"WIDER_val.zip\"),\n        (\"0B6eKvaijfFUDbW4tdGpaYjgzZkU\", \"e5d8f4248ed24c334bbd12f49c29dd40\", \"WIDER_test.zip\"),\n    ]\n    ANNOTATIONS_FILE = (\n        \"http://mmlab.ie.cuhk.edu.hk/projects/WIDERFace/support/bbx_annotation/wider_face_split.zip\",\n        \"0e3767bcf0e326556d407bf5bff5d27c\",\n        \"wider_face_split.zip\",\n    )\n\n    def __init__(\n        self,\n        root: str,\n        split: str = \"train\",\n        transform: Optional[Callable] = None,\n        target_transform: Optional[Callable] = None,\n        download: bool = False,\n    ) -> None:\n        super(WIDERFace, self).__init__(\n            root=os.path.join(root, self.BASE_FOLDER), transform=transform, target_transform=target_transform\n        )\n        # check arguments\n        self.split = verify_str_arg(split, \"split\", (\"train\", \"val\", \"test\"))\n\n        if download:\n            self.download()\n\n        if not self._check_integrity():\n            raise RuntimeError(\n                \"Dataset not found or corrupted. \" + \"You can use download=True to download and prepare it\"\n            )\n\n        self.img_info: List[Dict[str, Union[str, Dict[str, torch.Tensor]]]] = []\n        if self.split in (\"train\", \"val\"):\n            self.parse_train_val_annotations_file()\n        else:\n            self.parse_test_annotations_file()\n\n    def __getitem__(self, index: int) -> Tuple[Any, Any]:\n        \"\"\"\n        Args:\n            index (int): Index\n\n        Returns:\n            tuple: (image, target) where target is a dict of annotations for all faces in the image.\n            target=None for the test split.\n        \"\"\"\n\n        # stay consistent with other datasets and return a PIL Image\n        img = Image.open(self.img_info[index][\"img_path\"])\n\n        if self.transform is not None:\n            img = self.transform(img)\n\n        target = None if self.split == \"test\" else self.img_info[index][\"annotations\"]\n        if self.target_transform is not None:\n            target = self.target_transform(target)\n\n        return img, target\n\n    def __len__(self) -> int:\n        return len(self.img_info)\n\n    def extra_repr(self) -> str:\n        lines = [\"Split: {split}\"]\n        return \"\\n\".join(lines).format(**self.__dict__)\n\n    def parse_train_val_annotations_file(self) -> None:\n        filename = \"wider_face_train_bbx_gt.txt\" if self.split == \"train\" else \"wider_face_val_bbx_gt.txt\"\n        filepath = os.path.join(self.root, \"wider_face_split\", filename)\n\n        with open(filepath, \"r\") as f:\n            lines = f.readlines()\n            file_name_line, num_boxes_line, box_annotation_line = True, False, False\n            num_boxes, box_counter = 0, 0\n            labels = []\n            for line in lines:\n                line = line.rstrip()\n                if file_name_line:\n                    img_path = os.path.join(self.root, \"WIDER_\" + self.split, \"images\", line)\n                    img_path = abspath(expanduser(img_path))\n                    file_name_line = False\n                    num_boxes_line = True\n                elif num_boxes_line:\n                    num_boxes = int(line)\n                    num_boxes_line = False\n                    box_annotation_line = True\n                elif box_annotation_line:\n                    box_counter += 1\n                    line_split = line.split(\" \")\n                    line_values = [int(x) for x in line_split]\n                    labels.append(line_values)\n                    if box_counter >= num_boxes:\n                        box_annotation_line = False\n                        file_name_line = True\n                        labels_tensor = torch.tensor(labels)\n                        self.img_info.append(\n                            {\n                                \"img_path\": img_path,\n                                \"annotations\": {\n                                    \"bbox\": labels_tensor[:, 0:4],  # x, y, width, height\n                                    \"blur\": labels_tensor[:, 4],\n                                    \"expression\": labels_tensor[:, 5],\n                                    \"illumination\": labels_tensor[:, 6],\n                                    \"occlusion\": labels_tensor[:, 7],\n                                    \"pose\": labels_tensor[:, 8],\n                                    \"invalid\": labels_tensor[:, 9],\n                                },\n                            }\n                        )\n                        box_counter = 0\n                        labels.clear()\n                else:\n                    raise RuntimeError(\"Error parsing annotation file {}\".format(filepath))\n\n    def parse_test_annotations_file(self) -> None:\n        filepath = os.path.join(self.root, \"wider_face_split\", \"wider_face_test_filelist.txt\")\n        filepath = abspath(expanduser(filepath))\n        with open(filepath, \"r\") as f:\n            lines = f.readlines()\n            for line in lines:\n                line = line.rstrip()\n                img_path = os.path.join(self.root, \"WIDER_test\", \"images\", line)\n                img_path = abspath(expanduser(img_path))\n                self.img_info.append({\"img_path\": img_path})\n\n    def _check_integrity(self) -> bool:\n        # Allow original archive to be deleted (zip). Only need the extracted images\n        all_files = self.FILE_LIST.copy()\n        all_files.append(self.ANNOTATIONS_FILE)\n        for (_, md5, filename) in all_files:\n            file, ext = os.path.splitext(filename)\n            extracted_dir = os.path.join(self.root, file)\n            if not os.path.exists(extracted_dir):\n                return False\n        return True\n\n    def download(self) -> None:\n        if self._check_integrity():\n            print(\"Files already downloaded and verified\")\n            return\n\n        # download and extract image data\n        for (file_id, md5, filename) in self.FILE_LIST:\n            download_file_from_google_drive(file_id, self.root, filename, md5)\n            filepath = os.path.join(self.root, filename)\n            extract_archive(filepath)\n\n        # download and extract annotation files\n        download_and_extract_archive(\n            url=self.ANNOTATIONS_FILE[0], download_root=self.root, md5=self.ANNOTATIONS_FILE[1]\n        )\n", "path": "torchvision/datasets/widerface.py"}], "after_files": [{"content": "import os\nfrom os.path import abspath, expanduser\nfrom typing import Any, Callable, List, Dict, Optional, Tuple, Union\n\nimport torch\nfrom PIL import Image\n\nfrom .utils import (\n    download_file_from_google_drive,\n    download_and_extract_archive,\n    extract_archive,\n    verify_str_arg,\n)\nfrom .vision import VisionDataset\n\n\nclass WIDERFace(VisionDataset):\n    \"\"\"`WIDERFace <http://shuoyang1213.me/WIDERFACE/>`_ Dataset.\n\n    Args:\n        root (string): Root directory where images and annotations are downloaded to.\n            Expects the following folder structure if download=False:\n\n            .. code::\n\n                <root>\n                    \u2514\u2500\u2500 widerface\n                        \u251c\u2500\u2500 wider_face_split ('wider_face_split.zip' if compressed)\n                        \u251c\u2500\u2500 WIDER_train ('WIDER_train.zip' if compressed)\n                        \u251c\u2500\u2500 WIDER_val ('WIDER_val.zip' if compressed)\n                        \u2514\u2500\u2500 WIDER_test ('WIDER_test.zip' if compressed)\n        split (string): The dataset split to use. One of {``train``, ``val``, ``test``}.\n            Defaults to ``train``.\n        transform (callable, optional): A function/transform that  takes in a PIL image\n            and returns a transformed version. E.g, ``transforms.RandomCrop``\n        target_transform (callable, optional): A function/transform that takes in the\n            target and transforms it.\n        download (bool, optional): If true, downloads the dataset from the internet and\n            puts it in root directory. If dataset is already downloaded, it is not\n            downloaded again.\n\n    \"\"\"\n\n    BASE_FOLDER = \"widerface\"\n    FILE_LIST = [\n        # File ID                             MD5 Hash                            Filename\n        (\"15hGDLhsx8bLgLcIRD5DhYt5iBxnjNF1M\", \"3fedf70df600953d25982bcd13d91ba2\", \"WIDER_train.zip\"),\n        (\"1GUCogbp16PMGa39thoMMeWxp7Rp5oM8Q\", \"dfa7d7e790efa35df3788964cf0bbaea\", \"WIDER_val.zip\"),\n        (\"1HIfDbVEWKmsYKJZm4lchTBDLW5N7dY5T\", \"e5d8f4248ed24c334bbd12f49c29dd40\", \"WIDER_test.zip\"),\n    ]\n    ANNOTATIONS_FILE = (\n        \"http://shuoyang1213.me/WIDERFACE/support/bbx_annotation/wider_face_split.zip\",\n        \"0e3767bcf0e326556d407bf5bff5d27c\",\n        \"wider_face_split.zip\",\n    )\n\n    def __init__(\n        self,\n        root: str,\n        split: str = \"train\",\n        transform: Optional[Callable] = None,\n        target_transform: Optional[Callable] = None,\n        download: bool = False,\n    ) -> None:\n        super(WIDERFace, self).__init__(\n            root=os.path.join(root, self.BASE_FOLDER), transform=transform, target_transform=target_transform\n        )\n        # check arguments\n        self.split = verify_str_arg(split, \"split\", (\"train\", \"val\", \"test\"))\n\n        if download:\n            self.download()\n\n        if not self._check_integrity():\n            raise RuntimeError(\n                \"Dataset not found or corrupted. \" + \"You can use download=True to download and prepare it\"\n            )\n\n        self.img_info: List[Dict[str, Union[str, Dict[str, torch.Tensor]]]] = []\n        if self.split in (\"train\", \"val\"):\n            self.parse_train_val_annotations_file()\n        else:\n            self.parse_test_annotations_file()\n\n    def __getitem__(self, index: int) -> Tuple[Any, Any]:\n        \"\"\"\n        Args:\n            index (int): Index\n\n        Returns:\n            tuple: (image, target) where target is a dict of annotations for all faces in the image.\n            target=None for the test split.\n        \"\"\"\n\n        # stay consistent with other datasets and return a PIL Image\n        img = Image.open(self.img_info[index][\"img_path\"])\n\n        if self.transform is not None:\n            img = self.transform(img)\n\n        target = None if self.split == \"test\" else self.img_info[index][\"annotations\"]\n        if self.target_transform is not None:\n            target = self.target_transform(target)\n\n        return img, target\n\n    def __len__(self) -> int:\n        return len(self.img_info)\n\n    def extra_repr(self) -> str:\n        lines = [\"Split: {split}\"]\n        return \"\\n\".join(lines).format(**self.__dict__)\n\n    def parse_train_val_annotations_file(self) -> None:\n        filename = \"wider_face_train_bbx_gt.txt\" if self.split == \"train\" else \"wider_face_val_bbx_gt.txt\"\n        filepath = os.path.join(self.root, \"wider_face_split\", filename)\n\n        with open(filepath, \"r\") as f:\n            lines = f.readlines()\n            file_name_line, num_boxes_line, box_annotation_line = True, False, False\n            num_boxes, box_counter = 0, 0\n            labels = []\n            for line in lines:\n                line = line.rstrip()\n                if file_name_line:\n                    img_path = os.path.join(self.root, \"WIDER_\" + self.split, \"images\", line)\n                    img_path = abspath(expanduser(img_path))\n                    file_name_line = False\n                    num_boxes_line = True\n                elif num_boxes_line:\n                    num_boxes = int(line)\n                    num_boxes_line = False\n                    box_annotation_line = True\n                elif box_annotation_line:\n                    box_counter += 1\n                    line_split = line.split(\" \")\n                    line_values = [int(x) for x in line_split]\n                    labels.append(line_values)\n                    if box_counter >= num_boxes:\n                        box_annotation_line = False\n                        file_name_line = True\n                        labels_tensor = torch.tensor(labels)\n                        self.img_info.append(\n                            {\n                                \"img_path\": img_path,\n                                \"annotations\": {\n                                    \"bbox\": labels_tensor[:, 0:4],  # x, y, width, height\n                                    \"blur\": labels_tensor[:, 4],\n                                    \"expression\": labels_tensor[:, 5],\n                                    \"illumination\": labels_tensor[:, 6],\n                                    \"occlusion\": labels_tensor[:, 7],\n                                    \"pose\": labels_tensor[:, 8],\n                                    \"invalid\": labels_tensor[:, 9],\n                                },\n                            }\n                        )\n                        box_counter = 0\n                        labels.clear()\n                else:\n                    raise RuntimeError(\"Error parsing annotation file {}\".format(filepath))\n\n    def parse_test_annotations_file(self) -> None:\n        filepath = os.path.join(self.root, \"wider_face_split\", \"wider_face_test_filelist.txt\")\n        filepath = abspath(expanduser(filepath))\n        with open(filepath, \"r\") as f:\n            lines = f.readlines()\n            for line in lines:\n                line = line.rstrip()\n                img_path = os.path.join(self.root, \"WIDER_test\", \"images\", line)\n                img_path = abspath(expanduser(img_path))\n                self.img_info.append({\"img_path\": img_path})\n\n    def _check_integrity(self) -> bool:\n        # Allow original archive to be deleted (zip). Only need the extracted images\n        all_files = self.FILE_LIST.copy()\n        all_files.append(self.ANNOTATIONS_FILE)\n        for (_, md5, filename) in all_files:\n            file, ext = os.path.splitext(filename)\n            extracted_dir = os.path.join(self.root, file)\n            if not os.path.exists(extracted_dir):\n                return False\n        return True\n\n    def download(self) -> None:\n        if self._check_integrity():\n            print(\"Files already downloaded and verified\")\n            return\n\n        # download and extract image data\n        for (file_id, md5, filename) in self.FILE_LIST:\n            download_file_from_google_drive(file_id, self.root, filename, md5)\n            filepath = os.path.join(self.root, filename)\n            extract_archive(filepath)\n\n        # download and extract annotation files\n        download_and_extract_archive(\n            url=self.ANNOTATIONS_FILE[0], download_root=self.root, md5=self.ANNOTATIONS_FILE[1]\n        )\n", "path": "torchvision/datasets/widerface.py"}]}