TensorFlow图API分离了图的构造和执行。因此,我无法理解在哪条线神经网络中执行。
"""
- model_fn: function that performs the forward pass of the model
- init_fn: function that initializes the parameters of the model.
- learning_rate: the learning rate to use for SGD.
"""
tf.reset_default_graph()
is_training = tf.placeholder(tf.bool, name='is_training')
with tf.device(device):
x = tf.placeholder(tf.float32, [None, 32, 32, 3])
y = tf.placeholder(tf.int32, [None])
params = init_fn() # Initialize the model parameters
scores = model_fn(x, params) # Forward pass of the model
loss = training_step(scores, y, params, learning_rate) # SGD
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for t, (x_np, y_np) in enumerate(train_dset):
feed_dict = {x: x_np, y: y_np}
loss_np = sess.run(loss, feed_dict=feed_dict)
答案 0 :(得分:1)
如Tensorflow文档中所述:(https://www.tensorflow.org/api_docs/python/tf/Session#run)
通过运行以下方法,该方法运行TensorFlow计算的一个“步骤” 执行每个操作并评估每个操作所需的图形片段 张量
在您的示例中,sess.run(tf.global_variables_initializer())
运行创建所有权重和张量的初始化操作,loss_np = sess.run(loss, feed_dict=feed_dict)
执行直至loss
的所有操作。
我希望这能回答您的问题