Downloads · 30 days
0
wambugu71/crop_leaf_diseases_vit_onnx
crop_leaf_diseases_vit_onnx is a image classification model from wambugu71. Use it when you need a label for an image. The card lists the license as mit.
This repository contains an ONNX quantized version of the pre-trained ViT model for crop leaf disease classification originally from wambugu71/cropleafdiseasesvit.
Downloads · 30 days
0
Access
Public
Updated Oct 15, 2025
Repo size
22.3 MB
Likes
1
Public
Click a slice to open those files.
.onnx22.3 MB · 100%
From the Hugging Face model README
This repository contains an ONNX quantized version of the pre-trained ViT model for crop leaf disease classification originally from wambugu71/crop_leaf_diseases_vit.
The original model was converted to the ONNX format and then quantized to INT8 for improved efficiency and reduced size, making it suitable for deployment in resource-constrained environments, such as mobile devices.
wambugu71/crop_leaf_diseases_vitThis model can be loaded and used for inference with the ONNX Runtime.
import onnxruntime as ort
import numpy as np
from PIL import Image
from transformers import AutoFeatureExtractor # Assuming feature_extractor is needed for preprocessing
# Load the quantized ONNX model
onnx_model_path = "crop_leaf_diseases_vit.quant.onnx" # or the correct quantized model file name
session = ort.InferenceSession(onnx_model_path)
# Get input and output names
input_name = session.get_inputs()[0].name
output_name = session.get_outputs()[0].name
# Example inference (assuming you have an image and a feature extractor)
# Replace with your actual image loading and preprocessing
image_path = "path/to/your/image.jpg"
image = Image.open(image_path).convert("RGB")
# Load the feature extractor used during conversion
# feature_extractor = AutoFeatureExtractor.from_pretrained("wambugu71/crop_leaf_diseases_vit")
# inputs = feature_extractor(images=image, return_tensors="np")
# pixel_values = inputs["pixel_values"]
# If not using a feature extractor, you might need to preprocess manually
# based on the original model's requirements (e.g., resize, normalize)
# For example, if the model expects 3x224x224 float32 input:
# resized_image = image.resize((224, 224))
# input_data = np.array(resized_image, dtype=np.float32).transpose(2, 0, 1) # HWC to CHW
# input_data = np.expand_dims(input_data, axis=0) # Add batch dimension
# pixel_values = input_data
# Run inference
outputs = session.run([output_name], {input_name: pixel_values})
logits = outputs[0]
# Post-processing (example for classification)
predicted_class_idx = np.argmax(logits, axis=1)[0]
print("Predicted class index:", predicted_class_idx)
# You would then map the predicted_class_idx to the actual class label
# using the label mapping from the original model if available.
This model was quantized using dynamic quantization with ONNX Runtime.
crop_leaf_diseases_vit.onnx: The original ONNX model (before quantization).crop_leaf_diseases_vit.quant.onnx: The quantized ONNX model (INT8) find colab link.