Limit GPU memory growth in tensorflow 2.4.x by setting environment variable
Simplest way(TensorFlow 2.2+)
import tensorflow as tfgpus = tf.config.experimental.list_physical_devices('GPU')for gpu in gpus: tf.config.experimental.set_memory_growth(gpu, True)
Or set environment variable
setTF_FORCE_GPU_ALLOW_GROWTH
to true
.
if TensorFlow 2.0 and 2.1
import tensorflow as tftf.config.gpu.set_per_process_memory_growth(True)
License:
CC BY 4.0