【发布时间】:2020-05-26 04:52:09
【问题描述】:
我正在尝试使用已在 MNIST 数据库上训练的反向传播将自己的图像从头导入到神经网络中。
代码:
#X - input image
#W1/W2 - Weights
#b1/b2 - biases
def predict(X, W1, W2, b1, b2):
Z1 = np.dot(W1, X.T) + b1
A1 = tanh(Z1)
Z2 = np.dot(W2, A1) + b2
A2 = softmax(Z2)
prediction = np.argmax(A2, axis = 0)
return prediction
chosen_img = x_test[3]
output = predict(chosen_img, W1, W2, b1, b2)
myImg = chosen_img.reshape((28,28))
print(output)
哪里可能出错
当我尝试从 MNIST 数据库本身输入图像时,它仍然无法正常工作。例如,它可以将其输出为output:[7 2 2 7 7 2 2 7 1 2 7 7 2 2 2 7 7 7 7 7 7 7 2 2 7 2 2 2]。
请注意,我使用的代码与我的完整 NN 中的 相同 代码相同,因此前馈是相同的,猜测是相同的,权重和偏差是相同的 - 它确实适用于那个完整版,所以我真的不明白,为什么它现在不能工作。
我错过了什么吗? 感谢您的帮助!
【问题讨论】:
标签: python neural-network mnist