Skip to main content
 首页 » 编程设计

python之tensorflow 中 adam 优化器返回的第一个值是什么

2024年09月07日35pengyingh

我正在使用 tensorflow 创建一个两层的 DNN。我使用 AdamOptimizer 作为我的优化器。下面是我的代码

pred_raw = create_feedforward_nn_model(x, weights, biases) 
pred = tf.round(tf.nn.sigmoid(pred_raw)) 
cost = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(labels=pred, logits=y)) 
train_op = tf.train.AdamOptimizer(learning_rate).minimize(cost) 

当我在 train_op 上执行 seession.run 时,它返回两个值,我知道第二个值是损失,但这里的第一个值是多少。我看过很多教程,但是,在大多数教程中,他们通过使用 _ 来忽略第一个值,如下所示

_,loss = sess.run([train_op, cost],={x: batch_features, y: batch_labels}) 

请您参考如下方法:

在mnist/mechanics在检查状态下,您可以找到以下行:

Since train_op is an Operation with no output value, the corresponding element in the returned tuple is None and, thus, discarded. However, the value of the loss tensor may become NaN if the model diverges during training, so we capture this value for logging.