Untitled
unknown
plain_text
2 years ago
1.2 kB
5
Indexable
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.inception_v3 import preprocess_input
import numpy as np
model = load_model('/Analytics/venv/Jup/CAPE_Case_Management_PDF_Invoicing/Fine_tuned_invoice_model_v2_4dec.h5')
## Preprocessing the image as per requirement
def preprocess_image(img_path):
img = image.load_img(img_path, target_size=(299, 299))
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array = preprocess_input(img_array)
return img_array
## Making predictions
img_path = '/Analytics/venv/Jup/CAPE_Case_Management_PDF_Invoicing/Data/images/Test_dataset_images/non_invoice/Non_Invoice PDf.pdf_page_206.png'
preprocessed_img = preprocess_image(img_path)
# Make a prediction
prediction = model.predict(preprocessed_img)
# If it's binary classification, you can use a threshold to determine the class
threshold = 0.5 # Adjust as needed
predicted_class = 1 if prediction > threshold else 0
# Print the prediction
print(f"Prediction: {predicted_class} (1: Invoice, 0: Non-Invoice)")
Editor is loading...
Leave a Comment