keras中Convolution1D的使用

来源:互联网 发布:保险网络增员话术 编辑:程序博客网 时间:2024/05/01 00:13
这篇文章主要说明两个东西,一个是Convolution1D的介绍,另一个是model.summary()的使用。

首先我先说下model.summary(),此方法可以打印出模型的信息,读者可以查看每层输出内容。

接下来就说下Convolution1D的使用了,Convolution1D一维卷积,主要用于过滤一维输入的相邻元素,官方文档是这样的

keras.layers.convolutional.Convolution1D(nb_filter, filter_length, init='glorot_uniform', activation=None, weights=None, border_mode='valid', subsample_length=1, W_regularizer=None, b_regularizer=None, activity_regularizer=None, W_constraint=None, b_constraint=None, bias=True, input_dim=None, input_length=None)

然后官方给出的事例是这样的

# apply a convolution 1d of length 3 to a sequence with 10 timesteps,# with 64 output filtersmodel = Sequential()model.add(Convolution1D(64, 3, border_mode='same', input_shape=(10, 32)))# now model.output_shape == (None, 10, 64)# add a new conv1d on topmodel.add(Convolution1D(32, 3, border_mode='same'))# now model.output_shape == (None, 10, 32)

然后用print(model.summary())输出是这样的:

 

   下面我就围绕着上面代码简单介绍下:当把该层作为首层时,需要说明 input_shape

input_shape=(10, 32)简而言之就是10个32维的向量了,nb_filter : 卷积核的数量,也是输出的维度。filter_length : 每个过滤器的长度。首先我们先看第一个卷积层,输出shape很容易理解,因为有64个卷积核,所以输出也就是64,接下来我们看下参数:其实可以这么理解,我们把例子中(10,32)的信号进行1D卷积相当于对其进行卷积核为(filter_length, 32)的2D卷积

好了,就酱吧

                                             
0 0
原创粉丝点击