1

I have a multidimensional time series dataset which has the following shape (n_samples, 512, 9) where 512 is the timesteps and 9 are the channels.

After the first 1D CNN layer with 64 kernels my output shape is (n_samples, 512, 64). Now I would like to have my input to next layer which is an LSTM to be of the shape (n_samples, 384, 64).

It can be achieved if I have a Maxpool layer that returns maximum 3 values from pool size of 4 but is it possible to implement this in Keras?

Vikranth
  • 11
  • 2

1 Answers1

0

You can probably solve this with a keras.layers.Lambda layer, and the backend to tf.nn.in_top_k. Note that the handling is somewhat different from tf.nn.top_k, in that it does not pool if all the values are of the same value!

Now you can define yourself a function that returns the top k values (and does so somewhat efficiently), and then pass it as a function to the lambda layer.

I sadly haven't worked enough with Keras to type out the specific code, but maybe this is help enough to point you in the right direction. Also, there exists a similar thread for TensorFlow specifically.

dennlinger
  • 9,890
  • 1
  • 42
  • 63