Untitled

 avatar
unknown
plain_text
2 years ago
1.2 kB
4
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_dec5.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/invoice/Email_28112023053610_ag_13049100_1007.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 = 0 if prediction < threshold else 1

# Print the prediction
print(f"Prediction: {predicted_class} (0: Invoice, 1: Non-Invoice)")

Editor is loading...
Leave a Comment