krishnamishra8848 commited on
Commit
ab22240
·
verified ·
1 Parent(s): 28cce3c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +62 -1
README.md CHANGED
@@ -1,4 +1,65 @@
1
  ---
2
  license: apache-2.0
3
  pipeline_tag: object-detection
4
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
  pipeline_tag: object-detection
4
+ ---
5
+ # Nepal Vehicle License Plates Detection
6
+
7
+ ```python
8
+ # Example Code: You can test this model on colab
9
+
10
+ # Install required libraries
11
+ !pip install ultralytics
12
+ !pip install PIL
13
+
14
+ # Import necessary libraries
15
+ from ultralytics import YOLO
16
+ import matplotlib.pyplot as plt
17
+ from PIL import Image, ImageDraw
18
+ from google.colab import files
19
+ import requests
20
+
21
+ # Step 1: Download the model from Hugging Face
22
+ model_url = "https://huggingface.co/krishnamishra8848/Nepal_Vehicle_License_Plates_Detection_Version2/resolve/main/best.pt"
23
+ model_path = "best.pt"
24
+
25
+ # Download the model
26
+ print("Downloading the model...")
27
+ response = requests.get(model_url)
28
+ with open(model_path, 'wb') as f:
29
+ f.write(response.content)
30
+ print("Model downloaded!")
31
+
32
+ # Step 2: Load the model
33
+ model = YOLO(model_path)
34
+
35
+ # Step 3: Upload an image
36
+ print("Please upload an image to test:")
37
+ uploaded = files.upload()
38
+ image_path = list(uploaded.keys())[0]
39
+
40
+ # Step 4: Run inference
41
+ results = model(image_path)
42
+
43
+ # Step 5: Open the image and draw bounding boxes
44
+ img = Image.open(image_path)
45
+ draw = ImageDraw.Draw(img)
46
+
47
+ for box in results[0].boxes:
48
+ # Extract bounding box coordinates and class information
49
+ x_min, y_min, x_max, y_max = box.xyxy[0].tolist()
50
+ label = int(box.cls) # Class ID
51
+ confidence = float(box.conf) # Confidence score
52
+
53
+ # Draw bounding box
54
+ draw.rectangle([x_min, y_min, x_max, y_max], outline="red", width=3)
55
+
56
+ # Add label and confidence
57
+ text = f"Class {label}, {confidence:.2f}"
58
+ draw.text((x_min, y_min - 10), text, fill="red")
59
+
60
+ # Step 6: Display the image with bounding boxes
61
+ plt.figure(figsize=(10, 10))
62
+ plt.imshow(img)
63
+ plt.axis('off')
64
+ plt.show()
65
+