I have a use-case where I need to make predictions from a trained LSTM model (TensorFlow = 2.8 and Python = 3.9) where the dataset is large and results in OOM error on my GPU card. The turnaround I have is to predict for each batch and store the resulting tensor in a Python3 list:
# Create TF dataset to iterate over-
train_dataset = tf.data.Dataset.from_tensor_slices(X_train).batch(batch_size)
# batch_size = 256
# Python3 list to contain all model predictions-
preditcions = []
for x in train_dataset:
y_pred = model_e2d2.predict(x)
preditcions.append(y_pred)
# Sanity check-
len(preditcions)
# (2048)
# Each batch of prediction has the size: (256, 5, 11).
# Sanity check-
preditcions[0].shape, preditcions[-1].shape
# ((256, 5, 11), (222, 5, 11))
The aim is to convert precitions Python3 list to a numpy array of desired shape: (524254, 5, 11)
?
preditcions = np.vstack(preditcions)should already do it?reshapewon't help.concatenateon the first axis?