Keras: Connect Sequential Model and Functional API Model

Created on 24 Aug 2016  路  2Comments  路  Source: keras-team/keras

I want to finetune resnet50 model. But my data's label are just binary, so I have to adapt new full connected layer on top of resnet 50's convolutional layers.

Conceptually, my situation is like below,

model = ResNet50(include_top=False, weights='imagenet')  # Functional API 
top_model = TopModel(model.output_shape[1:])
top_model.load_weights("top_model.hdf5")
model.add(top_model)  # => AttributeError: 'Model' object has no attribute 'add'

My question is,

Is there any easy way to stack 'Sequential based' model on 'Functional API based' model ??

I mimic following codes.

Most helpful comment

model = ResNet50(include_top=False, weights='imagenet')  # Functional API 
top_model = TopModel(model.output_shape[1:])
top_model.load_weights("top_model.hdf5")
# Stack top_model on top
model = Model(input=model.input, output=top_model(model.output))

All 2 comments

model = ResNet50(include_top=False, weights='imagenet')  # Functional API 
top_model = TopModel(model.output_shape[1:])
top_model.load_weights("top_model.hdf5")
# Stack top_model on top
model = Model(input=model.input, output=top_model(model.output))

Thanks for the great responses!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anjishnu picture anjishnu  路  3Comments

harishkrishnav picture harishkrishnav  路  3Comments

vinayakumarr picture vinayakumarr  路  3Comments

rantsandruse picture rantsandruse  路  3Comments

snakeztc picture snakeztc  路  3Comments