解决tensoflow如何在已训练模型上继续训练fineturn的问题。
训练代码
任务描述: x = 3.0, y = 100.0, 运算公式 x×w+b = y,求 w和b的最优解。
# -*- coding: utf-8 -*-)
import tensorflow as tf
# 声明占位变量x、y
x = tf.placeholder("float", shape=[none, 1])
y = tf.placeholder("float", [none, 1])
# 声明变量
w = tf.variable(tf.zeros([1, 1]),name='w')
b = tf.variable(tf.zeros([1]),name='b')
# 操作
result = tf.matmul(x, w) + b
# 损失函数
lost = tf.reduce_sum(tf.pow((result - y), 2))
# 优化
train_step = tf.train.gradientdescentoptimizer(0.0007).minimize(lost)
with tf.session() as sess:
# 初始化变量
sess.run(tf.global_variables_initializer())
saver = tf.train.saver(max_to_keep=3)
# 这里x、y给固定的值
x_s = [[3.0]]
<