Warm tip: This article is reproduced from serverfault.com, please click

anaconda-对于tensorflow 2.x,如何在CPU和GPU版本之间切换?

(anaconda - For tensorflow 2.x, how to switch between the CPU and GPU version?)

发布于 2020-06-09 09:19:01

我已经将anaconda更新为最新版本。它同时安装了tensorflow 2.2和tensorflow-gpu 2.2。但是当I时import tensorflow,tensorflow-gpu是要使用的默认值。有没有办法在它们之间切换?

在此网站上询问的类似问题全部针对1.x版本。我已经尝试了解决方案,但似乎不适用于2.x版本。张量流在CPU / GPU之间切换

Questioner
CyberPlayerOne
Viewed
11
1,124 2020-06-11 17:46:07

这应该可以解决你的问题:

with tf.device('/gpu:0'):
    # YOUR def main() OR model.fit()
with tf.device('/cpu:0'):
    # YOUR def main() OR model.fit()

这应该适用于不带会话的TF2。