ValueError: Unexpected result of `predict_function` (Empty batch_outputs). Please use `Model.compile(…, run_eagerly=True)`

We Are Going To Discuss About ValueError: Unexpected result of `predict_function` (Empty batch_outputs). Please use `Model.compile(…, run_eagerly=True)`. So lets Start this Python Article.

ValueError: Unexpected result of `predict_function` (Empty batch_outputs). Please use `Model.compile(…, run_eagerly=True)`

  1. How to solve ValueError: Unexpected result of `predict_function` (Empty batch_outputs). Please use `Model.compile(…, run_eagerly=True)`

    Change the axis dimension in expand_dims to 1 and slice your data like this, since it is 2D:
    import tensorflow as tf import numpy as np tf.random.set_seed(42) # Create some regression data X_regression = np.expand_dims(np.arange(0, 1000, 5), axis=1) y_regression = np.expand_dims(np.arange(100, 1100, 5), axis=1) # Split it into training and test sets X_reg_train = X_regression[:150, :] X_reg_test = X_regression[150:, :] y_reg_train = y_regression[:150, :] y_reg_test = y_regression[150:, :] tf.random.set_seed(42) # Recreate the model model_3 = tf.keras.Sequential([ tf.keras.layers.Dense(100), tf.keras.layers.Dense(10), tf.keras.layers.Dense(1) ]) # Change the loss and metrics of our compiled model model_3.compile(loss=tf.keras.losses.mae, # change the loss function to be regression-specific optimizer=tf.keras.optimizers.Adam(learning_rate=0.01), metrics=['mae']) # change the metric to be regression-specific # Fit the recompiled model model_3.fit(X_reg_train, y_reg_train, epochs=100) model_3.predict(X_reg_test)

  2. ValueError: Unexpected result of `predict_function` (Empty batch_outputs). Please use `Model.compile(…, run_eagerly=True)`

    Change the axis dimension in expand_dims to 1 and slice your data like this, since it is 2D:
    import tensorflow as tf import numpy as np tf.random.set_seed(42) # Create some regression data X_regression = np.expand_dims(np.arange(0, 1000, 5), axis=1) y_regression = np.expand_dims(np.arange(100, 1100, 5), axis=1) # Split it into training and test sets X_reg_train = X_regression[:150, :] X_reg_test = X_regression[150:, :] y_reg_train = y_regression[:150, :] y_reg_test = y_regression[150:, :] tf.random.set_seed(42) # Recreate the model model_3 = tf.keras.Sequential([ tf.keras.layers.Dense(100), tf.keras.layers.Dense(10), tf.keras.layers.Dense(1) ]) # Change the loss and metrics of our compiled model model_3.compile(loss=tf.keras.losses.mae, # change the loss function to be regression-specific optimizer=tf.keras.optimizers.Adam(learning_rate=0.01), metrics=['mae']) # change the metric to be regression-specific # Fit the recompiled model model_3.fit(X_reg_train, y_reg_train, epochs=100) model_3.predict(X_reg_test)

Solution 1

Change the axis dimension in expand_dims to 1 and slice your data like this, since it is 2D:

import tensorflow as tf
import numpy as np

tf.random.set_seed(42)

# Create some regression data
X_regression = np.expand_dims(np.arange(0, 1000, 5), axis=1)
y_regression = np.expand_dims(np.arange(100, 1100, 5), axis=1)

# Split it into training and test sets
X_reg_train = X_regression[:150, :]
X_reg_test = X_regression[150:, :]

y_reg_train = y_regression[:150, :]
y_reg_test = y_regression[150:, :]

tf.random.set_seed(42)

# Recreate the model
model_3 = tf.keras.Sequential([
  tf.keras.layers.Dense(100),
  tf.keras.layers.Dense(10),
  tf.keras.layers.Dense(1)
])

# Change the loss and metrics of our compiled model
model_3.compile(loss=tf.keras.losses.mae, # change the loss function to be regression-specific
                optimizer=tf.keras.optimizers.Adam(learning_rate=0.01),
                metrics=['mae']) # change the metric to be regression-specific

# Fit the recompiled model
model_3.fit(X_reg_train, y_reg_train, epochs=100)

model_3.predict(X_reg_test)

Original Author AloneTogether Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment