Answers for "add lstm with vgg16 model"

0

add lstm with vgg16 model

inp = Input(shape=(224,224,3))
vgg_16 = VGG16(include_top=False, weights='imagenet', input_tensor=inp)
x = vgg_16.output

#Really depends on whether you want pre-trained values to be fixed or not
for layer in vgg_16.layers:
    layer.trainable = False 

#Add here whatever dense layers you need
x = TimeDistributed(Flatten())(x)
x = LSTM(256, return_sequences=False, dropout=0.5)(x)
predictions = Dense(4, name="dense", activation="softmax")(x)

my_model = Model(inputs=vgg_16.inputs, outputs=predictions)
my_model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
Posted by: Guest on September-22-2020

Browse Popular Code Answers by Language