TF1代码不适用于TF2,有人可以转换此TF1代码

问题描述 投票:0回答:1

我对深度学习很陌生,只是安装了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 deep-learning tensorflow2.0 mnist
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.