【问题标题】:How can I change the CIFAR-10 dataset labels?如何更改 CIFAR-10 数据集标签?
【发布时间】:2021-08-29 23:36:46
【问题描述】:
我想更改数据集 CIFAR-10 的一些标签。
这意味着,我想用这个数据集中的一些错误标签来训练我的网络。
更改数据集标签后,我需要一些格式,例如:
dataset_cifar_with_some_wrongs_labels = (amount of pictures, label, image)
image.shape=(32,32,3)
我知道我可以下载它:
https://www.cs.toronto.edu/~kriz/cifar.html
有人知道我该怎么做吗?
【问题讨论】:
标签:
python
tensorflow
keras
dataset
【解决方案1】:
您可以使用 keras 内部 cifar10 数据集。我已经通过排列实现了噪声机制,但可能还有很多其他选择。
import keras
import numpy as np
(x_train, y_train), (x_test, y_test) = keras.datasets.cifar10.load_data()
n = 1000
y_train_ = y_train.copy()
idx_to_shuffle = np.random.choice(y_train.shape[0], n)
y_train[idx_to_shuffle] = np.random.permutation(y_train[idx_to_shuffle])