We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
torchvision.dataset.STL10.__load_folds() loads image indices using uint8.
## 🐛 Bug

<!-- A clear and concise description of what the bug is. -->
There seems a bug to load STL-10 dataset using torchvision.dataset.STL10.
I think the bug causes from "uint8" used on _load_folds() function. The maximum range of uint8 is 0 to 255.
However, the range of STL-10 images for the training is 0 to 4999. So overflow happened when loading data.
It would be better to change "uint8" to "int" used on _load_folds() function.

## To Reproduce

Steps to reproduce the behavior:

1. current __load_folds() in torchvision.datasets.STL10
```
    def __load_folds(self, folds: Optional[int]) -> None:
        # loads one of the folds if specified
        if folds is None:
            return
        path_to_folds = os.path.join(
            self.root, self.base_folder, self.folds_list_file)
        with open(path_to_folds, 'r') as f:
            str_idx = f.read().splitlines()[folds]
            list_idx = np.fromstring(str_idx, dtype=np.uint8, sep=' ')
            self.data, self.labels = self.data[list_idx, :, :, :], self.labels[list_idx]
```

2. image indices[:20] of fold-5 in "fold_indices.txt"
1632 1914 1739 4639 1009 4160 4035 2197 2513 4705 2793 4056 2413 4147 2213 4980 1321 3163 4027 874 ...

3. load STL-10 fold-5 with current __load_folds()
```
    from torchvision.datasets import STL10
    data_dir = 'path/to/stl10'
    split = 'train'
    folds = 4  # fold_index (= fold_number - 1)
    dataset = STL10(data_dir, split=split, folds=folds, download=True)
```

4. loaded indices[:20]
96 122 203 31 241 64 195 149 209 97 233 216 109 51 165 116 41 91 187 106 ...

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Expected behavior

<!-- A clear and concise description of what you expected to happen. -->
1. load STL-10 fold-5 without current __load_folds()
```
    from torchvision.datasets import STL10
    data_dir = 'path/to/stl10'
    split = 'train'
    folds = 4  # fold_index (= fold_number - 1)
    dataset = STL10(data_dir, split=split, folds=None, download=True)

    ##############################
    # from __load_folds()
    path_to_folds = os.path.join(
        dataset.root, dataset.base_folder, dataset.folds_list_file)
    with open(path_to_folds, 'r') as f:
        str_idx = f.read().splitlines()[folds]
        # [MODIFIED] np.uint8 => np.int64
        # list_idx = np.fromstring(str_idx, dtype=np.uint8, sep=' ')
        list_idx = np.fromstring(str_idx, dtype=np.int64, sep=' ')
        dataset.data, dataset.labels = dataset.data[list_idx, :, :, :], dataset.labels[list_idx]
    ##############################
```

2. loaded indices[:20]
1632 1914 1739 4639 1009 4160 4035 2197 2513 4705 2793 4056 2413 4147 2213 4980 1321 3163 4027 874 ...

## Environment

Please copy and paste the output from our
[environment collection script](https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py)
(or fill out the checklist below manually).

You can get the script and run it with:
```
wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
```

 - PyTorch / torchvision Version (e.g., 1.0 / 0.4.0): 1.7.1 / 0.8.2
 - OS (e.g., Linux): Ubuntu 18.04.5 LTS (x86_64)
 - How you installed PyTorch / torchvision (`conda`, `pip`, source): pip
 - Build command you used (if compiling from source): -
 - Python version: 3.7 (64-bit runtime)
 - CUDA/cuDNN version: 10.2/8.0.5
 - GPU models and configuration: V100
 - Any other relevant information:

## Additional context

<!-- Add any other context about the problem here. -->


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/stl10.py`
Content:
```
1 from PIL import Image
2 import os
3 import os.path
4 import numpy as np
5 from typing import Any, Callable, Optional, Tuple
6 
7 from .vision import VisionDataset
8 from .utils import check_integrity, download_and_extract_archive, verify_str_arg
9 
10 
11 class STL10(VisionDataset):
12     """`STL10 <https://cs.stanford.edu/~acoates/stl10/>`_ Dataset.
13 
14     Args:
15         root (string): Root directory of dataset where directory
16             ``stl10_binary`` exists.
17         split (string): One of {'train', 'test', 'unlabeled', 'train+unlabeled'}.
18             Accordingly dataset is selected.
19         folds (int, optional): One of {0-9} or None.
20             For training, loads one of the 10 pre-defined folds of 1k samples for the
21             standard evaluation procedure. If no value is passed, loads the 5k samples.
22         transform (callable, optional): A function/transform that  takes in an PIL image
23             and returns a transformed version. E.g, ``transforms.RandomCrop``
24         target_transform (callable, optional): A function/transform that takes in the
25             target and transforms it.
26         download (bool, optional): If true, downloads the dataset from the internet and
27             puts it in root directory. If dataset is already downloaded, it is not
28             downloaded again.
29     """
30     base_folder = 'stl10_binary'
31     url = "http://ai.stanford.edu/~acoates/stl10/stl10_binary.tar.gz"
32     filename = "stl10_binary.tar.gz"
33     tgz_md5 = '91f7769df0f17e558f3565bffb0c7dfb'
34     class_names_file = 'class_names.txt'
35     folds_list_file = 'fold_indices.txt'
36     train_list = [
37         ['train_X.bin', '918c2871b30a85fa023e0c44e0bee87f'],
38         ['train_y.bin', '5a34089d4802c674881badbb80307741'],
39         ['unlabeled_X.bin', '5242ba1fed5e4be9e1e742405eb56ca4']
40     ]
41 
42     test_list = [
43         ['test_X.bin', '7f263ba9f9e0b06b93213547f721ac82'],
44         ['test_y.bin', '36f9794fa4beb8a2c72628de14fa638e']
45     ]
46     splits = ('train', 'train+unlabeled', 'unlabeled', 'test')
47 
48     def __init__(
49             self,
50             root: str,
51             split: str = "train",
52             folds: Optional[int] = None,
53             transform: Optional[Callable] = None,
54             target_transform: Optional[Callable] = None,
55             download: bool = False,
56     ) -> None:
57         super(STL10, self).__init__(root, transform=transform,
58                                     target_transform=target_transform)
59         self.split = verify_str_arg(split, "split", self.splits)
60         self.folds = self._verify_folds(folds)
61 
62         if download:
63             self.download()
64         elif not self._check_integrity():
65             raise RuntimeError(
66                 'Dataset not found or corrupted. '
67                 'You can use download=True to download it')
68 
69         # now load the picked numpy arrays
70         self.labels: Optional[np.ndarray]
71         if self.split == 'train':
72             self.data, self.labels = self.__loadfile(
73                 self.train_list[0][0], self.train_list[1][0])
74             self.__load_folds(folds)
75 
76         elif self.split == 'train+unlabeled':
77             self.data, self.labels = self.__loadfile(
78                 self.train_list[0][0], self.train_list[1][0])
79             self.__load_folds(folds)
80             unlabeled_data, _ = self.__loadfile(self.train_list[2][0])
81             self.data = np.concatenate((self.data, unlabeled_data))
82             self.labels = np.concatenate(
83                 (self.labels, np.asarray([-1] * unlabeled_data.shape[0])))
84 
85         elif self.split == 'unlabeled':
86             self.data, _ = self.__loadfile(self.train_list[2][0])
87             self.labels = np.asarray([-1] * self.data.shape[0])
88         else:  # self.split == 'test':
89             self.data, self.labels = self.__loadfile(
90                 self.test_list[0][0], self.test_list[1][0])
91 
92         class_file = os.path.join(
93             self.root, self.base_folder, self.class_names_file)
94         if os.path.isfile(class_file):
95             with open(class_file) as f:
96                 self.classes = f.read().splitlines()
97 
98     def _verify_folds(self, folds: Optional[int]) -> Optional[int]:
99         if folds is None:
100             return folds
101         elif isinstance(folds, int):
102             if folds in range(10):
103                 return folds
104             msg = ("Value for argument folds should be in the range [0, 10), "
105                    "but got {}.")
106             raise ValueError(msg.format(folds))
107         else:
108             msg = "Expected type None or int for argument folds, but got type {}."
109             raise ValueError(msg.format(type(folds)))
110 
111     def __getitem__(self, index: int) -> Tuple[Any, Any]:
112         """
113         Args:
114             index (int): Index
115 
116         Returns:
117             tuple: (image, target) where target is index of the target class.
118         """
119         target: Optional[int]
120         if self.labels is not None:
121             img, target = self.data[index], int(self.labels[index])
122         else:
123             img, target = self.data[index], None
124 
125         # doing this so that it is consistent with all other datasets
126         # to return a PIL Image
127         img = Image.fromarray(np.transpose(img, (1, 2, 0)))
128 
129         if self.transform is not None:
130             img = self.transform(img)
131 
132         if self.target_transform is not None:
133             target = self.target_transform(target)
134 
135         return img, target
136 
137     def __len__(self) -> int:
138         return self.data.shape[0]
139 
140     def __loadfile(self, data_file: str, labels_file: Optional[str] = None) -> Tuple[np.ndarray, Optional[np.ndarray]]:
141         labels = None
142         if labels_file:
143             path_to_labels = os.path.join(
144                 self.root, self.base_folder, labels_file)
145             with open(path_to_labels, 'rb') as f:
146                 labels = np.fromfile(f, dtype=np.uint8) - 1  # 0-based
147 
148         path_to_data = os.path.join(self.root, self.base_folder, data_file)
149         with open(path_to_data, 'rb') as f:
150             # read whole file in uint8 chunks
151             everything = np.fromfile(f, dtype=np.uint8)
152             images = np.reshape(everything, (-1, 3, 96, 96))
153             images = np.transpose(images, (0, 1, 3, 2))
154 
155         return images, labels
156 
157     def _check_integrity(self) -> bool:
158         root = self.root
159         for fentry in (self.train_list + self.test_list):
160             filename, md5 = fentry[0], fentry[1]
161             fpath = os.path.join(root, self.base_folder, filename)
162             if not check_integrity(fpath, md5):
163                 return False
164         return True
165 
166     def download(self) -> None:
167         if self._check_integrity():
168             print('Files already downloaded and verified')
169             return
170         download_and_extract_archive(self.url, self.root, filename=self.filename, md5=self.tgz_md5)
171         self._check_integrity()
172 
173     def extra_repr(self) -> str:
174         return "Split: {split}".format(**self.__dict__)
175 
176     def __load_folds(self, folds: Optional[int]) -> None:
177         # loads one of the folds if specified
178         if folds is None:
179             return
180         path_to_folds = os.path.join(
181             self.root, self.base_folder, self.folds_list_file)
182         with open(path_to_folds, 'r') as f:
183             str_idx = f.read().splitlines()[folds]
184             list_idx = np.fromstring(str_idx, dtype=np.uint8, sep=' ')
185             self.data = self.data[list_idx, :, :, :]
186             if self.labels is not None:
187                 self.labels = self.labels[list_idx]
188
```
--- 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/stl10.py b/torchvision/datasets/stl10.py
--- a/torchvision/datasets/stl10.py
+++ b/torchvision/datasets/stl10.py
@@ -181,7 +181,7 @@
             self.root, self.base_folder, self.folds_list_file)
         with open(path_to_folds, 'r') as f:
             str_idx = f.read().splitlines()[folds]
-            list_idx = np.fromstring(str_idx, dtype=np.uint8, sep=' ')
+            list_idx = np.fromstring(str_idx, dtype=np.int64, sep=' ')
             self.data = self.data[list_idx, :, :, :]
             if self.labels is not None:
                 self.labels = self.labels[list_idx]

{"golden_diff": "diff --git a/torchvision/datasets/stl10.py b/torchvision/datasets/stl10.py\n--- a/torchvision/datasets/stl10.py\n+++ b/torchvision/datasets/stl10.py\n@@ -181,7 +181,7 @@\n             self.root, self.base_folder, self.folds_list_file)\n         with open(path_to_folds, 'r') as f:\n             str_idx = f.read().splitlines()[folds]\n-            list_idx = np.fromstring(str_idx, dtype=np.uint8, sep=' ')\n+            list_idx = np.fromstring(str_idx, dtype=np.int64, sep=' ')\n             self.data = self.data[list_idx, :, :, :]\n             if self.labels is not None:\n                 self.labels = self.labels[list_idx]\n", "issue": "torchvision.dataset.STL10.__load_folds() loads image indices using uint8.\n## \ud83d\udc1b Bug\r\n\r\n<!-- A clear and concise description of what the bug is. -->\r\nThere seems a bug to load STL-10 dataset using torchvision.dataset.STL10.\r\nI think the bug causes from \"uint8\" used on _load_folds() function. The maximum range of uint8 is 0 to 255.\r\nHowever, the range of STL-10 images for the training is 0 to 4999. So overflow happened when loading data.\r\nIt would be better to change \"uint8\" to \"int\" used on _load_folds() function.\r\n\r\n## To Reproduce\r\n\r\nSteps to reproduce the behavior:\r\n\r\n1. current __load_folds() in torchvision.datasets.STL10\r\n```\r\n    def __load_folds(self, folds: Optional[int]) -> None:\r\n        # loads one of the folds if specified\r\n        if folds is None:\r\n            return\r\n        path_to_folds = os.path.join(\r\n            self.root, self.base_folder, self.folds_list_file)\r\n        with open(path_to_folds, 'r') as f:\r\n            str_idx = f.read().splitlines()[folds]\r\n            list_idx = np.fromstring(str_idx, dtype=np.uint8, sep=' ')\r\n            self.data, self.labels = self.data[list_idx, :, :, :], self.labels[list_idx]\r\n```\r\n\r\n2. image indices[:20] of fold-5 in \"fold_indices.txt\"\r\n1632 1914 1739 4639 1009 4160 4035 2197 2513 4705 2793 4056 2413 4147 2213 4980 1321 3163 4027 874 ...\r\n\r\n3. load STL-10 fold-5 with current __load_folds()\r\n```\r\n    from torchvision.datasets import STL10\r\n    data_dir = 'path/to/stl10'\r\n    split = 'train'\r\n    folds = 4  # fold_index (= fold_number - 1)\r\n    dataset = STL10(data_dir, split=split, folds=folds, download=True)\r\n```\r\n\r\n4. loaded indices[:20]\r\n96 122 203 31 241 64 195 149 209 97 233 216 109 51 165 116 41 91 187 106 ...\r\n\r\n<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->\r\n\r\n## Expected behavior\r\n\r\n<!-- A clear and concise description of what you expected to happen. -->\r\n1. load STL-10 fold-5 without current __load_folds()\r\n```\r\n    from torchvision.datasets import STL10\r\n    data_dir = 'path/to/stl10'\r\n    split = 'train'\r\n    folds = 4  # fold_index (= fold_number - 1)\r\n    dataset = STL10(data_dir, split=split, folds=None, download=True)\r\n\r\n    ##############################\r\n    # from __load_folds()\r\n    path_to_folds = os.path.join(\r\n        dataset.root, dataset.base_folder, dataset.folds_list_file)\r\n    with open(path_to_folds, 'r') as f:\r\n        str_idx = f.read().splitlines()[folds]\r\n        # [MODIFIED] np.uint8 => np.int64\r\n        # list_idx = np.fromstring(str_idx, dtype=np.uint8, sep=' ')\r\n        list_idx = np.fromstring(str_idx, dtype=np.int64, sep=' ')\r\n        dataset.data, dataset.labels = dataset.data[list_idx, :, :, :], dataset.labels[list_idx]\r\n    ##############################\r\n```\r\n\r\n2. loaded indices[:20]\r\n1632 1914 1739 4639 1009 4160 4035 2197 2513 4705 2793 4056 2413 4147 2213 4980 1321 3163 4027 874 ...\r\n\r\n## Environment\r\n\r\nPlease copy and paste the output from our\r\n[environment collection script](https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py)\r\n(or fill out the checklist below manually).\r\n\r\nYou can get the script and run it with:\r\n```\r\nwget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py\r\n# For security purposes, please check the contents of collect_env.py before running it.\r\npython collect_env.py\r\n```\r\n\r\n - PyTorch / torchvision Version (e.g., 1.0 / 0.4.0): 1.7.1 / 0.8.2\r\n - OS (e.g., Linux): Ubuntu 18.04.5 LTS (x86_64)\r\n - How you installed PyTorch / torchvision (`conda`, `pip`, source): pip\r\n - Build command you used (if compiling from source): -\r\n - Python version: 3.7 (64-bit runtime)\r\n - CUDA/cuDNN version: 10.2/8.0.5\r\n - GPU models and configuration: V100\r\n - Any other relevant information:\r\n\r\n## Additional context\r\n\r\n<!-- Add any other context about the problem here. -->\r\n\n\ncc @pmeier\n", "before_files": [{"content": "from PIL import Image\nimport os\nimport os.path\nimport numpy as np\nfrom typing import Any, Callable, Optional, Tuple\n\nfrom .vision import VisionDataset\nfrom .utils import check_integrity, download_and_extract_archive, verify_str_arg\n\n\nclass STL10(VisionDataset):\n    \"\"\"`STL10 <https://cs.stanford.edu/~acoates/stl10/>`_ Dataset.\n\n    Args:\n        root (string): Root directory of dataset where directory\n            ``stl10_binary`` exists.\n        split (string): One of {'train', 'test', 'unlabeled', 'train+unlabeled'}.\n            Accordingly dataset is selected.\n        folds (int, optional): One of {0-9} or None.\n            For training, loads one of the 10 pre-defined folds of 1k samples for the\n            standard evaluation procedure. If no value is passed, loads the 5k samples.\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        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    base_folder = 'stl10_binary'\n    url = \"http://ai.stanford.edu/~acoates/stl10/stl10_binary.tar.gz\"\n    filename = \"stl10_binary.tar.gz\"\n    tgz_md5 = '91f7769df0f17e558f3565bffb0c7dfb'\n    class_names_file = 'class_names.txt'\n    folds_list_file = 'fold_indices.txt'\n    train_list = [\n        ['train_X.bin', '918c2871b30a85fa023e0c44e0bee87f'],\n        ['train_y.bin', '5a34089d4802c674881badbb80307741'],\n        ['unlabeled_X.bin', '5242ba1fed5e4be9e1e742405eb56ca4']\n    ]\n\n    test_list = [\n        ['test_X.bin', '7f263ba9f9e0b06b93213547f721ac82'],\n        ['test_y.bin', '36f9794fa4beb8a2c72628de14fa638e']\n    ]\n    splits = ('train', 'train+unlabeled', 'unlabeled', 'test')\n\n    def __init__(\n            self,\n            root: str,\n            split: str = \"train\",\n            folds: Optional[int] = None,\n            transform: Optional[Callable] = None,\n            target_transform: Optional[Callable] = None,\n            download: bool = False,\n    ) -> None:\n        super(STL10, self).__init__(root, transform=transform,\n                                    target_transform=target_transform)\n        self.split = verify_str_arg(split, \"split\", self.splits)\n        self.folds = self._verify_folds(folds)\n\n        if download:\n            self.download()\n        elif not self._check_integrity():\n            raise RuntimeError(\n                'Dataset not found or corrupted. '\n                'You can use download=True to download it')\n\n        # now load the picked numpy arrays\n        self.labels: Optional[np.ndarray]\n        if self.split == 'train':\n            self.data, self.labels = self.__loadfile(\n                self.train_list[0][0], self.train_list[1][0])\n            self.__load_folds(folds)\n\n        elif self.split == 'train+unlabeled':\n            self.data, self.labels = self.__loadfile(\n                self.train_list[0][0], self.train_list[1][0])\n            self.__load_folds(folds)\n            unlabeled_data, _ = self.__loadfile(self.train_list[2][0])\n            self.data = np.concatenate((self.data, unlabeled_data))\n            self.labels = np.concatenate(\n                (self.labels, np.asarray([-1] * unlabeled_data.shape[0])))\n\n        elif self.split == 'unlabeled':\n            self.data, _ = self.__loadfile(self.train_list[2][0])\n            self.labels = np.asarray([-1] * self.data.shape[0])\n        else:  # self.split == 'test':\n            self.data, self.labels = self.__loadfile(\n                self.test_list[0][0], self.test_list[1][0])\n\n        class_file = os.path.join(\n            self.root, self.base_folder, self.class_names_file)\n        if os.path.isfile(class_file):\n            with open(class_file) as f:\n                self.classes = f.read().splitlines()\n\n    def _verify_folds(self, folds: Optional[int]) -> Optional[int]:\n        if folds is None:\n            return folds\n        elif isinstance(folds, int):\n            if folds in range(10):\n                return folds\n            msg = (\"Value for argument folds should be in the range [0, 10), \"\n                   \"but got {}.\")\n            raise ValueError(msg.format(folds))\n        else:\n            msg = \"Expected type None or int for argument folds, but got type {}.\"\n            raise ValueError(msg.format(type(folds)))\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 index of the target class.\n        \"\"\"\n        target: Optional[int]\n        if self.labels is not None:\n            img, target = self.data[index], int(self.labels[index])\n        else:\n            img, target = self.data[index], None\n\n        # doing this so that it is consistent with all other datasets\n        # to return a PIL Image\n        img = Image.fromarray(np.transpose(img, (1, 2, 0)))\n\n        if self.transform is not None:\n            img = self.transform(img)\n\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 self.data.shape[0]\n\n    def __loadfile(self, data_file: str, labels_file: Optional[str] = None) -> Tuple[np.ndarray, Optional[np.ndarray]]:\n        labels = None\n        if labels_file:\n            path_to_labels = os.path.join(\n                self.root, self.base_folder, labels_file)\n            with open(path_to_labels, 'rb') as f:\n                labels = np.fromfile(f, dtype=np.uint8) - 1  # 0-based\n\n        path_to_data = os.path.join(self.root, self.base_folder, data_file)\n        with open(path_to_data, 'rb') as f:\n            # read whole file in uint8 chunks\n            everything = np.fromfile(f, dtype=np.uint8)\n            images = np.reshape(everything, (-1, 3, 96, 96))\n            images = np.transpose(images, (0, 1, 3, 2))\n\n        return images, labels\n\n    def _check_integrity(self) -> bool:\n        root = self.root\n        for fentry in (self.train_list + self.test_list):\n            filename, md5 = fentry[0], fentry[1]\n            fpath = os.path.join(root, self.base_folder, filename)\n            if not check_integrity(fpath, md5):\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        download_and_extract_archive(self.url, self.root, filename=self.filename, md5=self.tgz_md5)\n        self._check_integrity()\n\n    def extra_repr(self) -> str:\n        return \"Split: {split}\".format(**self.__dict__)\n\n    def __load_folds(self, folds: Optional[int]) -> None:\n        # loads one of the folds if specified\n        if folds is None:\n            return\n        path_to_folds = os.path.join(\n            self.root, self.base_folder, self.folds_list_file)\n        with open(path_to_folds, 'r') as f:\n            str_idx = f.read().splitlines()[folds]\n            list_idx = np.fromstring(str_idx, dtype=np.uint8, sep=' ')\n            self.data = self.data[list_idx, :, :, :]\n            if self.labels is not None:\n                self.labels = self.labels[list_idx]\n", "path": "torchvision/datasets/stl10.py"}], "after_files": [{"content": "from PIL import Image\nimport os\nimport os.path\nimport numpy as np\nfrom typing import Any, Callable, Optional, Tuple\n\nfrom .vision import VisionDataset\nfrom .utils import check_integrity, download_and_extract_archive, verify_str_arg\n\n\nclass STL10(VisionDataset):\n    \"\"\"`STL10 <https://cs.stanford.edu/~acoates/stl10/>`_ Dataset.\n\n    Args:\n        root (string): Root directory of dataset where directory\n            ``stl10_binary`` exists.\n        split (string): One of {'train', 'test', 'unlabeled', 'train+unlabeled'}.\n            Accordingly dataset is selected.\n        folds (int, optional): One of {0-9} or None.\n            For training, loads one of the 10 pre-defined folds of 1k samples for the\n            standard evaluation procedure. If no value is passed, loads the 5k samples.\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        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    base_folder = 'stl10_binary'\n    url = \"http://ai.stanford.edu/~acoates/stl10/stl10_binary.tar.gz\"\n    filename = \"stl10_binary.tar.gz\"\n    tgz_md5 = '91f7769df0f17e558f3565bffb0c7dfb'\n    class_names_file = 'class_names.txt'\n    folds_list_file = 'fold_indices.txt'\n    train_list = [\n        ['train_X.bin', '918c2871b30a85fa023e0c44e0bee87f'],\n        ['train_y.bin', '5a34089d4802c674881badbb80307741'],\n        ['unlabeled_X.bin', '5242ba1fed5e4be9e1e742405eb56ca4']\n    ]\n\n    test_list = [\n        ['test_X.bin', '7f263ba9f9e0b06b93213547f721ac82'],\n        ['test_y.bin', '36f9794fa4beb8a2c72628de14fa638e']\n    ]\n    splits = ('train', 'train+unlabeled', 'unlabeled', 'test')\n\n    def __init__(\n            self,\n            root: str,\n            split: str = \"train\",\n            folds: Optional[int] = None,\n            transform: Optional[Callable] = None,\n            target_transform: Optional[Callable] = None,\n            download: bool = False,\n    ) -> None:\n        super(STL10, self).__init__(root, transform=transform,\n                                    target_transform=target_transform)\n        self.split = verify_str_arg(split, \"split\", self.splits)\n        self.folds = self._verify_folds(folds)\n\n        if download:\n            self.download()\n        elif not self._check_integrity():\n            raise RuntimeError(\n                'Dataset not found or corrupted. '\n                'You can use download=True to download it')\n\n        # now load the picked numpy arrays\n        self.labels: Optional[np.ndarray]\n        if self.split == 'train':\n            self.data, self.labels = self.__loadfile(\n                self.train_list[0][0], self.train_list[1][0])\n            self.__load_folds(folds)\n\n        elif self.split == 'train+unlabeled':\n            self.data, self.labels = self.__loadfile(\n                self.train_list[0][0], self.train_list[1][0])\n            self.__load_folds(folds)\n            unlabeled_data, _ = self.__loadfile(self.train_list[2][0])\n            self.data = np.concatenate((self.data, unlabeled_data))\n            self.labels = np.concatenate(\n                (self.labels, np.asarray([-1] * unlabeled_data.shape[0])))\n\n        elif self.split == 'unlabeled':\n            self.data, _ = self.__loadfile(self.train_list[2][0])\n            self.labels = np.asarray([-1] * self.data.shape[0])\n        else:  # self.split == 'test':\n            self.data, self.labels = self.__loadfile(\n                self.test_list[0][0], self.test_list[1][0])\n\n        class_file = os.path.join(\n            self.root, self.base_folder, self.class_names_file)\n        if os.path.isfile(class_file):\n            with open(class_file) as f:\n                self.classes = f.read().splitlines()\n\n    def _verify_folds(self, folds: Optional[int]) -> Optional[int]:\n        if folds is None:\n            return folds\n        elif isinstance(folds, int):\n            if folds in range(10):\n                return folds\n            msg = (\"Value for argument folds should be in the range [0, 10), \"\n                   \"but got {}.\")\n            raise ValueError(msg.format(folds))\n        else:\n            msg = \"Expected type None or int for argument folds, but got type {}.\"\n            raise ValueError(msg.format(type(folds)))\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 index of the target class.\n        \"\"\"\n        target: Optional[int]\n        if self.labels is not None:\n            img, target = self.data[index], int(self.labels[index])\n        else:\n            img, target = self.data[index], None\n\n        # doing this so that it is consistent with all other datasets\n        # to return a PIL Image\n        img = Image.fromarray(np.transpose(img, (1, 2, 0)))\n\n        if self.transform is not None:\n            img = self.transform(img)\n\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 self.data.shape[0]\n\n    def __loadfile(self, data_file: str, labels_file: Optional[str] = None) -> Tuple[np.ndarray, Optional[np.ndarray]]:\n        labels = None\n        if labels_file:\n            path_to_labels = os.path.join(\n                self.root, self.base_folder, labels_file)\n            with open(path_to_labels, 'rb') as f:\n                labels = np.fromfile(f, dtype=np.uint8) - 1  # 0-based\n\n        path_to_data = os.path.join(self.root, self.base_folder, data_file)\n        with open(path_to_data, 'rb') as f:\n            # read whole file in uint8 chunks\n            everything = np.fromfile(f, dtype=np.uint8)\n            images = np.reshape(everything, (-1, 3, 96, 96))\n            images = np.transpose(images, (0, 1, 3, 2))\n\n        return images, labels\n\n    def _check_integrity(self) -> bool:\n        root = self.root\n        for fentry in (self.train_list + self.test_list):\n            filename, md5 = fentry[0], fentry[1]\n            fpath = os.path.join(root, self.base_folder, filename)\n            if not check_integrity(fpath, md5):\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        download_and_extract_archive(self.url, self.root, filename=self.filename, md5=self.tgz_md5)\n        self._check_integrity()\n\n    def extra_repr(self) -> str:\n        return \"Split: {split}\".format(**self.__dict__)\n\n    def __load_folds(self, folds: Optional[int]) -> None:\n        # loads one of the folds if specified\n        if folds is None:\n            return\n        path_to_folds = os.path.join(\n            self.root, self.base_folder, self.folds_list_file)\n        with open(path_to_folds, 'r') as f:\n            str_idx = f.read().splitlines()[folds]\n            list_idx = np.fromstring(str_idx, dtype=np.int64, sep=' ')\n            self.data = self.data[list_idx, :, :, :]\n            if self.labels is not None:\n                self.labels = self.labels[list_idx]\n", "path": "torchvision/datasets/stl10.py"}]}