Views
No views yet
1# Example Code: Test this code on colab
2# Step 1: Install required libraries
3!pip install ultralytics
4!pip install huggingface_hub
5
6# Step 2: Download the model from Hugging Face
7from huggingface_hub import hf_hub_download
8
9# Replace "krishnamishra8848/Nepal_Vehicle_License_Plates_Detection_Version3" with your model's Hugging Face repo ID
10repo_id = "krishnamishra8848/Nepal_Vehicle_License_Plates_Detection_Version3"
11model_path = hf_hub_download(repo_id=repo_id, filename="best.pt")
12
13print(f"Model downloaded and saved at: {model_path}")
14
15# Step 3: Load the model
16from ultralytics import YOLO
17model = YOLO(model_path) # Load the model
18
19# Step 4: Upload an image for inference
20from google.colab import files
21import matplotlib.pyplot as plt
22import cv2
23
24# Allow user to upload an image
25uploaded = files.upload()
26
27# Get the uploaded file's path
28image_path = list(uploaded.keys())[0]
29
30# Step 5: Perform inference
31results = model.predict(source=image_path)
32
33# Step 6: Display the results
34# Extract the annotated image
35annotated_image = results[0].plot()
36
37# Display the image with bounding boxes
38plt.figure(figsize=(10, 10))
39plt.imshow(cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB))
40plt.axis("off")
41plt.show()