简体   繁体   English

Conv1D 在 Keras 中的行为(张量的维度)

[英]Behavior of Conv1D in Keras (Dimensions of Tensors)

My question concerns the dimensions of the tensors involved in a Conv1D layer in Keras.我的问题涉及 Keras 中 Conv1D 层中涉及的张量的维度。 The input shape is supposed to be (batch, steps, channels).输入形状应该是(批次、步骤、通道)。 I have for example Accelerometer data, where I get a time signal for each Axis.我有例如加速度计数据,我在其中获得每个轴的时间信号。 I would like to do inference on time windows of length 50, so one sample for inference has the shape (50, 3).我想对长度为 50 的时间窗口进行推理,因此一个推理样本的形状为 (50, 3)。

Now, if I use a Conv1D layer as first layer on this data with kernel_size=10 and filters=64 the outcome of the first layer on one window of data has the shape (41, 64).现在,如果我使用 Conv1D 层作为该数据的第一层,kernel_size=10 和 filters=64,则一个数据窗口上第一层的结果具有形状 (41, 64)。 I completely understand that 41 pops up, as it is the number of samples that arises from the convolution of a length 50 signal with a length 10 kernel.我完全理解 41 弹出,因为它是由长度为 50 的信号与长度为 10 的内核卷积产生的样本数。 However, I am not entirely sure where the three axis of my accelerometer are in these data.但是,我不完全确定我的加速度计的三个轴在这些数据中的位置。 I would have more expected the following behavior:我更期待以下行为:

input_shape = (batch, steps, channels), output_shape = (batch, steps_after_conv, channels, filters) input_shape =(batch,steps,channels),output_shape =(batch,steps_after_conv,channels,filters)

Can somebody explain that behavior of Keras?有人可以解释 Keras 的这种行为吗? I did not quite understand it from the documentation.我从文档中不太明白它。

卷积运算

As shown in the image given above (Image courtesy: http://followtheart.info/kareff-Mon_15_14.html ), in a convolution operation in a CNN , each filter convolves over all channels (three channels in case of an RGB image) for calculating output value.如上图所示(图片提供: http : //followtheart.info/kareff-Mon_15_14.html ),在CNNconvolution运算中,每个滤波器对所有通道进行卷积(RGB 图像的情况下为三个通道)用于计算输出值。 So in your case of 64 filters, each filter will take values from all input channels in its receptive field.因此,在您使用 64 个过滤器的情况下,每个过滤器将从其感受野中的所有输入通道获取值。 Hence your output will have outputs from 64 filters irrespective of the number of channels you have in your input.因此,无论输入中的通道数量如何,您的输出都将具有 64 个过滤器的输出。

For a batch of images (batch_size, num_channels, height, width) , output will be of shape (batch_size, num_filters, height_after_conv, width_after_conv) .对于一批图像(batch_size, num_channels, height, width) ,输出的形状为(batch_size, num_filters, height_after_conv, width_after_conv)

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

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