Face Mask Detection Model
!pip install ultralytics huggingface_hub
from huggingface_hub import hf_hub_download
from ultralytics import YOLO
from google.colab import files
from IPython.display import Image, display
import cv2
import matplotlib.pyplot as plt
repo_id = "krishnamishra8848/Face_Mask_Detection"
filename = "best.pt"
model_path = hf_hub_download(repo_id=repo_id, filename=filename)
print(f"Model downloaded to: {model_path}")
model = YOLO(model_path)
print("Upload an image to test:")
uploaded = files.upload()
image_path = list(uploaded.keys())[0]
print("Uploaded Image:")
display(Image(filename=image_path))
print("Running inference...")
results = model.predict(source=image_path, conf=0.5)
print("Saving and displaying predictions...")
for result in results:
annotated_image = result.plot()
annotated_image_rgb = cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)
plt.figure(figsize=(10, 10))
plt.imshow(annotated_image_rgb)
plt.axis("off")
plt.title("Prediction Results")
plt.show()