【问题标题】:I need help to use only 8 out of 10 classes from cifar 10. Normally it loads all 10 classes我需要帮助才能使用 cifar 10 中的 10 个类中的 8 个。通常它会加载所有 10 个类
【发布时间】:2021-09-27 21:28:04
【问题描述】:

我只想执行 8 个类别分类,因此需要从 10 个类别中过滤掉任何 8 个类别。请帮忙。谢谢!

加载 cifar 10 的代码如下

#Keras library for CIFAR-10 dataset
from keras.datasets import cifar10


#Downloading the CIFAR dataset
(x_train,y_train),(x_test,y_test)=cifar10.load_data()

# I tried the following but its changing the array shape please help
#Train
for i in range(8):
  index = np.where(y_train == i)
  X_train = x_train[index]
  Y_train = y_train[index]

#Test
for i in range(8):
  index = np.where(y_test == i)
  X_test = x_test[index]
  Y_test = y_test[index]

【问题讨论】:

标签: python tensorflow keras computer-vision


【解决方案1】:
(X_train, y_train), (X_test, y_test) = tf.keras.datasets.cifar10.load_data()

这包含 10 个类的所有样本

您可以根据类选择索引

index = np.where(y_train == 0)
X_train = X_train[index]
y_train = y_train[index]

这给出了所有第 0 个索引样本

您可以使用此技术加载您想要的任何特定类。

【讨论】:

  • #Train for i in range(8): index = np.where(y_train == i) X_train = x_train[index] Y_train = y_train[index] #Test for i in range(8) : index = np.where(y_test == i) X_test = x_test[index] Y_test = y_test[index]
猜你喜欢
  • 2013-01-29
  • 2021-12-30
  • 2013-04-06
  • 2014-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多