|
import torch |
|
import gradio as gr |
|
from huggingface_hub import hf_hub_download |
|
from PIL import Image |
|
|
|
REPO_ID = "thoucentric/Shelf_Objects_Detection_Yolov7_Pytorch" |
|
FILENAME = "best.pt" |
|
|
|
|
|
yolov7_custom_weights = hf_hub_download(repo_id=REPO_ID, filename=FILENAME) |
|
|
|
model = torch.hub.load('',model='custom', path_or_model=yolov7_custom_weights, force_reload=True) |
|
|
|
def object_detection(im, size=640): |
|
results = model(im) |
|
results.render() |
|
return Image.fromarray(results.imgs[0]) |
|
|
|
title = "Yolov7 Custom" |
|
|
|
image = gr.inputs.Image(shape=(640, 640), image_mode="RGB", source="upload", label="Upload Image", optional=False) |
|
outputs = gr.outputs.Image(type="pil", label="Output Image") |
|
|
|
Custom_description="<center>Custom Training Performed on Kaggle <a href='https://www.kaggle.com/code/owaiskhan9654/shelf-object-detection-yolov7-pytorch/notebook' style='text-decoration: underline' target='_blank'>Link</a> </center><br> <center>Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors </center> <br> on around 140 general items in Stores" |
|
|
|
Footer = ( |
|
"<center>Model Trained by: Owais Ahmad Data Scientist at <b> Thoucentric </b> <a href=\"https://www.linkedin.com/in/owaiskhan9654/\">Visit Profile</a> <br></center>" |
|
|
|
"<center> Model Trained Kaggle Kernel <a href=\"https://www.kaggle.com/code/owaiskhan9654/shelf-object-detection-yolov7-pytorch/notebook\">Link</a> <br></center>" |
|
|
|
|
|
"<center> HuggingFace🤗 Model Deployed Repository <a href=\"https://huggingface.co/thoucentric/Shelf_Objects_Detection_Yolov7_Pytorch\">Link</a> <br></center>" |
|
) |
|
|
|
examples1=[["Image1.jpg"],["Image2.jpg"],["Image3.jpg"],["Image4.jpg"],["Image5.jpg"],["Image6.jpg"]] |
|
|
|
Top_Title="<center>Yolov7 🚀 Custom Trained by <a href='https://www.linkedin.com/in/owaiskhan9654/' style='text-decoration: underline' target='_blank'>Owais Ahmad </center></a> on around 140 general items in Stores" |
|
css = ".output-image, .input-image {height: 50rem !important; width: 100% !important;}" |
|
css = ".image-preview {height: auto !important;}" |
|
|
|
gr.Interface( |
|
fn=object_detection, |
|
inputs=image, |
|
outputs=outputs, |
|
title=Top_Title, |
|
description=Custom_description, |
|
article=Footer, |
|
examples=examples1).launch() |