Lei*_*Lei 7 python performance tensorflow
我使用输入管道方法将数据提供给图形,并tf.train.shuffle_batch实现生成批处理数据.然而,随着训练的进行,张量流变得越来越慢,以后的迭代.我很困惑导致它的根本原因是什么?非常感谢!我的代码片段是:
def main(argv=None):
# define network parameters
# weights
# bias
# define graph
# graph network
# define loss and optimization method
# data = inputpipeline('*')
# loss
# optimizer
# Initializaing the variables
init = tf.initialize_all_variables()
# 'Saver' op to save and restore all the variables
saver = tf.train.Saver()
# Running session
print "Starting session... "
with tf.Session() as sess:
# initialize the variables
sess.run(init)
# initialize the queue threads to start to shovel data
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
print "from the train set:"
for i in range(train_set_size * epoch):
_, d, pre = sess.run([optimizer, depth_loss, prediction])
print "Training Finished!"
# Save the variables to disk.
save_path = saver.save(sess, model_path)
print("Model saved in file: %s" % save_path)
# stop our queue threads and properly close the session
coord.request_stop()
coord.join(threads)
sess.close()
Run Code Online (Sandbox Code Playgroud)
小智 1
训练时,您应该只执行一次 sess.run 。建议尝试这样的方法,希望有帮助:
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for i in range(train_set_size * epoch):
train_step.run([optimizer, depth_loss, prediction])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1349 次 |
| 最近记录: |