简体   繁体   中英

Which axis does Keras Conv1D layer work on?

I'm writting a model with Keras for time series analysis. The structure of the info I'm sending to the neural.network is (samples, timesteps, features)

My idea is to have three steps on the design of the.network. A first step with a (or some) Conv1D layers, then another with LSTMs and finally some Dense layers.

For the first layers (Conv1D), how can I select the axis where the convolution will be performed? 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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