How to use CPU in Tensorflow 2 globally

Viewed 1222

I know I can set

with tf.device('/cpu:0'):
    model.predict(...)

to use the CPU (or GPU) with Tensorflow 2.0, however, is there a way to set this at the beginning of a script to use the CPU exclusively?

In Tensorflow 1.x it was possible to use

config = tf.ConfigProto(device_count = {'GPU': 0})

but it was depreciated.

Is there a new way to do it?

0 Answers
Related