prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  STL-10 Testing Protocol
  Class STL10 does not support recommended testing protocol. 
  See STL-10 official page: https://cs.stanford.edu/~acoates/stl10/
  
  --- 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 __future__ import print_function
  2 from PIL import Image
  3 import os
  4 import os.path
  5 import numpy as np
  6 from .cifar import CIFAR10
  7 
  8 
  9 class STL10(CIFAR10):
  10     """`STL10 <https://cs.stanford.edu/~acoates/stl10/>`_ Dataset.
  11 
  12     Args:
  13         root (string): Root directory of dataset where directory
  14             ``stl10_binary`` exists.
  15         split (string): One of {'train', 'test', 'unlabeled', 'train+unlabeled'}.
  16             Accordingly dataset is selected.
  17         transform (callable, optional): A function/transform that  takes in an PIL image
  18             and returns a transformed version. E.g, ``transforms.RandomCrop``
  19         target_transform (callable, optional): A function/transform that takes in the
  20             target and transforms it.
  21         download (bool, optional): If true, downloads the dataset from the internet and
  22             puts it in root directory. If dataset is already downloaded, it is not
  23             downloaded again.
  24 
  25     """
  26     base_folder = 'stl10_binary'
  27     url = "http://ai.stanford.edu/~acoates/stl10/stl10_binary.tar.gz"
  28     filename = "stl10_binary.tar.gz"
  29     tgz_md5 = '91f7769df0f17e558f3565bffb0c7dfb'
  30     class_names_file = 'class_names.txt'
  31     train_list = [
  32         ['train_X.bin', '918c2871b30a85fa023e0c44e0bee87f'],
  33         ['train_y.bin', '5a34089d4802c674881badbb80307741'],
  34         ['unlabeled_X.bin', '5242ba1fed5e4be9e1e742405eb56ca4']
  35     ]
  36 
  37     test_list = [
  38         ['test_X.bin', '7f263ba9f9e0b06b93213547f721ac82'],
  39         ['test_y.bin', '36f9794fa4beb8a2c72628de14fa638e']
  40     ]
  41     splits = ('train', 'train+unlabeled', 'unlabeled', 'test')
  42 
  43     def __init__(self, root, split='train',
  44                  transform=None, target_transform=None, download=False):
  45         if split not in self.splits:
  46             raise ValueError('Split "{}" not found. Valid splits are: {}'.format(
  47                 split, ', '.join(self.splits),
  48             ))
  49         self.root = os.path.expanduser(root)
  50         self.transform = transform
  51         self.target_transform = target_transform
  52         self.split = split  # train/test/unlabeled set
  53 
  54         if download:
  55             self.download()
  56 
  57         if not self._check_integrity():
  58             raise RuntimeError(
  59                 'Dataset not found or corrupted. '
  60                 'You can use download=True to download it')
  61 
  62         # now load the picked numpy arrays
  63         if self.split == 'train':
  64             self.data, self.labels = self.__loadfile(
  65                 self.train_list[0][0], self.train_list[1][0])
  66         elif self.split == 'train+unlabeled':
  67             self.data, self.labels = self.__loadfile(
  68                 self.train_list[0][0], self.train_list[1][0])
  69             unlabeled_data, _ = self.__loadfile(self.train_list[2][0])
  70             self.data = np.concatenate((self.data, unlabeled_data))
  71             self.labels = np.concatenate(
  72                 (self.labels, np.asarray([-1] * unlabeled_data.shape[0])))
  73 
  74         elif self.split == 'unlabeled':
  75             self.data, _ = self.__loadfile(self.train_list[2][0])
  76             self.labels = np.asarray([-1] * self.data.shape[0])
  77         else:  # self.split == 'test':
  78             self.data, self.labels = self.__loadfile(
  79                 self.test_list[0][0], self.test_list[1][0])
  80 
  81         class_file = os.path.join(
  82             self.root, self.base_folder, self.class_names_file)
  83         if os.path.isfile(class_file):
  84             with open(class_file) as f:
  85                 self.classes = f.read().splitlines()
  86 
  87     def __getitem__(self, index):
  88         """
  89         Args:
  90             index (int): Index
  91 
  92         Returns:
  93             tuple: (image, target) where target is index of the target class.
  94         """
  95         if self.labels is not None:
  96             img, target = self.data[index], int(self.labels[index])
  97         else:
  98             img, target = self.data[index], None
  99 
  100         # doing this so that it is consistent with all other datasets
  101         # to return a PIL Image
  102         img = Image.fromarray(np.transpose(img, (1, 2, 0)))
  103 
  104         if self.transform is not None:
  105             img = self.transform(img)
  106 
  107         if self.target_transform is not None:
  108             target = self.target_transform(target)
  109 
  110         return img, target
  111 
  112     def __len__(self):
  113         return self.data.shape[0]
  114 
  115     def __loadfile(self, data_file, labels_file=None):
  116         labels = None
  117         if labels_file:
  118             path_to_labels = os.path.join(
  119                 self.root, self.base_folder, labels_file)
  120             with open(path_to_labels, 'rb') as f:
  121                 labels = np.fromfile(f, dtype=np.uint8) - 1  # 0-based
  122 
  123         path_to_data = os.path.join(self.root, self.base_folder, data_file)
  124         with open(path_to_data, 'rb') as f:
  125             # read whole file in uint8 chunks
  126             everything = np.fromfile(f, dtype=np.uint8)
  127             images = np.reshape(everything, (-1, 3, 96, 96))
  128             images = np.transpose(images, (0, 1, 3, 2))
  129 
  130         return images, labels
  131 
  132     def extra_repr(self):
  133         return "Split: {split}".format(**self.__dict__)
  134
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/torchvision/datasets/stl10.py b/torchvision/datasets/stl10.py
  --- a/torchvision/datasets/stl10.py
  +++ b/torchvision/datasets/stl10.py
  @@ -14,6 +14,9 @@
               ``stl10_binary`` exists.
           split (string): One of {'train', 'test', 'unlabeled', 'train+unlabeled'}.
               Accordingly dataset is selected.
  +        folds (int, optional): One of {0-9} or None.
  +            For training, loads one of the 10 pre-defined folds of 1k samples for the
  +             standard evaluation procedure. If no value is passed, loads the 5k samples.
           transform (callable, optional): A function/transform that  takes in an PIL image
               and returns a transformed version. E.g, ``transforms.RandomCrop``
           target_transform (callable, optional): A function/transform that takes in the
  @@ -28,6 +31,7 @@
       filename = "stl10_binary.tar.gz"
       tgz_md5 = '91f7769df0f17e558f3565bffb0c7dfb'
       class_names_file = 'class_names.txt'
  +    folds_list_file = 'fold_indices.txt'
       train_list = [
           ['train_X.bin', '918c2871b30a85fa023e0c44e0bee87f'],
           ['train_y.bin', '5a34089d4802c674881badbb80307741'],
  @@ -40,7 +44,7 @@
       ]
       splits = ('train', 'train+unlabeled', 'unlabeled', 'test')
   
  -    def __init__(self, root, split='train',
  +    def __init__(self, root, split='train', folds=None,
                    transform=None, target_transform=None, download=False):
           if split not in self.splits:
               raise ValueError('Split "{}" not found. Valid splits are: {}'.format(
  @@ -50,6 +54,7 @@
           self.transform = transform
           self.target_transform = target_transform
           self.split = split  # train/test/unlabeled set
  +        self.folds = folds  # one of the 10 pre-defined folds or the full dataset
   
           if download:
               self.download()
  @@ -63,9 +68,12 @@
           if self.split == 'train':
               self.data, self.labels = self.__loadfile(
                   self.train_list[0][0], self.train_list[1][0])
  +            self.__load_folds(folds)
  +
           elif self.split == 'train+unlabeled':
               self.data, self.labels = self.__loadfile(
                   self.train_list[0][0], self.train_list[1][0])
  +            self.__load_folds(folds)
               unlabeled_data, _ = self.__loadfile(self.train_list[2][0])
               self.data = np.concatenate((self.data, unlabeled_data))
               self.labels = np.concatenate(
  @@ -131,3 +139,16 @@
   
       def extra_repr(self):
           return "Split: {split}".format(**self.__dict__)
  +
  +    def __load_folds(self, folds):
  +        # loads one of the folds if specified
  +        if isinstance(folds, int):
  +            if folds >= 0 and folds < 10:
  +                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]
  +            else:
  +                raise ValueError('Folds "{}" not found. Valid splits are: 0-9.'.format(folds))
  
verification_info: {"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@@ -14,6 +14,9 @@\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@@ -28,6 +31,7 @@\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@@ -40,7 +44,7 @@\n     ]\n     splits = ('train', 'train+unlabeled', 'unlabeled', 'test')\n \n-    def __init__(self, root, split='train',\n+    def __init__(self, root, split='train', folds=None,\n                  transform=None, target_transform=None, download=False):\n         if split not in self.splits:\n             raise ValueError('Split \"{}\" not found. Valid splits are: {}'.format(\n@@ -50,6 +54,7 @@\n         self.transform = transform\n         self.target_transform = target_transform\n         self.split = split  # train/test/unlabeled set\n+        self.folds = folds  # one of the 10 pre-defined folds or the full dataset\n \n         if download:\n             self.download()\n@@ -63,9 +68,12 @@\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@@ -131,3 +139,16 @@\n \n     def extra_repr(self):\n         return \"Split: {split}\".format(**self.__dict__)\n+\n+    def __load_folds(self, folds):\n+        # loads one of the folds if specified\n+        if isinstance(folds, int):\n+            if folds >= 0 and folds < 10:\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.labels = self.data[list_idx, :, :, :], self.labels[list_idx]\n+            else:\n+                raise ValueError('Folds \"{}\" not found. Valid splits are: 0-9.'.format(folds))\n", "issue": "STL-10 Testing Protocol\nClass STL10 does not support recommended testing protocol. \r\nSee STL-10 official page: https://cs.stanford.edu/~acoates/stl10/\n", "before_files": [{"content": "from __future__ import print_function\nfrom PIL import Image\nimport os\nimport os.path\nimport numpy as np\nfrom .cifar import CIFAR10\n\n\nclass STL10(CIFAR10):\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        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    \"\"\"\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    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__(self, root, split='train',\n                 transform=None, target_transform=None, download=False):\n        if split not in self.splits:\n            raise ValueError('Split \"{}\" not found. Valid splits are: {}'.format(\n                split, ', '.join(self.splits),\n            ))\n        self.root = os.path.expanduser(root)\n        self.transform = transform\n        self.target_transform = target_transform\n        self.split = split  # train/test/unlabeled set\n\n        if download:\n            self.download()\n\n        if 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        if self.split == 'train':\n            self.data, self.labels = self.__loadfile(\n                self.train_list[0][0], self.train_list[1][0])\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            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 __getitem__(self, index):\n        \"\"\"\n        Args:\n            index (int): Index\n\n        Returns:\n            tuple: (image, target) where target is index of the target class.\n        \"\"\"\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):\n        return self.data.shape[0]\n\n    def __loadfile(self, data_file, labels_file=None):\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 extra_repr(self):\n        return \"Split: {split}\".format(**self.__dict__)\n", "path": "torchvision/datasets/stl10.py"}], "after_files": [{"content": "from __future__ import print_function\nfrom PIL import Image\nimport os\nimport os.path\nimport numpy as np\nfrom .cifar import CIFAR10\n\n\nclass STL10(CIFAR10):\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    \"\"\"\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__(self, root, split='train', folds=None,\n                 transform=None, target_transform=None, download=False):\n        if split not in self.splits:\n            raise ValueError('Split \"{}\" not found. Valid splits are: {}'.format(\n                split, ', '.join(self.splits),\n            ))\n        self.root = os.path.expanduser(root)\n        self.transform = transform\n        self.target_transform = target_transform\n        self.split = split  # train/test/unlabeled set\n        self.folds = folds  # one of the 10 pre-defined folds or the full dataset\n\n        if download:\n            self.download()\n\n        if 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        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 __getitem__(self, index):\n        \"\"\"\n        Args:\n            index (int): Index\n\n        Returns:\n            tuple: (image, target) where target is index of the target class.\n        \"\"\"\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):\n        return self.data.shape[0]\n\n    def __loadfile(self, data_file, labels_file=None):\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 extra_repr(self):\n        return \"Split: {split}\".format(**self.__dict__)\n\n    def __load_folds(self, folds):\n        # loads one of the folds if specified\n        if isinstance(folds, int):\n            if folds >= 0 and folds < 10:\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.labels = self.data[list_idx, :, :, :], self.labels[list_idx]\n            else:\n                raise ValueError('Folds \"{}\" not found. Valid splits are: 0-9.'.format(folds))\n", "path": "torchvision/datasets/stl10.py"}]}