我在Tensorflow中构建了一个模型,我试图将其转换为TensorFlow Estimator。这是我的一个例子:
train_op = tf.train.AdamOptimizer(learning_rate=lr).minimize(cost)
saver = tf.train.Saver()
init = tf.global_variables_initializer()
assign_Wvh = pretrained_rsm.temporal_assignment(params['W'])
with tf.Session() as sess:
sess.run(init)
for epoch in range(epochs):
start = time.time()
_ = sess.run(train_op, feed_dict={x: input})
print("%i. elapsed time: %0.2f" % (epoch, time.time() - start))
# before saving the weights do an operation to change the weights
# only need to perform it once at the end to avoid unecessary operations
# that are time consuming at each iteration
_ = sess.run(assign_Wvh)
# save the weights
save_path = saver.save(sess, os.path.join(weights_path, 'init.ckpt'))
我在考虑将此行添加到 model_fn (估算工具)中:
tf.train.get_global_step() == 1000: # 1000 is my specific epoch
do operation
但显然我不能用估算器做到这一点。
有人知道如何实现这样的事情吗?知道我仍然需要保存将通过最后一次操作转换的权重。