Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensorflow, restore variables in a specific device

Tags:

tensorflow

Maybe my question is a bit naive, but I really didn't find anything in the tensorflow documentation.

I have a trained tensorflow model where the variables of it was placed in the GPU. Now I would like to restore this model and test it using the CPU.

If I do this via 'tf.train.Saver.restore` as in the example: saver = tf.train.import_meta_graph("/tmp/graph.meta") saver.restore(session, "/tmp/model.ckp")

I have the following excpetion:

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

How can I make restore these variables in the CPU?

Thanks

like image 360
Tiago Freitas Pereira Avatar asked Mar 17 '26 06:03

Tiago Freitas Pereira


1 Answers

Use clear_devices flag, ie

saver = tf.train.import_meta_graph("/tmp/graph.meta", clear_devices=True)
like image 167
Yaroslav Bulatov Avatar answered Mar 21 '26 02:03

Yaroslav Bulatov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!