Last active
March 25, 2019 19:09
-
-
Save BAXTER001/5b2bb9e65b587f893298f09102436ca1 to your computer and use it in GitHub Desktop.
Keras multi gpu duplicate model names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.models import Model | |
from keras.layers import Input, Add | |
from keras.utils import multi_gpu_model | |
m_in = Input( shape=(1,) ) | |
m_out1 = Add()([m_in,m_in]) | |
m_out2 = m_in | |
m = Model( m_in, [m_out1,m_out2] ) | |
x = Input( shape=(1,) ) | |
compoundModel = Model( x, m( x ) ) | |
compoundModel = multi_gpu_model( compoundModel ,2) | |
#RuntimeError: ('The name "model_1" is used 2 times in the model. All layer names should be unique. Layer names: ', | |
#['input_2', 'lambda_1', 'lambda_2', 'model_2', 'model_1', 'model_1']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Merge outputs on CPU. | |
with tf.device('/cpu:0'): | |
merged = [] | |
for n,(name, outputs) in enumerate(zip(model.output_names, all_outputs)): | |
merged.append(concatenate(outputs, | |
axis=0, name=name+'_gpu_'+str(n))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would you please make a pr? This is useful to me.