Understanding Keras (.h5) Model .predict() Method

Hello,

I have a Keras model (model.h5) of a tiny YOLOv3 object-detection model that results in two outputs, conv2d_2 and conv2d_5 (convolution layers), after implementing the following tutorial: GitHub - david8862/keras-YOLOv3-model-set: end-to-end YOLOv4/v3/v2 object detection pipeline, implemented on tf.keras with different technologies

In the evaluation/testing script provided, eval.py, every image is fed into an internal method of the Keras model, .predict(), and two Numpy arrays are returned. I would like to understand how these arrays are produced (what the method takes as input data from the model) and what exactly the data that is in them means.

I tried to go through the source code for the .predict() method (tensorflow/tensorflow/python/keras/engine/training.py at v2.5.0 · tensorflow/tensorflow · GitHub), but I honestly couldn’t really grasp how it works or what it’s doing exactly.

I would appreciate any help I can get with this.

Thanks,
Ahmad

Hi @ahmaedchalhoub,

The .predict() method accepts inputs such as numpy arrays, tensors, or TF.data datasets, and it returns only numpy arrays. For more detailed information, please refer to the documentation and source code.

In the example provided, the image has been preprocessed and converted into numpy arrays or tensors using from common.data_utils import preprocess_image to prepare it for the model where model accepts only arrays or tensors.

Thank You.