简体   繁体   中英

How to add layers to the bottom of a pretrained model in keras' functional api?

I am running into an error while adding layers to the bottom of the pretrained VGG16 model from keras' functional api.

I was going through the Deep Learning for Python tutorials and I think the book was written in an earlier addition of keras where the Sequential API is being used instead.

from tensorflow.keras.applications.vgg16 import VGG16
from keras.layers import Input,Flatten,Dense
from keras.models import Model

inp=(150,225,3)
inputs = Input(shape=inp)
base = VGG16(weights='../input/keras-pretrained- 
models/vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5',
         include_top=False,
         input_shape=inp)

base_output = base(inputs)
out = Flatten()(base_output)
out =Dense(256, activation='relu')(out)
out =Dense(1, activation='sigmoid')(out)


model = Model(inputs=inputs,outputs=out)

I am see the following error. AttributeError: 'InputLayer' object has no attribute 'outbound_nodes'

The problem was with my imports

from tensorflow.keras.layers import Input,Flatten,Dense
from tensorflow.keras.models import Model

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM