吴良超 融合 cnn+lstm
生活随笔
收集整理的這篇文章主要介紹了
吴良超 融合 cnn+lstm
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
吳良超 融合 cnn+lstm
鏈接
from keras.applications.vgg16 import VGG16 from keras.models import Sequential, Model from keras.layers import Input, TimeDistributed, Flatten, GRU, Dense, Dropout from keras import optimizersdef build_model():pretrained_cnn = VGG16(weights='imagenet', include_top=False)# pretrained_cnn.trainable = Falsefor layer in pretrained_cnn.layers[:-5]:layer.trainable = False# input shape required by pretrained_cnninput = Input(shape = (224, 224, 3)) x = pretrained_cnn(input)x = Flatten()(x)x = Dense(2048)(x)x = Dropout(0.5)(x)pretrained_cnn = Model(inputs = input, output = x)input_shape = (None, 224, 224, 3) # (seq_len, width, height, channel)model = Sequential()model.add(TimeDistributed(pretrained_cnn, input_shape=input_shape))model.add(GRU(1024, kernel_initializer='orthogonal', bias_initializer='ones', dropout=0.5, recurrent_dropout=0.5))model.add(Dense(categories, activation = 'softmax'))model.compile(loss='categorical_crossentropy',optimizer = optimizers.SGD(lr=0.01, momentum=0.9, clipnorm=1., clipvalue=0.5),metrics=['accuracy'])return modelkeras 官方給出的例子
from tensorflow import keras from tensorflow.keras import layers from tensorflow.keras.applications import InceptionV3video=keras.Input(shape=(None,150,150,3))cnn=InceptionV3(weights='imagenet',include_top=False,pooling='avg')cnn.trainable=Falseframe_features=layers.TimeDistributed(cnn)(video)video_vector=layers.LSTM(256)(frame_features)posted on 2018-11-02 14:51 luoganttcc 閱讀(...) 評(píng)論(...) 編輯 收藏
總結(jié)
以上是生活随笔為你收集整理的吴良超 融合 cnn+lstm的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: keras example
- 下一篇: mongodb转json