model.evaluate() in TensorFlow Last Updated : 10 Feb, 2025 Comments Improve Suggest changes Like Article Like Report The model.evaluate() function in TensorFlow is used to evaluate a trained model on a given dataset. It returns the loss value and any additional metrics specified during model compilation. model.evaluate() function allows us to assess how well the trained model generalizes to unseen data.Syntax of model.evaluate()model.evaluate( x=None, y=None, batch_size=None, verbose=1, sample_weight=None, steps=None, callbacks=None, return_dict=False, use_multiprocessing=False)Parameters: x: Input data. Can be a NumPy array, TensorFlow dataset, or generator.y: Target data (labels corresponding to x).batch_size: Number of samples per batch. If None, the batch size defaults to 32.verbose: Controls logging output (0 = silent, 1 = progress bar, 2 = one line per epoch).sample_weight: Optional weights for samples.steps: Number of batches to evaluate (only applicable if x is a generator).callbacks: List of callback functions to be applied during evaluation.return_dict: If True, returns a dictionary of metric values.use_multiprocessing: If True, uses multiple CPU processes for data loading.The function returns:If return_dict=False: A scalar loss value or a list of values (loss + additional metrics).If return_dict=True: A dictionary containing loss and metrics.Using model.evaluate() to evaluate Deep Learning Model Python import tensorflow as tf import numpy as np from tensorflow import keras (x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data() x_train, x_test = x_train / 255.0, x_test / 255.0 model = keras.Sequential([ keras.layers.Flatten(input_shape=(28, 28)), keras.layers.Dense(128, activation='relu'), keras.layers.Dense(10, activation='softmax') ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) model.fit(x_train, y_train, epochs=5, batch_size=32) loss, accuracy = model.evaluate(x_test, y_test, batch_size=32) print(f"Test Loss: {loss:.4f}") print(f"Test Accuracy: {accuracy:.4f}") Output: Test Loss: 0.0775Test Accuracy: 0.9773model.evaluate() function in TensorFlow provides a simple and effective way to assess model performance on test data. By understanding its parameters and return values, you can efficiently measure your model's accuracy, loss, and other metrics. Comment More infoAdvertise with us Next Article Using the SavedModel format in Tensorflow S sanjulika_sharma Follow Improve Article Tags : Deep Learning AI-ML-DS Tensorflow AI-ML-DS With Python Similar Reads tf.Module in Tensorflow Example TensorFlow is an open-source library for data science. It provides various tools and APIs. One of the core components of TensorFlow is tf.Module, a class that represents a reusable piece of computation. A tf.Module is an object that encapsulates a set of variables and functions that operate on them. 6 min read Export a SavedModel in Tensorflow In TensorFlow, a SavedModel is basically a serialized format for storing a complete TensorFlow program. The tf.saved_model.save() function in TensorFlow can be used to export a SavedModel. A trained model and its related variables are saved to disc in the SavedModel format by this function. It inclu 4 min read tf.keras.models.load_model in Tensorflow TensorFlow is an open-source machine-learning library developed by Google. In this article, we are going to explore the how can we load a model in TensorFlow. tf.keras.models.load_model tf.keras.models.load_model function is used to load saved models from storage for further use. It allows users to 3 min read Using the SavedModel format in Tensorflow TensorFlow is a popular deep-learning framework that provides a variety of tools to help users build, train, and deploy machine-learning models. One of the most important aspects of deploying a machine learning model is saving and exporting it to a format that can be easily used by other programs an 4 min read Python - tensorflow.math.equal() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. equal() is used to perform element by equality comparison.  It performs argument broadcasting before applying the comparison. Syntax: tensorflow.math.equal( x, y, name) 2 min read Debugging in TensorFlow This article discusses the basics of TensorFlow and also dives deep into debugging in TensorFlow in Python. We will see debugging techniques, and debugging tools, and also get to know about common TensorFlow errors. TensorFlow TensorFlow is an open-source library that helps develop, deploy, and trai 8 min read Like