owaiskha9654
commited on
Commit
Β·
9984c6c
1
Parent(s):
be1ba3d
Update app.py
Browse files
app.py
CHANGED
@@ -11,20 +11,46 @@ yolov7_custom_weights = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
|
|
11 |
|
12 |
model = torch.hub.load('Owaiskhan9654/yolov7-1:main',model='custom', path_or_model=yolov7_custom_weights, force_reload=True) # Github repository https://github.com/Owaiskhan9654
|
13 |
|
14 |
-
def object_detection(
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
results.render()
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
title = "Yolov7 Custom"
|
20 |
|
21 |
-
image = gr.inputs.Image(shape=(640, 640), image_mode="RGB", source="upload", label="Upload Image", optional=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
outputs = gr.outputs.Image(type="pil", label="Output Image")
|
|
|
|
|
23 |
|
24 |
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"
|
25 |
|
26 |
Footer = (
|
27 |
-
"<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>"
|
28 |
|
29 |
"<center> Model Trained Kaggle Kernel <a href=\"https://www.kaggle.com/code/owaiskhan9654/shelf-object-detection-yolov7-pytorch/notebook\">Link</a> <br></center>"
|
30 |
|
@@ -34,15 +60,17 @@ Footer = (
|
|
34 |
|
35 |
examples1=[["Image1.jpg"],["Image2.jpg"],["Image3.jpg"],["Image4.jpg"],["Image5.jpg"],["Image6.jpg"]]
|
36 |
|
37 |
-
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"
|
38 |
css = ".output-image, .input-image {height: 50rem !important; width: 100% !important;}"
|
39 |
css = ".image-preview {height: auto !important;}"
|
40 |
|
41 |
gr.Interface(
|
42 |
fn=object_detection,
|
43 |
-
inputs=
|
44 |
-
outputs=outputs,
|
45 |
title=Top_Title,
|
46 |
description=Custom_description,
|
47 |
article=Footer,
|
|
|
|
|
48 |
examples=examples1).launch()
|
|
|
11 |
|
12 |
model = torch.hub.load('Owaiskhan9654/yolov7-1:main',model='custom', path_or_model=yolov7_custom_weights, force_reload=True) # Github repository https://github.com/Owaiskhan9654
|
13 |
|
14 |
+
def object_detection(
|
15 |
+
image: gr.inputs.Image = None,
|
16 |
+
model_path: gr.inputs.Dropdown = None,
|
17 |
+
image_size: gr.inputs.Slider = 640,
|
18 |
+
conf_threshold: gr.inputs.Slider = 0.25,
|
19 |
+
iou_threshold: gr.inputs.Slider = 0.45,):
|
20 |
+
|
21 |
+
|
22 |
+
results = model(image)
|
23 |
+
|
24 |
results.render()
|
25 |
+
count_dict = results.pandas().xyxy[0]['name'].value_counts().to_dict()
|
26 |
+
|
27 |
+
|
28 |
+
if len(count_dict)>0:
|
29 |
+
return Image.fromarray(results.imgs[0]),str(count_dict)
|
30 |
+
else:
|
31 |
+
return Image.fromarray(results.imgs[0]),'No object Found. Add more Custom classes in the training set'
|
32 |
+
|
33 |
|
34 |
title = "Yolov7 Custom"
|
35 |
|
36 |
+
# image = gr.inputs.Image(shape=(640, 640), image_mode="RGB", source="upload", label="Upload Image", optional=False)
|
37 |
+
|
38 |
+
inputs = [
|
39 |
+
gr.inputs.Image(shape=(640, 640), image_mode="RGB", source="upload", label="Upload Image", optional=False),
|
40 |
+
gr.inputs.Dropdown(["best.pt",],
|
41 |
+
default="best.pt", label="Model"),
|
42 |
+
gr.inputs.Slider(minimum=320, maximum=1280, default=640, step=32, label="Image Size"),
|
43 |
+
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.25, step=0.05, label="Confidence Threshold"),
|
44 |
+
gr.inputs.Slider(minimum=0.0, maximum=1.0, default=0.45, step=0.05, label="IOU Threshold"),
|
45 |
+
]
|
46 |
outputs = gr.outputs.Image(type="pil", label="Output Image")
|
47 |
+
outputs_cls = gr.Label(label= "Categories Detected Proportion Statistics" )
|
48 |
+
|
49 |
|
50 |
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"
|
51 |
|
52 |
Footer = (
|
53 |
+
"<br><br><br><br><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>"
|
54 |
|
55 |
"<center> Model Trained Kaggle Kernel <a href=\"https://www.kaggle.com/code/owaiskhan9654/shelf-object-detection-yolov7-pytorch/notebook\">Link</a> <br></center>"
|
56 |
|
|
|
60 |
|
61 |
examples1=[["Image1.jpg"],["Image2.jpg"],["Image3.jpg"],["Image4.jpg"],["Image5.jpg"],["Image6.jpg"]]
|
62 |
|
63 |
+
Top_Title="<br><br><br><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"
|
64 |
css = ".output-image, .input-image {height: 50rem !important; width: 100% !important;}"
|
65 |
css = ".image-preview {height: auto !important;}"
|
66 |
|
67 |
gr.Interface(
|
68 |
fn=object_detection,
|
69 |
+
inputs=inputs,
|
70 |
+
outputs=[outputs,outputs_cls],
|
71 |
title=Top_Title,
|
72 |
description=Custom_description,
|
73 |
article=Footer,
|
74 |
+
cache= True,
|
75 |
+
allow_flagging=False,
|
76 |
examples=examples1).launch()
|