【发布时间】:2018-10-31 11:41:44
【问题描述】:
我的代码结构如下:
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.
阅读this question我是这样改代码的:
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()之前
标签: python tensorflow gpu