Repository: pytorch/vision

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


Discussion:

Resolving patch:
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 @@ def __load_folds(self, folds: Optional[int]) -> None:
             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]


Test patch: