# Load the raw CIFAR-10 data
时间: 2024-05-06 10:17:54 浏览: 74
Here's some code to load the raw CIFAR-10 data in Python:
```python
import pickle
def load_cifar10_data(filename):
with open(filename, 'rb') as f:
data = pickle.load(f, encoding='bytes')
# extract the data from the dictionary
images = data[b'data']
labels = data[b'labels']
return images, labels
```
You can then use this function to load the training and test data like this:
```python
train_images, train_labels = load_cifar10_data('cifar-10-batches-py/data_batch_1')
test_images, test_labels = load_cifar10_data('cifar-10-batches-py/test_batch')
```
Note that the CIFAR-10 data is stored in binary format, so we need to use the `pickle` module to load it. Also, the images are stored as a 1D array of length 3072 (32x32x3), so we need to reshape them to a 3D array of shape (32, 32, 3) before we can visualize them.
阅读全文