我的代码结构如下:
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, ...)
我想在训练阶段后保存模型。 运行时会出现以下错误:
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.
阅读这个问题后,我以这种方式更改了代码:
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, ...)
但现在我遇到了这个错误:
ValueError: No variables to save
我也尝试过这种方式:
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, ...)
我仍然遇到相同的错误。错误总是出现在saver = tf.train.Saver()
这一行。
我该如何解决这个问题?
with tf.device():
和tf.Session()
之间。 - User