After Keras 2.X version, it is very convenient to support the use of multiple GPUs for training. Using multiple GPUs can improve our training process, such as speeding up and solving the problem of insufficient memory.
mine tensorflow_gpu=1.15.0
;Keras==2.1.6
code involved
- Set the number of GPUs that can be used
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "2,3" # 仅让id=2,3的GPU可被使用
- When there are multiple GPUs in your computer, keras.utils.multi_gpu_model provides a built-in function, which can generate a data parallel version of any model, and supports parallelism on up to 8 GPUs.
from keras.utils import multi_gpu_model #加载头文件
model = VGG16_model(input_shape=(224,