Can't use multiple instances of InceptionV3 in the same model
See original GitHub issuePlease make sure that the boxes below are checked before you submit your issue. If your issue is an implementation question, please ask your question on StackOverflow or join the Keras Slack channel and ask there instead of filing a GitHub issue.
Thank you!
-
Check that you are up-to-date with the master branch of Keras. You can update with: pip install git+git://github.com/fchollet/keras.git --upgrade --no-deps
-
If running on TensorFlow, check that you are up-to-date with the latest version. The installation instructions can be found here.
-
If running on Theano, check that you are up-to-date with the master branch of Theano. You can update with: pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps
-
Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).
from keras.applications import InceptionV3
from keras.applications import Xception
from keras.preprocessing import image
from keras.models import Model
from keras.layers import concatenate
from keras.layers import Dense, GlobalAveragePooling2D, Input, Embedding, LSTM
from keras import backend as K
from keras.applications.inception_v3 import preprocess_input
from keras.preprocessing.image import img_to_array
from keras.preprocessing.image import load_img
f1_base = InceptionV3(weights='imagenet', include_top=False)
for layer in f1_base.layers:
layer.trainable = False
f1_x = f1_base.output
f1_x = GlobalAveragePooling2D()(f1_x)
f1_x = Dense(1024, activation='relu')(f1_x)
f2_base = InceptionV3(weights='imagenet', include_top=False)
for layer in f2_base.layers:
layer.trainable = False
f2_x = f2_base.output
f2_x = GlobalAveragePooling2D()(f2_x)
f2_x = Dense(1024, activation='relu')(f2_x)
x = concatenate([f1_x, f2_x])
x = Dense(1024, activation='relu')(x)
x = Dense(1024, activation='relu')(x)
x = Dense(5, activation='sigmoid', name="main_output")(x)
model = Model(inputs=[f1_base.input, f2_base.input],outputs=[x])
model.compile(loss="categorical_crossentropy", optimizer="sgd")
print "DONE"
Produces the error
RuntimeError: The name "mixed0" is used 2 times in the model. All layer names should be unique.
I want to run the inception model on multiple frames of a video clip and create a model of the result. I currently can’t do that because of layer naming conflicts.
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (3 by maintainers)
I’ve run into this as well a few times. maybe there should be a parameter in the keras.applications models to let you automatically append a string to the layer names? like
and then the name gets postpended to each layer name?
Setting the model’s _name attribute to something unique works for me, I hope it works for others too.
model = InceptionV3(include_top = False, input_shape = (256,256,3))
model._name = name