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.

Keras 2.0.6, VGG16 'Model' object has no attribute 'add'

See original GitHub issue

在练习你们文档中"面向小数据集构建图像分类模型"案例时,第三部分微调预训练网络,出错.

top_model = Sequential()
top_model.add(Flatten(input_shape=model.output_shape[1:]))
top_model.add(Dense(256, activation='relu'))
top_model.add(Dropout(0.5))
top_model.add(Dense(1, activation='sigmoid'))

# note that it is necessary to start with a fully-trained
# classifier, including the top classifier,
# in order to successfully do fine-tuning
top_model.load_weights(top_model_weights_path)

# add the model on top of the convolutional base
model.add(top_model)

文章地址:https://blog.keras.io/building-powerful-image-classification-models-using-very-little-data.html 代码地址(59-75行):https://gist.github.com/fchollet/7eb39b44eb9e16e59632d25fb3119975

Keras 2.06, TensorFlow 1.2.x,

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

14reactions
MatinHzcommented, Jul 18, 2017

Use something like this:

base_model = applications.VGG16(...

top_model = Sequential()
top_model.add(Flatten(input_shape=base_model.output_shape[1:]))
top_model.add(Dense(256, activation='relu'))
top_model.add(Dropout(0.5))
top_model.add(Dense(1, activation='sigmoid'))
top_model.load_weights(top_model_weights_path)

model = Model(inputs= base_model.input, outputs= top_model(base_model.output))
8reactions
edovencommented, Aug 2, 2017

I solved by creating a new model (Sequential()) and by copying all the layers of VGG16 into this new model:

model = applications.VGG16(...)
...
new_model = Sequential() #new model
for layer in model.layers: 
    new_model.add(layer)
...
new_model.add(top_model) # now this works
Read more comments on GitHub >

github_iconTop Results From Across the Web

Model has no attribute 'shape' - VGG16 Model - Stack Overflow
The problem is that in error line, you are introducing your VGG16 model as input, and what you want is to introduce the...
Read more >
tf.keras.applications.vgg16.VGG16 | TensorFlow v2.11.0
None means that the output of the model will be the 4D tensor output of the last convolutional block.
Read more >
Image Augmentation for Deep Learning with Keras
In this post, you will discover how to use data preparation and data augmentation with your image datasets when developing and evaluating deep ......
Read more >
Home - Keras 2.0.6. Documentation
Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or Theano. It was...
Read more >
NEWS
Any R objects stored in private will only be available to methods, and will not be ... format() method for keras models (and...
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