简体   繁体   English

如何实现给定的model到Keras?

[英]How to implement a given model to Keras?

I am currently trying to reproduce a 1D-CNN approach I have found in the literature ( Ullah et al., 2022 ) In that publication the following baseline modelstructure is given:我目前正在尝试重现我在文献中发现的 1D-CNN 方法( Ullah 等人,2022 年),在该出版物中给出了以下基线模型结构: 一维CNN模型 . .
For testing purposes I want to use that model for my data as well.出于测试目的,我也想将 model 用于我的数据。 Yet, I have trouble understanding the Keras documentation in regards to the Conv1D-layer.然而,我无法理解有关 Conv1D 层的 Keras 文档。 Could anyone help me to understand how to interpret the image (ie, what does the 25x1x3 mean) and translate that to a Keras model?谁能帮助我理解如何解释图像(即 25x1x3 是什么意思)并将其转换为 Keras model?

My current code for the model looks something like this (not sure if any of that is right):我当前的 model 代码看起来像这样(不确定是否正确):

import keras
from keras.models import Sequential
from keras.layers import Dense, Conv1D

model = Sequential()
model.add(Conv1D(filters=25, kernel_size=3, activation='relu', input_shape=(12,1)))
model.add(Dense(25, activation='relu'))
model.add(Conv1D(50, 3, activation='relu'))
model.add(Conv1D(100, 3, activation='relu'))
model.add(Dense(2200, activation='relu'))
model.add(Dense(2, activation='relu'))
model.add(Dense(2, activation='softmax'))

In the paper, author says:在论文中,作者说:

The proposed base.network is a deep seven-layer.network that contains 3 convolution layers (with 25, 50, and 100 ker- nels, respectively), an activation layer after first convolution, two fully connected layer (having 2200 and 2 neurons, re- spectively), and a SoftMax layer at the end.拟议的 base.network 是一个深度七层网络,包含 3 个卷积层(分别具有 25、50 和 100 个内核)、第一个卷积后的激活层、两个全连接层(具有 2200 和 2 个神经元) ,分别),最后是一个 SoftMax 层。 We used RELU as an activation function.我们使用 RELU 作为激活 function。

So unlike the model you are showing in the question, the model in the paper has:因此,与您在问题中显示的 model 不同,论文中的 model 具有:

  • No dense layer after the first convolution layer, which you added in the model shown in the question在问题中显示的 model 中添加的第一个卷积层之后没有密集层
  • No activation is specified in the second and third convolution layers, so these layers stay without activation第二个和第三个卷积层没有指定激活,所以这些层保持没有激活

The 25x1x3 is the size of the kernels applied to the input vector. 25x1x3 是应用于输入向量的内核大小。 It means 25 kernels of size (1,3) are applied to the input这意味着将 25 个大小为 (1,3) 的内核应用于输入

I presume this should be the architecture you are looking for我想这应该是您正在寻找的架构

import keras
from keras.models import Sequential
from keras.layers import Dense, Conv1D, Flatten

model = Sequential()
model.add(Conv1D(filters=25, kernel_size=3, activation='relu', input_shape=(12,1)))
model.add(Conv1D(50, 3))
model.add(Conv1D(100, 3))
model.add(Flatten())
model.add(Dense(2200, activation='relu'))
model.add(Dense(2, activation='relu'))
model.add(Dense(2, activation='softmax'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM