Update README.md
Browse files
README.md
CHANGED
@@ -1,4 +1,57 @@
|
|
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 |
+
# Face Mask Detection Model
|
6 |
+
|
7 |
+
```python
|
8 |
+
# Example Code: You can test this model on colab or anywhere u want
|
9 |
+
|
10 |
+
# Install necessary libraries
|
11 |
+
!pip install ultralytics huggingface_hub
|
12 |
+
|
13 |
+
# Download the model from Hugging Face
|
14 |
+
from huggingface_hub import hf_hub_download
|
15 |
+
from ultralytics import YOLO
|
16 |
+
from google.colab import files
|
17 |
+
from IPython.display import Image, display
|
18 |
+
import cv2
|
19 |
+
import matplotlib.pyplot as plt
|
20 |
+
|
21 |
+
# Define repository and file path
|
22 |
+
repo_id = "krishnamishra8848/Face_Mask_Detection"
|
23 |
+
filename = "best.pt" # File name in your Hugging Face repo
|
24 |
+
|
25 |
+
# Download the model file
|
26 |
+
model_path = hf_hub_download(repo_id=repo_id, filename=filename)
|
27 |
+
print(f"Model downloaded to: {model_path}")
|
28 |
+
|
29 |
+
# Load the YOLOv8 model
|
30 |
+
model = YOLO(model_path)
|
31 |
+
|
32 |
+
# Upload an image for testing
|
33 |
+
print("Upload an image to test:")
|
34 |
+
uploaded = files.upload()
|
35 |
+
image_path = list(uploaded.keys())[0]
|
36 |
+
|
37 |
+
# Display the uploaded image
|
38 |
+
print("Uploaded Image:")
|
39 |
+
display(Image(filename=image_path))
|
40 |
+
|
41 |
+
# Run inference on the uploaded image
|
42 |
+
print("Running inference...")
|
43 |
+
results = model.predict(source=image_path, conf=0.5)
|
44 |
+
|
45 |
+
# Save and visualize the results
|
46 |
+
print("Saving and displaying predictions...")
|
47 |
+
for result in results:
|
48 |
+
annotated_image = result.plot() # Annotate the image with bounding boxes and labels
|
49 |
+
# Convert annotated image to RGB for display with matplotlib
|
50 |
+
annotated_image_rgb = cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)
|
51 |
+
plt.figure(figsize=(10, 10))
|
52 |
+
plt.imshow(annotated_image_rgb)
|
53 |
+
plt.axis("off")
|
54 |
+
plt.title("Prediction Results")
|
55 |
+
plt.show()
|
56 |
+
|
57 |
+
|