Keras multi-gpu training model weights file can not issue a single cpu or gpu machines used

Nature: As a result of inconsistent naming keras

Principle: Keras version of the training which consists of a plurality of output branch, that is more loss, generally give a default name for each network, to find layers by naming at compile time.

Error point: After using keras.utils.training_utils.multi_gpu_model (), the name has changed. Therefore, when predicting, keras not find layers path

Due to the use of two GPU, and therefore expect two weight information reported, only a single 0

 

Solution:

We use a multi-GPUS training interfaces, using a single interface to save the GPU

def get_model(input_shape):
.
.
.
return model
model = get_model(input_shape) #此时为单GPU 搭建的model

from keras.utils import multi_gpu_model
# Replicates `model` on 4 GPUs.
# This assumes that your machine has 4 available GPUs.
paralleled_model = multi_gpu_model(model, gpus=4) #将搭建的model复制到4个GPU中
# for train 
paralleled_model.compile(loss='categorical_crossentropy',
                       optimizer='adam')
model.save_weights("single_gpu_model.h5")
# fit data for train 

 

tensorflow multi GPUS principle:

tf the data to map each GPU, and calculates loss gradient, and tf and the gradient are all loss to reduce the cpu, optimized gradient and average gradient cpu seeking loss of

Essence: Multi gpu acceleration principle is to increase the batch parallel processing capabilities, to run each GPU 64, a GPU 4 256 run Batch

 

Guess you like

Origin blog.csdn.net/weixin_38740463/article/details/91491307