CNN archicture with keras

时间:2019-05-06 12:06:09

标签: python keras conv-neural-network

I am working with a binary classification problem with Python (keras).

my CNN network architecture is given below:

    def CNN():
      model = Sequential()
      model.add(Conv2D(64, kernel_size=(1, 3), activation='elu', padding='valid', input_size=(20,10, 1)))
      model.add(Conv2D(32, kernel_size=(1, 3), activation='elu', padding='valid'))
      model.add(Conv2D(16, kernel_size=(1, 3), activation='elu', padding='valid'))

      model.add(Flatten())
      model.add(Dense(512, activation='elu'))
      model.add(Dense(512, activation='sigmoid'))

Now I am trying to describe my CNN architecture in a table: I have one dimensional dataset with 200 column 200k number of rows.

Batch Size = 64

CNN 1 - channel 64 CNN 2 - channel 32 CNN 3 - channel 16

FC1 - 500 units FC2 - 1 Unit

Here I am trying to describe the architecture in a table (problem in this section)

-- CNN1 -- CNN2 -- CNN3 -- FC1 -- FC2

Input_Shape-- 64* 64 * 200 * 1 -- 32* 64 * 200 * 1 -- 16* 64 * 200 * 1 -- 16*64*200*1*500 - 16*64*200*1*500

Output_Shape -- 32* 64 * 200 * 1 - 16* 64 * 200 * 1 - 16* 64 * 200 * 1 - 16*64*200*1*500 -- 1

I am heaving trouble to define the correct input output shape of my network, seeking some help. Thank you.

1 个答案:

答案 0 :(得分:2)

在Keras中用于图像分类的标准CNN的输入形状如下:

input_shape = ( batch_size , height , width , num_channels )

第一Conv2D层的输入形状为:

img_height = 20
img_width = 10
num_channels = 1

model.add(Conv2D(64, kernel_size=(1, 3), activation='elu', padding='valid', 
input_size=(img_height,img_width, num_channels)))

由于您正在执行二进制分类,因此最后一个Dense层如下所示:

model.add(Dense(1, activation='sigmoid'))

此外,作为奖励,模型编制如下:

model.compile( loss='binary_crossentropy' , optimizer='adam' , metrics=['accuracy'] )