We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
A small bug in ImageNet Dataset Implementation
Currently, all values (i.e., index) in the `class_to_idx` and `wnid_to_idx` of `ImageNet` are 0.
The current code is as follows where `idcs` is wrong since it will fetch the indices of images instead of classes.
```python
        idcs = [idx for _, idx in self.imgs]
        self.wnids = self.classes
        self.wnid_to_idx = {wnid: idx for idx, wnid in zip(idcs, self.wnids)}
        self.classes = [wnid_to_classes[wnid] for wnid in self.wnids]
        self.class_to_idx = {cls: idx
                             for clss, idx in zip(self.classes, idcs)
                             for cls in clss}
```
A simple fix will be,
```python
        self.wnids = self.classes
        self.wnid_to_idx = self.class_to_idx   # ImageFolder handles it well
        self.classes, self.class_to_idx = [], {}
        for wnid, idx in self.wnid_to_idx.items():
            classes = wnid_to_classes[wnid]
            self.classes.append(classes)
            for c in classes:
                self.class_to_idx[c] = idx
```

--- 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/imagenet.py`
Content:
```
1 from __future__ import print_function
2 import os
3 import shutil
4 import tempfile
5 import torch
6 from .folder import ImageFolder
7 from .utils import check_integrity, download_and_extract_archive, extract_archive
8 
9 ARCHIVE_DICT = {
10     'train': {
11         'url': 'http://www.image-net.org/challenges/LSVRC/2012/nnoupb/ILSVRC2012_img_train.tar',
12         'md5': '1d675b47d978889d74fa0da5fadfb00e',
13     },
14     'val': {
15         'url': 'http://www.image-net.org/challenges/LSVRC/2012/nnoupb/ILSVRC2012_img_val.tar',
16         'md5': '29b22e2961454d5413ddabcf34fc5622',
17     },
18     'devkit': {
19         'url': 'http://www.image-net.org/challenges/LSVRC/2012/nnoupb/ILSVRC2012_devkit_t12.tar.gz',
20         'md5': 'fa75699e90414af021442c21a62c3abf',
21     }
22 }
23 
24 
25 class ImageNet(ImageFolder):
26     """`ImageNet <http://image-net.org/>`_ 2012 Classification Dataset.
27 
28     Args:
29         root (string): Root directory of the ImageNet Dataset.
30         split (string, optional): The dataset split, supports ``train``, or ``val``.
31         download (bool, optional): If true, downloads the dataset from the internet and
32             puts it in root directory. If dataset is already downloaded, it is not
33             downloaded again.
34         transform (callable, optional): A function/transform that  takes in an 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         loader (callable, optional): A function to load an image given its path.
39 
40      Attributes:
41         classes (list): List of the class names.
42         class_to_idx (dict): Dict with items (class_name, class_index).
43         wnids (list): List of the WordNet IDs.
44         wnid_to_idx (dict): Dict with items (wordnet_id, class_index).
45         imgs (list): List of (image path, class_index) tuples
46         targets (list): The class_index value for each image in the dataset
47     """
48 
49     def __init__(self, root, split='train', download=False, **kwargs):
50         root = self.root = os.path.expanduser(root)
51         self.split = self._verify_split(split)
52 
53         if download:
54             self.download()
55         wnid_to_classes = self._load_meta_file()[0]
56 
57         super(ImageNet, self).__init__(self.split_folder, **kwargs)
58         self.root = root
59 
60         idcs = [idx for _, idx in self.imgs]
61         self.wnids = self.classes
62         self.wnid_to_idx = {wnid: idx for idx, wnid in zip(idcs, self.wnids)}
63         self.classes = [wnid_to_classes[wnid] for wnid in self.wnids]
64         self.class_to_idx = {cls: idx
65                              for clss, idx in zip(self.classes, idcs)
66                              for cls in clss}
67 
68     def download(self):
69         if not check_integrity(self.meta_file):
70             tmp_dir = tempfile.mkdtemp()
71 
72             archive_dict = ARCHIVE_DICT['devkit']
73             download_and_extract_archive(archive_dict['url'], self.root,
74                                          extract_root=tmp_dir,
75                                          md5=archive_dict['md5'])
76             devkit_folder = _splitexts(os.path.basename(archive_dict['url']))[0]
77             meta = parse_devkit(os.path.join(tmp_dir, devkit_folder))
78             self._save_meta_file(*meta)
79 
80             shutil.rmtree(tmp_dir)
81 
82         if not os.path.isdir(self.split_folder):
83             archive_dict = ARCHIVE_DICT[self.split]
84             download_and_extract_archive(archive_dict['url'], self.root,
85                                          extract_root=self.split_folder,
86                                          md5=archive_dict['md5'])
87 
88             if self.split == 'train':
89                 prepare_train_folder(self.split_folder)
90             elif self.split == 'val':
91                 val_wnids = self._load_meta_file()[1]
92                 prepare_val_folder(self.split_folder, val_wnids)
93         else:
94             msg = ("You set download=True, but a folder '{}' already exist in "
95                    "the root directory. If you want to re-download or re-extract the "
96                    "archive, delete the folder.")
97             print(msg.format(self.split))
98 
99     @property
100     def meta_file(self):
101         return os.path.join(self.root, 'meta.bin')
102 
103     def _load_meta_file(self):
104         if check_integrity(self.meta_file):
105             return torch.load(self.meta_file)
106         else:
107             raise RuntimeError("Meta file not found or corrupted.",
108                                "You can use download=True to create it.")
109 
110     def _save_meta_file(self, wnid_to_class, val_wnids):
111         torch.save((wnid_to_class, val_wnids), self.meta_file)
112 
113     def _verify_split(self, split):
114         if split not in self.valid_splits:
115             msg = "Unknown split {} .".format(split)
116             msg += "Valid splits are {{}}.".format(", ".join(self.valid_splits))
117             raise ValueError(msg)
118         return split
119 
120     @property
121     def valid_splits(self):
122         return 'train', 'val'
123 
124     @property
125     def split_folder(self):
126         return os.path.join(self.root, self.split)
127 
128     def extra_repr(self):
129         return "Split: {split}".format(**self.__dict__)
130 
131 
132 def parse_devkit(root):
133     idx_to_wnid, wnid_to_classes = parse_meta(root)
134     val_idcs = parse_val_groundtruth(root)
135     val_wnids = [idx_to_wnid[idx] for idx in val_idcs]
136     return wnid_to_classes, val_wnids
137 
138 
139 def parse_meta(devkit_root, path='data', filename='meta.mat'):
140     import scipy.io as sio
141 
142     metafile = os.path.join(devkit_root, path, filename)
143     meta = sio.loadmat(metafile, squeeze_me=True)['synsets']
144     nums_children = list(zip(*meta))[4]
145     meta = [meta[idx] for idx, num_children in enumerate(nums_children)
146             if num_children == 0]
147     idcs, wnids, classes = list(zip(*meta))[:3]
148     classes = [tuple(clss.split(', ')) for clss in classes]
149     idx_to_wnid = {idx: wnid for idx, wnid in zip(idcs, wnids)}
150     wnid_to_classes = {wnid: clss for wnid, clss in zip(wnids, classes)}
151     return idx_to_wnid, wnid_to_classes
152 
153 
154 def parse_val_groundtruth(devkit_root, path='data',
155                           filename='ILSVRC2012_validation_ground_truth.txt'):
156     with open(os.path.join(devkit_root, path, filename), 'r') as txtfh:
157         val_idcs = txtfh.readlines()
158     return [int(val_idx) for val_idx in val_idcs]
159 
160 
161 def prepare_train_folder(folder):
162     for archive in [os.path.join(folder, archive) for archive in os.listdir(folder)]:
163         extract_archive(archive, os.path.splitext(archive)[0], remove_finished=True)
164 
165 
166 def prepare_val_folder(folder, wnids):
167     img_files = sorted([os.path.join(folder, file) for file in os.listdir(folder)])
168 
169     for wnid in set(wnids):
170         os.mkdir(os.path.join(folder, wnid))
171 
172     for wnid, img_file in zip(wnids, img_files):
173         shutil.move(img_file, os.path.join(folder, wnid, os.path.basename(img_file)))
174 
175 
176 def _splitexts(root):
177     exts = []
178     ext = '.'
179     while ext:
180         root, ext = os.path.splitext(root)
181         exts.append(ext)
182     return root, ''.join(reversed(exts))
183
```
--- 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/imagenet.py b/torchvision/datasets/imagenet.py
--- a/torchvision/datasets/imagenet.py
+++ b/torchvision/datasets/imagenet.py
@@ -38,7 +38,7 @@
         loader (callable, optional): A function to load an image given its path.
 
      Attributes:
-        classes (list): List of the class names.
+        classes (list): List of the class name tuples.
         class_to_idx (dict): Dict with items (class_name, class_index).
         wnids (list): List of the WordNet IDs.
         wnid_to_idx (dict): Dict with items (wordnet_id, class_index).
@@ -57,12 +57,11 @@
         super(ImageNet, self).__init__(self.split_folder, **kwargs)
         self.root = root
 
-        idcs = [idx for _, idx in self.imgs]
         self.wnids = self.classes
-        self.wnid_to_idx = {wnid: idx for idx, wnid in zip(idcs, self.wnids)}
+        self.wnid_to_idx = self.class_to_idx
         self.classes = [wnid_to_classes[wnid] for wnid in self.wnids]
         self.class_to_idx = {cls: idx
-                             for clss, idx in zip(self.classes, idcs)
+                             for idx, clss in enumerate(self.classes)
                              for cls in clss}
 
     def download(self):

{"golden_diff": "diff --git a/torchvision/datasets/imagenet.py b/torchvision/datasets/imagenet.py\n--- a/torchvision/datasets/imagenet.py\n+++ b/torchvision/datasets/imagenet.py\n@@ -38,7 +38,7 @@\n         loader (callable, optional): A function to load an image given its path.\n \n      Attributes:\n-        classes (list): List of the class names.\n+        classes (list): List of the class name tuples.\n         class_to_idx (dict): Dict with items (class_name, class_index).\n         wnids (list): List of the WordNet IDs.\n         wnid_to_idx (dict): Dict with items (wordnet_id, class_index).\n@@ -57,12 +57,11 @@\n         super(ImageNet, self).__init__(self.split_folder, **kwargs)\n         self.root = root\n \n-        idcs = [idx for _, idx in self.imgs]\n         self.wnids = self.classes\n-        self.wnid_to_idx = {wnid: idx for idx, wnid in zip(idcs, self.wnids)}\n+        self.wnid_to_idx = self.class_to_idx\n         self.classes = [wnid_to_classes[wnid] for wnid in self.wnids]\n         self.class_to_idx = {cls: idx\n-                             for clss, idx in zip(self.classes, idcs)\n+                             for idx, clss in enumerate(self.classes)\n                              for cls in clss}\n \n     def download(self):\n", "issue": "A small bug in ImageNet Dataset Implementation\nCurrently, all values (i.e., index) in the `class_to_idx` and `wnid_to_idx` of `ImageNet` are 0.\r\nThe current code is as follows where `idcs` is wrong since it will fetch the indices of images instead of classes.\r\n```python\r\n        idcs = [idx for _, idx in self.imgs]\r\n        self.wnids = self.classes\r\n        self.wnid_to_idx = {wnid: idx for idx, wnid in zip(idcs, self.wnids)}\r\n        self.classes = [wnid_to_classes[wnid] for wnid in self.wnids]\r\n        self.class_to_idx = {cls: idx\r\n                             for clss, idx in zip(self.classes, idcs)\r\n                             for cls in clss}\r\n```\r\nA simple fix will be,\r\n```python\r\n        self.wnids = self.classes\r\n        self.wnid_to_idx = self.class_to_idx   # ImageFolder handles it well\r\n        self.classes, self.class_to_idx = [], {}\r\n        for wnid, idx in self.wnid_to_idx.items():\r\n            classes = wnid_to_classes[wnid]\r\n            self.classes.append(classes)\r\n            for c in classes:\r\n                self.class_to_idx[c] = idx\r\n```\n", "before_files": [{"content": "from __future__ import print_function\nimport os\nimport shutil\nimport tempfile\nimport torch\nfrom .folder import ImageFolder\nfrom .utils import check_integrity, download_and_extract_archive, extract_archive\n\nARCHIVE_DICT = {\n    'train': {\n        'url': 'http://www.image-net.org/challenges/LSVRC/2012/nnoupb/ILSVRC2012_img_train.tar',\n        'md5': '1d675b47d978889d74fa0da5fadfb00e',\n    },\n    'val': {\n        'url': 'http://www.image-net.org/challenges/LSVRC/2012/nnoupb/ILSVRC2012_img_val.tar',\n        'md5': '29b22e2961454d5413ddabcf34fc5622',\n    },\n    'devkit': {\n        'url': 'http://www.image-net.org/challenges/LSVRC/2012/nnoupb/ILSVRC2012_devkit_t12.tar.gz',\n        'md5': 'fa75699e90414af021442c21a62c3abf',\n    }\n}\n\n\nclass ImageNet(ImageFolder):\n    \"\"\"`ImageNet <http://image-net.org/>`_ 2012 Classification Dataset.\n\n    Args:\n        root (string): Root directory of the ImageNet Dataset.\n        split (string, optional): The dataset split, supports ``train``, or ``val``.\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        transform (callable, optional): A function/transform that  takes in an 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        loader (callable, optional): A function to load an image given its path.\n\n     Attributes:\n        classes (list): List of the class names.\n        class_to_idx (dict): Dict with items (class_name, class_index).\n        wnids (list): List of the WordNet IDs.\n        wnid_to_idx (dict): Dict with items (wordnet_id, class_index).\n        imgs (list): List of (image path, class_index) tuples\n        targets (list): The class_index value for each image in the dataset\n    \"\"\"\n\n    def __init__(self, root, split='train', download=False, **kwargs):\n        root = self.root = os.path.expanduser(root)\n        self.split = self._verify_split(split)\n\n        if download:\n            self.download()\n        wnid_to_classes = self._load_meta_file()[0]\n\n        super(ImageNet, self).__init__(self.split_folder, **kwargs)\n        self.root = root\n\n        idcs = [idx for _, idx in self.imgs]\n        self.wnids = self.classes\n        self.wnid_to_idx = {wnid: idx for idx, wnid in zip(idcs, self.wnids)}\n        self.classes = [wnid_to_classes[wnid] for wnid in self.wnids]\n        self.class_to_idx = {cls: idx\n                             for clss, idx in zip(self.classes, idcs)\n                             for cls in clss}\n\n    def download(self):\n        if not check_integrity(self.meta_file):\n            tmp_dir = tempfile.mkdtemp()\n\n            archive_dict = ARCHIVE_DICT['devkit']\n            download_and_extract_archive(archive_dict['url'], self.root,\n                                         extract_root=tmp_dir,\n                                         md5=archive_dict['md5'])\n            devkit_folder = _splitexts(os.path.basename(archive_dict['url']))[0]\n            meta = parse_devkit(os.path.join(tmp_dir, devkit_folder))\n            self._save_meta_file(*meta)\n\n            shutil.rmtree(tmp_dir)\n\n        if not os.path.isdir(self.split_folder):\n            archive_dict = ARCHIVE_DICT[self.split]\n            download_and_extract_archive(archive_dict['url'], self.root,\n                                         extract_root=self.split_folder,\n                                         md5=archive_dict['md5'])\n\n            if self.split == 'train':\n                prepare_train_folder(self.split_folder)\n            elif self.split == 'val':\n                val_wnids = self._load_meta_file()[1]\n                prepare_val_folder(self.split_folder, val_wnids)\n        else:\n            msg = (\"You set download=True, but a folder '{}' already exist in \"\n                   \"the root directory. If you want to re-download or re-extract the \"\n                   \"archive, delete the folder.\")\n            print(msg.format(self.split))\n\n    @property\n    def meta_file(self):\n        return os.path.join(self.root, 'meta.bin')\n\n    def _load_meta_file(self):\n        if check_integrity(self.meta_file):\n            return torch.load(self.meta_file)\n        else:\n            raise RuntimeError(\"Meta file not found or corrupted.\",\n                               \"You can use download=True to create it.\")\n\n    def _save_meta_file(self, wnid_to_class, val_wnids):\n        torch.save((wnid_to_class, val_wnids), self.meta_file)\n\n    def _verify_split(self, split):\n        if split not in self.valid_splits:\n            msg = \"Unknown split {} .\".format(split)\n            msg += \"Valid splits are {{}}.\".format(\", \".join(self.valid_splits))\n            raise ValueError(msg)\n        return split\n\n    @property\n    def valid_splits(self):\n        return 'train', 'val'\n\n    @property\n    def split_folder(self):\n        return os.path.join(self.root, self.split)\n\n    def extra_repr(self):\n        return \"Split: {split}\".format(**self.__dict__)\n\n\ndef parse_devkit(root):\n    idx_to_wnid, wnid_to_classes = parse_meta(root)\n    val_idcs = parse_val_groundtruth(root)\n    val_wnids = [idx_to_wnid[idx] for idx in val_idcs]\n    return wnid_to_classes, val_wnids\n\n\ndef parse_meta(devkit_root, path='data', filename='meta.mat'):\n    import scipy.io as sio\n\n    metafile = os.path.join(devkit_root, path, filename)\n    meta = sio.loadmat(metafile, squeeze_me=True)['synsets']\n    nums_children = list(zip(*meta))[4]\n    meta = [meta[idx] for idx, num_children in enumerate(nums_children)\n            if num_children == 0]\n    idcs, wnids, classes = list(zip(*meta))[:3]\n    classes = [tuple(clss.split(', ')) for clss in classes]\n    idx_to_wnid = {idx: wnid for idx, wnid in zip(idcs, wnids)}\n    wnid_to_classes = {wnid: clss for wnid, clss in zip(wnids, classes)}\n    return idx_to_wnid, wnid_to_classes\n\n\ndef parse_val_groundtruth(devkit_root, path='data',\n                          filename='ILSVRC2012_validation_ground_truth.txt'):\n    with open(os.path.join(devkit_root, path, filename), 'r') as txtfh:\n        val_idcs = txtfh.readlines()\n    return [int(val_idx) for val_idx in val_idcs]\n\n\ndef prepare_train_folder(folder):\n    for archive in [os.path.join(folder, archive) for archive in os.listdir(folder)]:\n        extract_archive(archive, os.path.splitext(archive)[0], remove_finished=True)\n\n\ndef prepare_val_folder(folder, wnids):\n    img_files = sorted([os.path.join(folder, file) for file in os.listdir(folder)])\n\n    for wnid in set(wnids):\n        os.mkdir(os.path.join(folder, wnid))\n\n    for wnid, img_file in zip(wnids, img_files):\n        shutil.move(img_file, os.path.join(folder, wnid, os.path.basename(img_file)))\n\n\ndef _splitexts(root):\n    exts = []\n    ext = '.'\n    while ext:\n        root, ext = os.path.splitext(root)\n        exts.append(ext)\n    return root, ''.join(reversed(exts))\n", "path": "torchvision/datasets/imagenet.py"}], "after_files": [{"content": "from __future__ import print_function\nimport os\nimport shutil\nimport tempfile\nimport torch\nfrom .folder import ImageFolder\nfrom .utils import check_integrity, download_and_extract_archive, extract_archive\n\nARCHIVE_DICT = {\n    'train': {\n        'url': 'http://www.image-net.org/challenges/LSVRC/2012/nnoupb/ILSVRC2012_img_train.tar',\n        'md5': '1d675b47d978889d74fa0da5fadfb00e',\n    },\n    'val': {\n        'url': 'http://www.image-net.org/challenges/LSVRC/2012/nnoupb/ILSVRC2012_img_val.tar',\n        'md5': '29b22e2961454d5413ddabcf34fc5622',\n    },\n    'devkit': {\n        'url': 'http://www.image-net.org/challenges/LSVRC/2012/nnoupb/ILSVRC2012_devkit_t12.tar.gz',\n        'md5': 'fa75699e90414af021442c21a62c3abf',\n    }\n}\n\n\nclass ImageNet(ImageFolder):\n    \"\"\"`ImageNet <http://image-net.org/>`_ 2012 Classification Dataset.\n\n    Args:\n        root (string): Root directory of the ImageNet Dataset.\n        split (string, optional): The dataset split, supports ``train``, or ``val``.\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        transform (callable, optional): A function/transform that  takes in an 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        loader (callable, optional): A function to load an image given its path.\n\n     Attributes:\n        classes (list): List of the class name tuples.\n        class_to_idx (dict): Dict with items (class_name, class_index).\n        wnids (list): List of the WordNet IDs.\n        wnid_to_idx (dict): Dict with items (wordnet_id, class_index).\n        imgs (list): List of (image path, class_index) tuples\n        targets (list): The class_index value for each image in the dataset\n    \"\"\"\n\n    def __init__(self, root, split='train', download=False, **kwargs):\n        root = self.root = os.path.expanduser(root)\n        self.split = self._verify_split(split)\n\n        if download:\n            self.download()\n        wnid_to_classes = self._load_meta_file()[0]\n\n        super(ImageNet, self).__init__(self.split_folder, **kwargs)\n        self.root = root\n\n        self.wnids = self.classes\n        self.wnid_to_idx = self.class_to_idx\n        self.classes = [wnid_to_classes[wnid] for wnid in self.wnids]\n        self.class_to_idx = {cls: idx\n                             for idx, clss in enumerate(self.classes)\n                             for cls in clss}\n\n    def download(self):\n        if not check_integrity(self.meta_file):\n            tmp_dir = tempfile.mkdtemp()\n\n            archive_dict = ARCHIVE_DICT['devkit']\n            download_and_extract_archive(archive_dict['url'], self.root,\n                                         extract_root=tmp_dir,\n                                         md5=archive_dict['md5'])\n            devkit_folder = _splitexts(os.path.basename(archive_dict['url']))[0]\n            meta = parse_devkit(os.path.join(tmp_dir, devkit_folder))\n            self._save_meta_file(*meta)\n\n            shutil.rmtree(tmp_dir)\n\n        if not os.path.isdir(self.split_folder):\n            archive_dict = ARCHIVE_DICT[self.split]\n            download_and_extract_archive(archive_dict['url'], self.root,\n                                         extract_root=self.split_folder,\n                                         md5=archive_dict['md5'])\n\n            if self.split == 'train':\n                prepare_train_folder(self.split_folder)\n            elif self.split == 'val':\n                val_wnids = self._load_meta_file()[1]\n                prepare_val_folder(self.split_folder, val_wnids)\n        else:\n            msg = (\"You set download=True, but a folder '{}' already exist in \"\n                   \"the root directory. If you want to re-download or re-extract the \"\n                   \"archive, delete the folder.\")\n            print(msg.format(self.split))\n\n    @property\n    def meta_file(self):\n        return os.path.join(self.root, 'meta.bin')\n\n    def _load_meta_file(self):\n        if check_integrity(self.meta_file):\n            return torch.load(self.meta_file)\n        else:\n            raise RuntimeError(\"Meta file not found or corrupted.\",\n                               \"You can use download=True to create it.\")\n\n    def _save_meta_file(self, wnid_to_class, val_wnids):\n        torch.save((wnid_to_class, val_wnids), self.meta_file)\n\n    def _verify_split(self, split):\n        if split not in self.valid_splits:\n            msg = \"Unknown split {} .\".format(split)\n            msg += \"Valid splits are {{}}.\".format(\", \".join(self.valid_splits))\n            raise ValueError(msg)\n        return split\n\n    @property\n    def valid_splits(self):\n        return 'train', 'val'\n\n    @property\n    def split_folder(self):\n        return os.path.join(self.root, self.split)\n\n    def extra_repr(self):\n        return \"Split: {split}\".format(**self.__dict__)\n\n\ndef parse_devkit(root):\n    idx_to_wnid, wnid_to_classes = parse_meta(root)\n    val_idcs = parse_val_groundtruth(root)\n    val_wnids = [idx_to_wnid[idx] for idx in val_idcs]\n    return wnid_to_classes, val_wnids\n\n\ndef parse_meta(devkit_root, path='data', filename='meta.mat'):\n    import scipy.io as sio\n\n    metafile = os.path.join(devkit_root, path, filename)\n    meta = sio.loadmat(metafile, squeeze_me=True)['synsets']\n    nums_children = list(zip(*meta))[4]\n    meta = [meta[idx] for idx, num_children in enumerate(nums_children)\n            if num_children == 0]\n    idcs, wnids, classes = list(zip(*meta))[:3]\n    classes = [tuple(clss.split(', ')) for clss in classes]\n    idx_to_wnid = {idx: wnid for idx, wnid in zip(idcs, wnids)}\n    wnid_to_classes = {wnid: clss for wnid, clss in zip(wnids, classes)}\n    return idx_to_wnid, wnid_to_classes\n\n\ndef parse_val_groundtruth(devkit_root, path='data',\n                          filename='ILSVRC2012_validation_ground_truth.txt'):\n    with open(os.path.join(devkit_root, path, filename), 'r') as txtfh:\n        val_idcs = txtfh.readlines()\n    return [int(val_idx) for val_idx in val_idcs]\n\n\ndef prepare_train_folder(folder):\n    for archive in [os.path.join(folder, archive) for archive in os.listdir(folder)]:\n        extract_archive(archive, os.path.splitext(archive)[0], remove_finished=True)\n\n\ndef prepare_val_folder(folder, wnids):\n    img_files = sorted([os.path.join(folder, file) for file in os.listdir(folder)])\n\n    for wnid in set(wnids):\n        os.mkdir(os.path.join(folder, wnid))\n\n    for wnid, img_file in zip(wnids, img_files):\n        shutil.move(img_file, os.path.join(folder, wnid, os.path.basename(img_file)))\n\n\ndef _splitexts(root):\n    exts = []\n    ext = '.'\n    while ext:\n        root, ext = os.path.splitext(root)\n        exts.append(ext)\n    return root, ''.join(reversed(exts))\n", "path": "torchvision/datasets/imagenet.py"}]}