Note: I have already read How to reshape BatchDataset class tensor? but the solution doesn't apply here.
As mentioned in Train a neural network with input as sliding windows of a matrix with Tensorflow / Keras, and memory issues, I need to train a neural network with all sliding windows of shape (16, 2000) from a matrix of shape (10000, 2000). (In my other post it's 100k, but here 10k is ok).
import tensorflow
import numpy as np
X = np.array(range(20000000)).reshape(10000, 2000)
X = tensorflow.keras.preprocessing.timeseries_dataset_from_array(X, None, 16, sequence_stride=1, sampling_rate=1, batch_size=32)
for b in X:
print(b) # Tensor of shape (32, 16, 2000)
break
The problem is that I need to feed it into a model which requires a (..., 16, 2000, 1) shape.
model = Sequential()
model.add(Conv2D(16, kernel_size=(9, 9), activation='relu', input_shape=(16, 2000, 1), padding='same'))
...
model.fit(X, Y, epochs=8)
I tried
X = tensorflow.reshape(X, (-1, 16, 2000, 1))
without success.
How to do this, i.e. have the output of timeseries_dataset_from_array
of shape (..., 16, 2000, 1)
?