Tensorflow,还原特定设备中的变量

Tia*_*ira 3 tensorflow

也许我的问题有点天真,但是我在tensorflow文档中什么都没找到。

我有一个训练有素的张量流模型,其中的变量被放置在GPU中。现在,我想还原此模型并使用CPU对其进行测试。

如果我通过“ tf.train.Saver.restore”执行此操作,如示例所示: saver = tf.train.import_meta_graph("/tmp/graph.meta") saver.restore(session, "/tmp/model.ckp")

我有以下例外情况:

InvalidArgumentError: Cannot assign a device to node 'b_fc8/b_fc8/Adam_1': Could not satisfy explicit device specification '/device:GPU:0' because no devices matching that specification are registered in this process; available devices: /job:localhost/replica:0/task:0/cpu:0

如何在中还原这些变量CPU

谢谢

Yar*_*tov 7

使用clear_devices标志,即

saver = tf.train.import_meta_graph("/tmp/graph.meta", clear_devices=True)
Run Code Online (Sandbox Code Playgroud)