TensorFlow 2.12: Trouble with tf.data.Dataset and Multi-Output Model Predictions
I'm confused about I'm currently working on a multi-output regression model using TensorFlow 2.12, and I'm experiencing issues with predicting outputs after training..... My model is structured to predict two outputs simultaneously, and I'm using the `tf.data.Dataset` API to manage my input data. However, when I try to make predictions, the output shapes are not what I expected, leading to an IndexError. Here's a simplified version of how I set up my model: ```python import tensorflow as tf # Define the model input_layer = tf.keras.layers.Input(shape=(10,)) output1 = tf.keras.layers.Dense(1, name='output1')(input_layer) output2 = tf.keras.layers.Dense(1, name='output2')(input_layer) model = tf.keras.Model(inputs=input_layer, outputs=[output1, output2]) model.compile(optimizer='adam', loss='mse') ``` I created a `tf.data.Dataset` for training: ```python import numpy as np # Generate dummy data data_x = np.random.random((100, 10)) data_y1 = np.random.random((100, 1)) data_y2 = np.random.random((100, 1)) dataset = tf.data.Dataset.from_tensor_slices((data_x, (data_y1, data_y2))) dataset = dataset.batch(32) ``` After training the model: ```python model.fit(dataset, epochs=10) ``` When I try predicting, I use the following code: ```python predictions = model.predict(data_x) print(predictions) ``` However, I get an behavior: ``` IndexError: list index out of range ``` I've also tried reshaping `data_x` to ensure compatibility, but it didn't solve the question. I expect `predictions` to be two arrays corresponding to my outputs, but instead, I am running into this IndexError. I would appreciate any insights into why this might be happening and how to correctly retrieve predictions from my model in this multi-output setup. Could this be a known issue? This is part of a larger application I'm building. What's the correct way to implement this?