当前位置:网站首页>CNN-LSTM的flatten
CNN-LSTM的flatten
2022-06-28 20:03:00 【seven_不是赛文】
CNN和LSTM之间该如何连接?
之前有看到过说,展平也行不展平也行
第一种做法,展平
假设你最原始的序列的最大长度为100,词嵌入之后,维度为16,那就是[N, 100,16]。假设你CNN相同卷积并输出64通道,那CNN之后的输出就是[N, 100, 64]。然后你可以把它flatten成[N, 6400]输入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())
#如果输入的形状为(None,32),
# 经过添加RepeatVector(3)层之后,
# 输出变为(None,3,32),RepeatVector不改变我们的步长,
# 改变我们的每一步的维数(即:属性长度)
model.add(RepeatVector(n_outputs))
model.add(LSTM(200, activation='relu', return_sequences=True))
# TimeDistributed和Dense一起配合使用,
# 主要应用于一对多,多对多的情况。
model.add(TimeDistributed(Dense(100, activation='relu')))
# input_shape = (10, 16),表示步长是10,
# 每一步的维度为16,(即:每一个数据的属性长度为16))
# 首先使用TimeDistributed(Dense(8),input_shape = (10, 16))
# 把每一步的维度为16变成8,不改变步长的大小
# eg:输入形状然后(50, 10, 16),则这一层之后的输出为(50, 10, 8)
model.add(TimeDistributed(Dense(1)))
model.compile(loss='mse', optimizer='adam', metrics=['accuracy'])
print(model.summary())

第二种方法,不展平
比如,也可以直接把[N, 100, 64]输入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())

结果显示
还是有区别的:
边栏推荐
- ROS中quaternion四元數和歐拉角轉換
- 输入分隔符
- 字符和整数
- 核芯物联蓝牙aoa定位系统服务器配置估算
- 2788.Cifera
- Markdown mermaid种草(1)_ mermaid简介
- SQL server2019 create a new SQL server authentication user name and log in
- Severity code description project file line suppress status error lnk2038 detected a mismatch of "runtimelibrary": the value "md\u dynamicrelease" does not match the value "mdd\u dynamicde"
- A few lines of code can realize complex excel import and export. This tool class is really powerful!
- 28 rounds of interviews with 10 companies in two and a half years
猜你喜欢

如何获取飞机穿过雷达两端的坐标

easypoi

Rsync remote synchronization

社招两年半10个公司28轮面试面经

电子科大(申恒涛团队)&京东AI(梅涛团队)提出用于视频问答的结构化双流注意网络,性能SOTA!优于基于双视频表示的方法!...

SQL server2019 create a new SQL server authentication user name and log in

Racher add / delete node

easypoi

On the first anniversary of the data security law, which four major changes are coming?

2022茶艺师(中级)考试模拟100题及模拟考试
随机推荐
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
522. 最长特殊序列 II(贪心&双指针)
2280.Cupboards
严重性 代码 说明 项目 文件 行 禁止显示状态 错误 LNK2038 检测到“RuntimeLibrary”的不匹配项: 值“MD_DynamicRelease”不匹配值“MDd_DynamicDe
SaaS sales upgrade under the new situation | tob Master Course
3. integrate listener
Class loading mechanism and object creation
Huawei cloud onemeeting tells you that the whole scene meeting is held like this!
Employee salary management system
On the first anniversary of the data security law, which four major changes are coming?
Why does next() in iterator need to be forcibly converted?
Shell reads the value of the JSON file
jsp中获取session中的值
Win 10 create a gin framework project
resilience4j 重试源码分析以及重试指标采集
【学习笔记】聚类分析
社招两年半10个公司28轮面试面经
2022 P cylinder filling test exercises and online simulation test
QSP read label configuration error
QSP读取标签配置错误问题