question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't use multiple instances of InceptionV3 in the same model

See original GitHub issue

Please 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:closed
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
jmhesselcommented, Jul 25, 2017

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

f1_base = InceptionV3(weights='imagenet', include_top=False, name='f1_base')

and then the name gets postpended to each layer name?

1reaction
bundasmacommented, Aug 10, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Wrong classification with Inceptionv3 - Stack Overflow
Main problem: Reason is that rescaling is missing. When using image data generators rescale factor is given. However, when images are ...
Read more >
tf.keras.applications.inception_v3.InceptionV3 - TensorFlow
This function returns a Keras image classification model, optionally loaded with weights pre-trained on ImageNet. For image classification use ...
Read more >
Inception V3 Deep Convolutional Architecture For Classifying ...
One of the most famous models that can be used for transfer learning is Inception V3. As mentioned above, this model was originally...
Read more >
Advanced Guide to Inception v3 | Cloud TPU
This document discusses aspects of the Inception model and how they come together to make the model run efficiently on Cloud TPU. It...
Read more >
Deep convolutional neural network Inception-v3 model for ...
The three NHL images that were misdiagnosed as reactive lymphoid hyperplasia consisted of two cases of follicular lymphoma and one case of marginal...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found