LinearRegressionCustom.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:Tensorflow_Practice 作者: Ram81 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号