【问题标题】:Trying to access subset of mnist dataset in pytorch [equal samples from each class]尝试访问 pytorch 中 mnist 数据集的子集 [每个类的样本相等]
【发布时间】:2020-12-30 05:07:09
【问题描述】:

尝试访问 pytorch 中的 mnist 数据集子集 [每个类的样本相等] 但出现此错误

prng = RandomState(42)
random_permute = prng.permutation(np.arange(0, 6000))[0:3000]
indx = np.concatenate([np.where(np.array(mnist_data.targets) == classe)[0][random_permute] for classe in range(0,10)])
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-178-038015f76b77> in <module>
----> 1 indx = np.concatenate([np.where(np.array(mnist_data.targets) == classe)[0][random_permute] for classe in range(0,10)])

<ipython-input-178-038015f76b77> in <listcomp>(.0)
----> 1 indx = np.concatenate([np.where(np.array(mnist_data.targets) == classe)[0][random_permute] for classe in range(0,10)])

IndexError: index 5992 is out of bounds for axis 0 with size 5923

【问题讨论】:

    标签: python arrays numpy pytorch mnist


    【解决方案1】:

    MNIST 数据集的目标分布不均匀。您收到此错误是因为 MNIST 中的 0 类包含 5923 个样本。

    nums = [0]*10
    for i in range(60000):
      nums[(int(mnist_data.targets[i]))] += 1
    print(nums)
    

    这将打印[5923, 6742, 5958, 6131, 5842, 5421, 5918, 6265, 5851, 5949]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-15
      • 2020-07-17
      • 2019-06-12
      相关资源
      最近更新 更多