简体   繁体   English

Keras Conv1D层在哪个轴上工作?

[英]Which axis does Keras Conv1D layer work on?

I'm writting a model with Keras for time series analysis.我正在写一个 model 和 Keras 用于时间序列分析。 The structure of the info I'm sending to the neural.network is (samples, timesteps, features)我发送到 neural.network 的信息结构是(samples, timesteps, features)

My idea is to have three steps on the design of the.network.我的想法是在.network的设计上分三步走。 A first step with a (or some) Conv1D layers, then another with LSTMs and finally some Dense layers.第一步使用(或一些)Conv1D 层,然后使用 LSTM,最后使用一些 Dense 层。

For the first layers (Conv1D), how can I select the axis where the convolution will be performed?对于第一层(Conv1D),我如何 select 执行卷积的轴? I'm trying to do that on the timesteps axis, but I'm not sure if with something like我正在尝试在时间轴上这样做,但我不确定是否使用类似

model = Sequential()
model.add(Conv1D(180, 60, padding="same", strides=5, activation="relu"))

the timesteps axis will be used, or a different one.将使用时间步长轴或其他轴。

By default, it's applied to the axis with the time steps.默认情况下,它应用于具有时间步长的轴。

import tensorflow as tf

timesteps = 7
features = 10

inputs = tf.random.uniform(shape=(100, timesteps, features), maxval=1, dtype=tf.float32)
filters = tf.random.uniform(shape=(3, 1, 1), maxval=1, dtype=tf.float32)

print(tf.keras.layers.Conv1D(filters=5, kernel_size=(3,))(inputs).shape)
(100, 5, 5)

The resulting shape is (n_samples, time_steps - (kernel_size - 1), filters)生成的形状是(n_samples, time_steps - (kernel_size - 1), filters)

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

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