Spaces:
Runtime error
Runtime error
darshanjani
commited on
Commit
β’
524f5ea
1
Parent(s):
3a0062c
gradio webapp
Browse files
app.py
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
|
4 |
+
from Utilities.model import YOLOv3
|
5 |
+
from Utilities import config
|
6 |
+
from Utilities.transforms import resize_transforms
|
7 |
+
from Utilities.runtime_utils import generate_gradcam_output, plot_bboxes
|
8 |
+
|
9 |
+
model = YOLOv3.load_from_checkpoint(
|
10 |
+
config.MODEL_CHECKPOINT_PATH,
|
11 |
+
map_location=torch.device('cpu')
|
12 |
+
)
|
13 |
+
|
14 |
+
examples = [
|
15 |
+
[config.EXAMPLE_IMAGE_PATH + "cat.jpeg", 1],
|
16 |
+
[config.EXAMPLE_IMG_PATH + "horse.jpg", 1],
|
17 |
+
[config.EXAMPLE_IMG_PATH + "000018.jpg", 2],
|
18 |
+
[config.EXAMPLE_IMG_PATH + "bird.webp", 2],
|
19 |
+
[config.EXAMPLE_IMG_PATH + "000022.jpg", 2],
|
20 |
+
[config.EXAMPLE_IMG_PATH + "airplane.png", 0],
|
21 |
+
[config.EXAMPLE_IMG_PATH + "shipp.jpg", 0],
|
22 |
+
[config.EXAMPLE_IMG_PATH + "car.jpg", 1],
|
23 |
+
[config.EXAMPLE_IMG_PATH + "000007.jpg", 1],
|
24 |
+
[config.EXAMPLE_IMG_PATH + "000013.jpg", 2],
|
25 |
+
[config.EXAMPLE_IMG_PATH + "000012.jpg", 2],
|
26 |
+
[config.EXAMPLE_IMG_PATH + "000006.jpg", 1],
|
27 |
+
[config.EXAMPLE_IMG_PATH + "000004.jpg", 1],
|
28 |
+
[config.EXAMPLE_IMG_PATH + "000014.jpg", 0],
|
29 |
+
]
|
30 |
+
|
31 |
+
title = "Building YOLOv3 from Scratch using PyTorch Lightning"
|
32 |
+
description = """Unveiling the intricacies of YOLOv3 through PyTorch Lightning β‘οΈπ΅οΈββοΈ
|
33 |
+
---
|
34 |
+
In the rapidly evolving landscape of machine learning, expertise in building sophisticated models from scratch is invaluable. Presenting the YOLOv3 Object Detection System crafted meticulously using the cutting-edge PyTorch Lightning framework.
|
35 |
+
|
36 |
+
π Key Highlights:
|
37 |
+
---
|
38 |
+
1. **Deep Dive into YOLOv3**: Ground-up development of the YOLOv3 model, showcasing proficiency in intricate model architectures and in-depth understanding of computer vision principles.
|
39 |
+
|
40 |
+
2. **PyTorch Lightning Advantage**: Leverage the robustness and efficiency of PyTorch Lightning, reflecting modern best practices and optimizing training workflows. This demonstrates strong proficiency in state-of-the-art deep learning frameworks.
|
41 |
+
|
42 |
+
3. **High Precision with GradCAM**: Integrated GradCAM (Gradient-weighted Class Activation Mapping), offering insights into model's decision-making layers, indicative of a holistic approach to model transparency and interpretability.
|
43 |
+
|
44 |
+
4. **Flexibility in Object Detection**: Multi-scale outputs (13x13, 26x26, 52x52) for versatile object detection, displaying an understanding of varying image resolutions and their impact on detection tasks.
|
45 |
+
|
46 |
+
πΈ Workflow:
|
47 |
+
---
|
48 |
+
- Upload an image for object detection.
|
49 |
+
- Choose an appropriate output stream size.
|
50 |
+
- Experience real-time object identification, enriched with GradCAM visualizations, highlighting the model's decision-making areas.
|
51 |
+
|
52 |
+
β
Recognizable Pascal VOC Classes:
|
53 |
+
---
|
54 |
+
aeroplane, bicycle, bird, boat, bottle, bus, car, cat, chair, cow, diningtable, dog, horse, motorbike, person, pottedplant, sheep, sofa, train, tvmonitor
|
55 |
+
|
56 |
+
π Dive Deeper:
|
57 |
+
---
|
58 |
+
Explore the "Examples" section for comprehensive visual insights. Understand the YOLOv3's capabilities and analyze GradCAM results for varied output streams. This emphasizes a keen interest in not just creating, but also in understanding and optimizing machine learning models.
|
59 |
+
|
60 |
+
Venture into a hands-on demonstration of skills, innovation, and expertise in computer vision and deep learning. Dive into this YOLOv3 Object Detection System, exemplifying the forefront of machine learning prowess.
|
61 |
+
"""
|
62 |
+
|
63 |
+
def generate_gradio_output(input_img, gradcam_output_stream=0):
|
64 |
+
input_img = resize_transforms(image=input_img)["image"]
|
65 |
+
|
66 |
+
fig, processed_img = plot_bboxes(
|
67 |
+
input_img=input_img,
|
68 |
+
model=model,
|
69 |
+
thresh=0.6,
|
70 |
+
iou_thresh=0.5,
|
71 |
+
anchors=model.scaled_anchors,
|
72 |
+
)
|
73 |
+
|
74 |
+
visualization = generate_gradcam_output(
|
75 |
+
org_img=input_img,
|
76 |
+
model=model,
|
77 |
+
input_img=processed_img,
|
78 |
+
gradcam_output_stream=gradcam_output_stream,
|
79 |
+
)
|
80 |
+
return fig, visualization
|
81 |
+
|
82 |
+
gr.Interface(
|
83 |
+
fn=generate_gradio_output,
|
84 |
+
inputs=[
|
85 |
+
gr.Image(label="Input Image"),
|
86 |
+
gr.Slider(0, 2, step=1, label="GradCAM Output Stream (13, 26, 52)")
|
87 |
+
],
|
88 |
+
outputs=[
|
89 |
+
gr.Plot(
|
90 |
+
visible=True,
|
91 |
+
label="Bounding Box Predictions",
|
92 |
+
),
|
93 |
+
gr.Image(label="GradCAM Visualization").style(width=416, height=416)
|
94 |
+
],
|
95 |
+
examples=examples,
|
96 |
+
title=title,
|
97 |
+
description=description,
|
98 |
+
).launch()
|
99 |
+
|