[英]Problem with tf.train.Saver() and GPU - TensorFlow
My code is structured as follows: 我的代码结构如下:
with tf.device('/gpu:1'):
...
model = get_model(input_pl)
...
with tf.Session() as sess:
saver = tf.train.Saver()
sess.run(tf.global_variables_initializer())
for epoch in range(num_epochs):
...
for n in range(num_batches):
...
sess.run(...)
# eval epoch
saver.save(sess, ...)
I want to save the model after the training phase. 我想在训练阶段后保存模型。 When I run it gives me this error:
当我运行它给我这个错误:
InvalidArgumentError (see above for traceback): Cannot assign a device for operation 'save/SaveV2': Could not satisfy explicit device specification '/device:GPU:1' because no supported kernel for GPU devices is available.
Reading this question I changed the code in this way: 阅读这个问题我用这种方式改变了代码:
saver = tf.train.Saver()
with tf.device('/gpu:1'):
...
model = get_model(pointcloud_pl)
...
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for epoch in range(num_epochs):
...
for n in range(num_batches):
...
sess.run(...)
# eval epoch
saver.save(sess, ...)
But now I get this error: 但是现在我收到了这个错误:
ValueError: No variables to save
I've tried also to do this way: 我也尝试过这样做:
with tf.Session() as sess:
saver = tf.train.Saver()
...
with tf.device('/gpu:1'):
sess.run(tf.global_variables_initializer())
for epoch in range(num_epochs):
...
for n in range(num_batches):
...
sess.run()
# eval epoch
saver.save(sess, ...)
And I still get the same error. 我仍然得到同样的错误。 The error is always in the
saver = tf.train.Saver()
line. 该错误始终在
saver = tf.train.Saver()
行中。
How can I solve this problem? 我怎么解决这个问题?
Solved doing this: 解决了这个问题:
tf.Session()
saver = tf.train.Saver()
with tf.device():
Here an example code 这是一个示例代码
with tf.Session() as sess:
...
model = get_model(input_pl)
saver = tf.train.Saver()
...
with tf.device('/gpu:1'):
sess.run(tf.global_variables_initializer())
for epoch in range(num_epochs):
...
for n in range(num_batches):
...
sess.run()
# eval epoch
saver.save(sess, ...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.