Downloads · 30 days
6
22% of all-time downloads
CalvinYu727/invoice_cheque_creditcard_model
invoice_cheque_creditcard_model is a image classification model from CalvinYu727. Use it when you need a label for an image. It is set up for keras. The card lists the license as mit.
A fine-tuned model for classifying invoices, credit card and bank cheque, trained using MobileNetV3Large using Google Colab.
Downloads · 30 days
6
22% of all-time downloads
All-time downloads
27
Public
Repo size
24.5 MB
Likes
0
Public
Click a slice to open those files.
.keras24.5 MB · 100%
From the Hugging Face model README
A fine-tuned model for classifying invoices, credit card and bank cheque, trained using MobileNetV3_Large using Google Colab.
''' from tensorflow.keras.models import load_model import cv2 from tensorflow.keras.preprocessing.image import img_to_array import tensorflow as tf import numpy as np from google.colab import files, drive import matplotlib.pyplot as plt
IMG_SIZE = 224
CONFIDENCE_THRESHOLD = 0.5
drive.mount('/content/drive')
finetuned_model = load_model('/content/drive/MyDrive/models/finetuned_mobilenetv3large_model_v4.keras')
uploaded = files.upload()
for fn in uploaded.keys(): # Read the image img_path = fn img = cv2.imread(img_path)
# Resize the image (using tf.image.resize)
img = tf.image.resize(img, [IMG_SIZE, IMG_SIZE])
# Convert image to array
img_array = img_to_array(img)
# Normalize pixel values
img_array = img_array / 255.0
# Add a dimension (batch size)
img_array = tf.expand_dims(img_array, 0)
# Perform inference using the finetuned model
prediction = finetuned_model.predict(img_array)
# Get probabilities for all classes
class_probabilities = prediction[0]
# Display results
print(f'{fn}:')
max_prob = np.max(class_probabilities)
if max_prob > CONFIDENCE_THRESHOLD:
for i, prob in enumerate(class_probabilities):
if i == 0:
class_name = 'Bank Cheque'
elif i == 1:
class_name = 'Credit Card'
elif i == 2:
class_name = 'Invoice'
else:
class_name = 'Others'
print(f' {class_name}: ({prob:.4f})')
else:
print('Others')
# Display the image
plt.imshow(img.numpy().astype(np.uint8))
plt.title(fn)
plt.show()