完全正确。
当你训练
optimizer
使用梯度下降或任何其他优化算法,如
AdamOptimizer()
,优化器将
loss
函数,它可以是Softmax交叉熵
tf.nn.softmax_cross_entropy_with_logits
根据多类分类,或平方误差损失
tf.losses.mean_squared_error
在回归或你自己的习惯损失方面。这个
损失
使用模型假设来评估或计算函数。
因此tensorflow使用这种级联方法通过调用
tf.Session().run()
上
优化器
是的。在多分类设置中,请参见以下粗略示例:
batch_size = 128
# build the linear model
hypothesis = tf.add(tf.matmul(input_X, weight), bias)
# softmax cross entropy loss or cost function for logistic regression
loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=targets,
logits=hypothesis))
# optimizer to minimize loss
optimizer = tf.train.GradientDescentOptimizer(learning_rate = 0.001).minimize(loss)
# execute in Session
with tf.Session() as sess:
# initialize all variables
tf.global_variables_initializer().run()
tf.local_variables_initializer().run()
# Train the model
for steps in range(1000):
mini_batch = zip(range(0, X_train.shape[0], batch_size),
range(batch_size, X_train.shape[0]+1, batch_size))
# train using mini-batches
for (start, end) in mini_batch:
sess.run(optimizer, feed_dict = {input_X: X_features[start:end],
input_y: y_targets[start:end]})