更新时间:2023-12-02 18:24:22
假设图像shape=(dim_x, dim_y, img_channels)
,您可以通过设置以下内容获得1D
卷积:
Assuming that your image shape=(dim_x, dim_y, img_channels)
you can obtain a 1D
convolution by setting:
conv1d_on_image = Convolution2D(output_channels, 1, dim_y, border_mode='valid')(input)
请记住,此层的输出将具有形状(dim_x, 1, output_channels)
.如果您希望输入是连续的,则可以通过设置以下内容来使用Reshape
层:
Remember that the output from this layer would have shape (dim_x, 1, output_channels)
. If you want your input to be sequential you may use the Reshape
layer by setting:
conv1d_on_image = Reshape((dim_x, output_channels))(conv1d_on_image)
这将产生形状为(dim_x, output_channels)
的输出.
This would produce output with shape (dim_x, output_channels)
.
一个有趣的事实是,这正是Conv1D
在具有tf
后端的Keras
中工作的方式.
An interesting fact is that this is exactly the way how Conv1D
works in Keras
with tf
backend.