【问题标题】:Add data to MNIST dataset将数据添加到 MNIST 数据集
【发布时间】:2017-07-21 06:46:37
【问题描述】:

我正在做一个机器学习项目来识别手写数字。实际上,我只是想向 MNIST 添加更多数据集,但我无法这样做。

我做了以下事情:

n_samples = len(mnist.data)
x = mnist.data.reshape((n_samples, -1))# array of feature of 64 pixel
y = mnist.target                         # Class label from 0-9 as there are digits

img_temp_train=cv2.imread('C:/Users/amuly/Desktop/Soap/crop/2.jpg',0)

X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.2)

#Now I want to add the img_temp_train to my dataset for training.

X_train=np.append(X_train,img_temp_train.reshape(-1))
y_train=np.append(y_train,[4.0])

训练后的长度为:

  • 43904784 (X_train)
  • 56001(y_train)

但两者都应该是 56001。

【问题讨论】:

    标签: python numpy


    【解决方案1】:

    试试这个:

    X_train = np.append(X_train, [img_temp_train], axis=0)
    

    您不应该在不考虑您首先在做什么的情况下随意改造事物!

    此外,使用连接通常是一个更好的主意:

    X_train = np.concatenate((X_train, [img_temp_train]), axis=0)
    

    【讨论】:

    • 不起作用,因为 X_train.shape 是 (56000,784) 而 img_temp_train.shape 是 (784,)
    • 已更新。 (忘记在第一个示例中包含axis=0。)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-05
    • 2021-03-04
    • 2022-11-12
    • 1970-01-01
    • 2020-06-13
    • 1970-01-01
    • 2020-03-13
    相关资源
    最近更新 更多