Keras: Sequential model to Functional model

Created on 9 Jul 2016  路  9Comments  路  Source: keras-team/keras

Is there any way of converting Sequential model into Functional model? (same architecture, same weights)

Most helpful comment

Sequential uses the Model class internally, so if you have a Sequential model in seqmodel you can do seqmodel.build() or seqmodel.compile(...) and get the functional model via funcmodel = seqmodel.model.

Is that what you meant?

All 9 comments

Sequential uses the Model class internally, so if you have a Sequential model in seqmodel you can do seqmodel.build() or seqmodel.compile(...) and get the functional model via funcmodel = seqmodel.model.

Is that what you meant?

@mbollmann Yes ! Thanks, thats exactly what i meant. Thank you very much!
It really makes joining two different models together easier, i think it would be nice if it was mentioned in docs.

Anyway, thanks!.

@hawkerpl Do you share one example how to implement it ? Thanks.

@mbollmann what about vice versa. I have a Model (vgg16) and I want to convert it to Sequential

@johnny5550822 I don't know, maybe Sequential(layers=model.layers) could work? Provided that the model actually is sequential, of course. But why would you ever want to do that? Model class is more powerful after all and Sequential seems to be mainly for convenience.

@mbollmann because I had a situation where there is Modal and Sequential model and I want to merge them into a single network. I think I have figure it out.

@johnny5550822
Could you please share your solution? I'm trying to do the same thing (convert a _Model_ into a _Sequential_)

@alyato Functional model to Sequential: https://gist.github.com/hawkerpl/ce488f7ecdbe9c9d37fb62930dbe3649

@ psgl @johnny5550822 @mbollmann To convert the functional to sequential in keras, you just need to call the constructor Sequential(layers=functional_model.layers)

@hawkerpl
Thanks for your suggestions. I know this thread is pretty old, but I don't think the gist that referenced is the example you were thinking it was. I don't see a functional model or a conversion in the gist. Am I missing something? If there is a different example that you had in mind, it would still be great to see.
Thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

braingineer picture braingineer  路  3Comments

MarkVdBergh picture MarkVdBergh  路  3Comments

snakeztc picture snakeztc  路  3Comments

harishkrishnav picture harishkrishnav  路  3Comments

somewacko picture somewacko  路  3Comments