如何在 Tensorflow 2 中全局使用 CPU

ReR*_*Red 5 tensorflow tensorflow2.0

我知道我可以设置

with tf.device('/cpu:0'):
    model.predict(...)
Run Code Online (Sandbox Code Playgroud)

但是,要在 Tensorflow 2.0 中使用 CPU(或 GPU),有没有办法在脚本开头设置它以独占使用 CPU?

在 Tensorflow 1.x 中可以使用

config = tf.ConfigProto(device_count = {'GPU': 0})
Run Code Online (Sandbox Code Playgroud)

但它已经贬值了。

有新的方法吗?