|
--- |
|
license: apache-2.0 |
|
pipeline_tag: object-detection |
|
--- |
|
# Nepal Vehicle License Plates Detection |
|
|
|
```python |
|
# Example Code: You can test this model on colab |
|
|
|
# Install required libraries |
|
!pip install ultralytics |
|
!pip install PIL |
|
|
|
# Import necessary libraries |
|
from ultralytics import YOLO |
|
import matplotlib.pyplot as plt |
|
from PIL import Image, ImageDraw |
|
from google.colab import files |
|
import requests |
|
|
|
# Step 1: Download the model from Hugging Face |
|
model_url = "https://huggingface.co/krishnamishra8848/Nepal_Vehicle_License_Plates_Detection_Version2/resolve/main/best.pt" |
|
model_path = "best.pt" |
|
|
|
# Download the model |
|
print("Downloading the model...") |
|
response = requests.get(model_url) |
|
with open(model_path, 'wb') as f: |
|
f.write(response.content) |
|
print("Model downloaded!") |
|
|
|
# Step 2: Load the model |
|
model = YOLO(model_path) |
|
|
|
# Step 3: Upload an image |
|
print("Please upload an image to test:") |
|
uploaded = files.upload() |
|
image_path = list(uploaded.keys())[0] |
|
|
|
# Step 4: Run inference |
|
results = model(image_path) |
|
|
|
# Step 5: Open the image and draw bounding boxes |
|
img = Image.open(image_path) |
|
draw = ImageDraw.Draw(img) |
|
|
|
for box in results[0].boxes: |
|
# Extract bounding box coordinates and class information |
|
x_min, y_min, x_max, y_max = box.xyxy[0].tolist() |
|
label = int(box.cls) # Class ID |
|
confidence = float(box.conf) # Confidence score |
|
|
|
# Draw bounding box |
|
draw.rectangle([x_min, y_min, x_max, y_max], outline="red", width=3) |
|
|
|
# Add label and confidence |
|
text = f"Class {label}, {confidence:.2f}" |
|
draw.text((x_min, y_min - 10), text, fill="red") |
|
|
|
# Step 6: Display the image with bounding boxes |
|
plt.figure(figsize=(10, 10)) |
|
plt.imshow(img) |
|
plt.axis('off') |
|
plt.show() |
|
|
|
|