Inference.zip Folder structure:
requirements.txt
Trained Model file
inference.py
Other files and folders used
Inference.py file format:
Import Statements
Onetime executable operations
{Ex: Loading the Model, label encoding etc.}
def predict(Input arguments as per the use-case)
{
Data Preprocessing
Inference
Return output based on the use-case
}
*Do not change the naming convention for the entities marked inblueimport os, sys
import cv2
import numpy as np
import tensorflow as tf
#load the model and any other custom defined functions/variables
detection_model = tf.saved_model.load('saved_model')
def predict(img, output_directory): #mandatory function: First arg: img path to read from, Second arg: Dir to save the output image
img = cv2.imread(img)
#code for predictions
#........
#.........
output_file = output_directory + "image.jpg"
cv2.imwrite(output_file,image_np_with_detections)
return output_file
tensorflow==2.4.1
numpy
opencv-python-headless