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.

Connecting Functional API models together

See original GitHub issue

@fchollet I’m trying to connect 2 functional API models together. here’s the summary of the 2 models:

The First “Input” Model (It works as a single model just fine):

model1

The Second Model that is supposed to be connected to the first model:

model2

I’m trying to connect them together like this:

model = Model(input=generator.input, output=[discriminator.output[0], discriminator.output[1]])

But I get this error:

Graph disconnected: cannot obtain value for tensor discriminator_input at layer “discriminator_input”. The following previous layers were accessed without issue: []

I tried to make a model out of them like this: Model(input=[generator.input, discriminator.input], output=[discriminator.output[0], discriminator.output[1]])

But this code just resulted in the second Model (and not the 2 of them together), or at least this is what I think after getting a summary of the model and plotting it’s structure.

can we do this in Keras (connecting functional API models) or is there another way? Thanks

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

21reactions
dieuwkehupkescommented, Oct 31, 2016

You should connect the output layer of the first network to the input layer of the second network. Something like:

Model(input=generator.input, output=discriminator(generator.output))
3reactions
krishhtofcommented, Jul 30, 2019

You should connect the output layer of the first network to the input layer of the second network. Something like:

Model(input=generator.input, output=discriminator(generator.output))

Hi @dieuwkehupkes,

I know it’s an old comment of yours, but it is still helpful. I’m using the same code as you’ve mentioned above to combine 2 separate Keras Models and it works correctly. EXCEPT for one small problem when I want to print out the summary of the newly combined model. When I print out the summary, I get the following output:

image

The main info from above to look out for is the last layer called model_1(Model). This is actually the model that I connected my first model to which you can see correctly above the model_1(Model) layer. What I want is the summary method from keras to print the entire model with all its layers and not just model_1(Model) as it shows above.

Do you or does anyone else know how one can achieve this in Keras?

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Functional API - Keras
The Keras functional API is a way to create models that are more flexible than the tf.keras.Sequential API. The functional API can handle ......
Read more >
Keras - Connecting Functional API models together
I want to know the possibilities when making a new Model based on models which have been made with the Functional API in...
Read more >
How to Use the Keras Functional API for Deep Learning
The Sequential model API is a way of creating deep learning models ... model layers and connecting them together, you must define the...
Read more >
Two Different Ways to Build Keras Models: Sequential API and ...
The Functional API method allows you to build models in a non-sequential fashion. You can build models that have branches, multiple inputs or ......
Read more >
Combining Multiple Features and Multiple Outputs Using ...
Keras functional API allows us to build each layer granularly, with part or all of the inputs directly connected to the output layer...
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