在张量流中实现神经网络时出错[关闭]

问题描述 投票:-4回答:2
我正在尝试实现此代码以获取示例神经网络,但在此步骤中遇到错误,有人可以帮助我吗?

import tensorflow as tf const = tf.constant(2.0, name="const") b = tf.Variable(2.0, name='b') c = tf.Variable(1.0, name='c') # now create some operations d = tf.add(b, c, name='d') e = tf.add(c, const, name='e') a = tf.multiply(d, e, name='a') # setup the variable initialisation init_op = tf.global_variables_initializar() with tf.Session() as sess: # initialise the variables sess.run(init_op) # compute the output of the graph print("Variable a is {}".format(a_out)) b = tf.placeholder(tf.float32, [None, 1], name='b') a_out = sess.run(a, feed_dict={b: np.arange(0, 10)[:, np.newaxis]}) from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) # Python optimisation variables learning_rate = 0.5 epochs = 10 batch_size = 100

python tensorflow neural-network
2个回答
0
投票
您需要更正initializar,因为它的书写方式不正确:

init_op = tf.global_variables_initializer()

您正在告诉您打印未声明的a_out,我想应该是这样

with tf.Session() as sess: sess.run(init_op) a_out = sess.run(a) print("Variable a is {}".format(a_out))


0
投票
首先,您的init_op = tf.global_variables_initializar()中存在拼写错误,应该为init_op = tf.global_variables_initializer()。其次,您在分配a_out之前使用它。
© www.soinside.com 2019 - 2024. All rights reserved.