当我尝试运行训练步骤时会生成此错误。数据集是来自 Kaggle 的 MNIST 数据集。我正在使用神经网络来预测手写数字:
输入数据:[33600, 784]
重塑为[784, 33600]
神经网络架构:
第 1 层有 W1 1000 x 784 relu
第 2 层有 W2 1000 x 1000 relu
第 3 层有 W3 500 x 1000 relu
第 4 层有 W4 200 x 500 relu
第 5 层有 W5 10 x 200 和 softmax
没有使用偏差
代码:
print(X_train[:, 0].reshape(-1, 1).shape," ",y_train[:,0].reshape(-1,1).shape)`
输出:(784, 1)
(10, 1)
代码:
X, Y = tf.placeholder(tf.float32,[784, None]), tf.placeholder(tf.float32,[10, None])
logits = forward_propagation(X, parameters)
cost = compute_cost(logits, Y)
optimizer = tf.train.AdamOptimizer(learning_rate=1e-3).minimize(cost)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
_,c = sess.run([optimizer,cost], feed_dict= {X:X_train[:,0].reshape(-1,1),
Y:y_train[:, 0].reshape(-1,1)})
print(c)
输出:
ValueError Traceback (most recent call
last)
<ipython-input-41-f78f499b0606> in <module>()
8 with tf.Session() as sess:
9 sess.run(tf.global_variables_initializer())
---> 10 _,c = sess.run([optimizer,cost], feed_dict=
{X:np.asarray(X_train), Y:np.asarray(y_train)})
11 print(c)
.......
.......
ValueError: setting an array element with a sequence.
如果可以,请更正代码。