当前位置:网站首页>Flatten of cnn-lstm
Flatten of cnn-lstm
2022-06-28 20:20:00 【seven_ Not Severn】
CNN and LSTM How to connect ?
I have seen it before , Flatten or not
The first way , Flattening
Suppose that the maximum length of your original sequence is 100, After word embedding , Dimension for 16, That's it [N, 100,16]. Suppose you CNN Same convolution and output 64 passageway , that CNN Then the output is [N, 100, 64]. Then you can put it flatten become [N, 6400] Input LSTM.
model = Sequential()
model.add(Conv1D(filters=64, kernel_size=3, activation='relu',
input_shape=(n_timesteps, n_features)))
model.add(Conv1D(filters=64, kernel_size=3, activation='relu'))
model.add(MaxPooling1D(pool_size=2))
model.add(Flatten())
# If the input shape is (None,32),
# After adding RepeatVector(3) After the layer ,
# The output changes to (None,3,32),RepeatVector Don't change our step size ,
# Change the dimension of our every step ( namely : Attribute length )
model.add(RepeatVector(n_outputs))
model.add(LSTM(200, activation='relu', return_sequences=True))
# TimeDistributed and Dense Used together ,
# Mainly used in one to many , Many to many situation .
model.add(TimeDistributed(Dense(100, activation='relu')))
# input_shape = (10, 16), Indicates that the step size is 10,
# The dimension of each step is 16,( namely : The attribute length of each data is 16))
# use first TimeDistributed(Dense(8),input_shape = (10, 16))
# The dimension of each step is 16 become 8, Do not change the size of the step
# eg: Enter a shape and (50, 10, 16), Then the output after this layer is (50, 10, 8)
model.add(TimeDistributed(Dense(1)))
model.compile(loss='mse', optimizer='adam', metrics=['accuracy'])
print(model.summary())

The second method , No flattening
such as , You can also directly [N, 100, 64] Input LSTM.
model = Sequential()
model.add(Conv1D(filters=64, kernel_size=3, activation='relu',
input_shape=(n_timesteps, n_features)))
model.add(Conv1D(filters=64, kernel_size=6, activation='relu'))
model.add(MaxPooling1D(pool_size=1))
model.add(RepeatVector(n_outputs))
model.add(LSTM(200, activation='relu', return_sequences=True))
model.add(TimeDistributed(Dense(100, activation='relu')))
model.add(TimeDistributed(Dense(1)))
model.compile(loss='mse', optimizer='adam', metrics=['accuracy'])
print(model.summary())

Results show
There's a difference :
边栏推荐
猜你喜欢

UESTC (shenhengtao team) & JD AI (Mei Tao team) proposed a structured dual stream attention network for video Q & A, with performance SOTA! Better than the method based on dual video representation

Day88.七牛云: 房源图片、用户头像上传

Ali open source (easyexcel)

C # connect to the database to complete the operation of adding, deleting, modifying and querying
oracle delete误删除表数据后如何恢复

2022年T电梯修理考试题库模拟考试平台操作
![[graduation season · advanced technology Er] hard work can only pass, hard work can be excellent!](/img/e5/b6035abfa7d4bb59c3080d3b87ce45.jpg)
[graduation season · advanced technology Er] hard work can only pass, hard work can be excellent!

Echart: category text position adjustment of horizontal histogram

【算法篇】刷了两道大厂面试题,含泪 ”重学数组“

Analysis of all knowledge points of TCP protocol in network planning
随机推荐
Troubleshooting of pyinstaller failed to pack pikepdf
Real number operation
Compression and decompression commands
Lecture 30 linear algebra Lecture 4 linear equations
jsp中获取session中的值
How to understand the usability of cloud native databases?
Day88. qiniu cloud: upload house source pictures and user avatars
with torch.no_grad():的使用原因
严重性 代码 说明 项目 文件 行 禁止显示状态 错误 C1047 对象或库文件“.lib”是使用与其他对象(如“x64\Release\main.obj”)不同的
redisTemplate
集合之ArrayList
【算法篇】刷了两道大厂面试题,含泪 ”重学数组“
Xiaobai's e-commerce business is very important to choose the right mall system!
How to obtain the coordinates of the aircraft passing through both ends of the radar
Markdown mermaid种草(1)_ mermaid简介
各种类型长
Pipeline | and redirection >
With a market value of $120billion, how did intuit, an old tax giant, do it?
522. longest special sequence II (greedy & double pointer)
ArrayList of collection