def model(features, labels, mode):
W = tf.get_variable("W", [1], dtype = tf.float64)
b = tf.get_variable("b", [1], dtype = tf.float64)
y = W * features['x'] + b
#loss sub-graph
loss = tf.reduce_sum(tf.square(y - labels))
#training sub-graph
global_step = tf.train.get_global_step()
optimizer = tf.train.GradientDescentOptimizer(0.01)
train = tf.group(optimizer.minimize(loss), tf.assign_add(global_step, 1))
#modelFnOps connects subgraphs we built
return tf.contrib.learn.ModelFnOps(mode = mode, predictions = y, loss = loss, train_op = train)
LinearRegressionCustom.py 文件源码
python
阅读 28
收藏 0
点赞 0
评论 0
评论列表
文章目录