Face Mask Detection Model

# Example Code: You can test this model on colab or anywhere u want

# Install necessary libraries
!pip install ultralytics huggingface_hub

# Download the model from Hugging Face
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

# Define repository and file path
repo_id = "krishnamishra8848/Face_Mask_Detection"
filename = "best.pt"  # File name in your Hugging Face repo

# Download the model file
model_path = hf_hub_download(repo_id=repo_id, filename=filename)
print(f"Model downloaded to: {model_path}")

# Load the YOLOv8 model
model = YOLO(model_path)

# Upload an image for testing
print("Upload an image to test:")
uploaded = files.upload()
image_path = list(uploaded.keys())[0]

# Display the uploaded image
print("Uploaded Image:")
display(Image(filename=image_path))

# Run inference on the uploaded image
print("Running inference...")
results = model.predict(source=image_path, conf=0.5)

# Save and visualize the results
print("Saving and displaying predictions...")
for result in results:
    annotated_image = result.plot()  # Annotate the image with bounding boxes and labels
    # Convert annotated image to RGB for display with matplotlib
    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()

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Examples
Unable to determine this model's library. Check the docs .

Space using krishnamishra8848/Face_Mask_Detection 1