我对深度学习很陌生,只是安装了tensorflow,但是我遵循的教程使用TensorFlow 1,这在我的系统上引发错误,有人可以将这段代码从TensorFlow 1转换为TensorFlow 2
with tf.Session() as sess:
sess.run(tf.initialize_all_variables())
for epoch in range(hm_epochs) :
epoch_loss = 0
for _ in range(int(mnist.train.num_examples/batch_size)):
epoch_x, epoch_y = mnist.train.next_batch(batch_size)
_, c = sess.run([optimizer, cost], feed_dict = {x: epoch_x, y: epoch_y})
epoch_loss += c
print('Epoch ', epoch, ' completed out of ', hm_epochs, ' loss: ',epoch_loss)
correct = tf.equal(tf.argmax(prediction,1), tf.argmax(y,1))
accuracy = tf.reduce_mean(tf.cast(correct,'float'))
print('Accuracy: ',accuracy.eval({x:mnist.test.images, y:mnist.test.lables}))
tensorflow 2.0
中的MNIST示例:https://www.tensorflow.org/tutorials/quickstart/beginner