构建LSTM网络

import numpy as np
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, LSTM, Input
from keras.layers import Conv2D, MaxPooling2D
from keras.optimizers import SGD
from keras.layers import Input, Dense
from keras.models import Model

input_x = Input(shape=(20,4096,))
x = LSTM(256, return_sequences=True)(input_x)
#x = LSTM(100)(x)
x =Flatten()(x)

x = Dense(2048)(x)
x = Dropout(0.5)(x)

pred = Dense(4, activation='softmax')(x)
model = Model(input_x, pred)
model.compile('rmsprop', 'categorical_crossentropy', ['acc', ])
model.summary()

构建LSTM网络_第1张图片

理解flatten 与dense 的区别

import numpy as np
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, LSTM, Input
from keras.layers import Conv2D, MaxPooling2D
from keras.optimizers import SGD
from keras.layers import Input, Dense
from keras.models import Model

input_x = Input(shape=(20,4096,))
x = LSTM(256, return_sequences=True)(input_x)
#x = LSTM(100)(x)
#x =Flatten()(x)

x = Dense(2048)(x)
x = Dropout(0.5)(x)

pred = Dense(4, activation='softmax')(x)
model = Model(input_x, pred)
model.compile('rmsprop', 'categorical_crossentropy', ['acc', ])
model.summary()

 构建LSTM网络_第2张图片

你可能感兴趣的:(python3)