0

在 TensorFlow 示例中,我用自己的数据代替了 MNIST 数据,其中我有 2d 数组作为模型输入 (x),即:

[[379 1] [412 2] ... [205 1] [504 8]]

和一维输出(y),即:

[20, 24, ... 19, 27]

以下代码[0.5, 0.5]为所有训练步骤生成 2d 数组,为测试数据生成 1 个数组(当随机生成测试数据时)。此外,所有权重和偏差都为零。

for i in range(10):
  print 'iterator:'
  print i
  batch_ys = np.reshape(training_outputs, (300, 1))

  ## batch_xs.shape = (300, 2)
  batch_xs = training_inputs

  sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})

  print 'softmax value'
  ## !! these are a all [ 0.5  0.5]  !!
  print(sess.run(y, feed_dict={x: batch_xs}))

correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1))

accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

test_outputs = np.random.rand(300, 1)

## the following prints 1
print(sess.run(accuracy, feed_dict={x: test_inputs, y_: test_outputs}))

我从根本上错过了什么吗?

4

0 回答 0