user19534996
user19534996

Reputation:

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 model.
For testing purposes I want to use that model for my data as well. Yet, I have trouble understanding the Keras documentation in regards to the Conv1D-layer. Could anyone help me to understand how to interpret the image (i.e., what does the 25x1x3 mean) and translate that to a Keras model?

My current code for the model looks something like this (not sure if any of that is right):

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'))

Upvotes: 1

Views: 215

Answers (1)

Reda El Hail
Reda El Hail

Reputation: 1016

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. We used RELU as an activation function.

So unlike the model you are showing in the question, the model in the paper has:

  • No dense layer after the first convolution layer, which you added in the model shown in the question
  • 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. It means 25 kernels of size (1,3) are applied to the input

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'))

Upvotes: 0

Related Questions