metadata
license: mit
language:
- en
metrics:
- accuracy
base_model:
- timm/mobilenetv3_large_100.ra_in1k
pipeline_tag: image-classification
Model Card for Model ID
A fine-tuned model for classifying invoices, credit card and bank cheque, trained using MobileNetV3_Large using Google Colab.
Model Description
- Developed by: Calvin
- Model type: Image Classification
- License: MIT
- Finetuned from model: timm/mobilenetv3_large_100.ra_in1k
''' 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
Define image size
IMG_SIZE = 224
Set confidence threshold
CONFIDENCE_THRESHOLD = 0.5
drive.mount('/content/drive')
Load the finetuned model
finetuned_model = load_model('/content/drive/MyDrive/models/finetuned_mobilenetv3large_model_v4.keras')
Upload image using google.colab.files
uploaded = files.upload()
Process the uploaded image
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()