Spaces:
Sleeping
Sleeping
Commit
·
cbdd536
1
Parent(s):
31cffc8
Added checkbox for EigenCAM
Browse files
app.py
CHANGED
@@ -64,7 +64,7 @@ def display_false_detection_data(false_detection_data, number_of_samples):
|
|
64 |
|
65 |
return fig
|
66 |
|
67 |
-
def inference(input_img, conf_thres, iou_thres, is_false_detection_images=True, num_false_detection_images=10):
|
68 |
stride, names, pt = model.stride, model.names, model.pt
|
69 |
|
70 |
# Load image
|
@@ -104,35 +104,39 @@ def inference(input_img, conf_thres, iou_thres, is_false_detection_images=True,
|
|
104 |
else:
|
105 |
misclassified_images = None
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
112 |
|
113 |
-
|
114 |
-
|
115 |
-
|
|
|
|
|
116 |
|
117 |
return img0, cam_image, misclassified_images
|
118 |
|
119 |
title = "YOLOv9 model to detect shirt/tshirt"
|
120 |
description = "A simple Gradio interface to infer on YOLOv9 model and detect tshirt in image"
|
121 |
-
examples = [["image_1.jpg", 0.25, 0.45, True, 10],
|
122 |
-
["image_2.jpg", 0.25, 0.45, True, 10],
|
123 |
-
["image_3.jpg", 0.25, 0.45, True, 10],
|
124 |
-
["image_4.jpg", 0.25, 0.45, True, 10],
|
125 |
-
["image_5.jpg", 0.25, 0.45, True, 10],
|
126 |
-
["image_6.jpg", 0.25, 0.45, True, 10],
|
127 |
-
["image_7.jpg", 0.25, 0.45, True, 10],
|
128 |
-
["image_8.jpg", 0.25, 0.45, True, 10],
|
129 |
-
["image_9.jpg", 0.25, 0.45, True, 10],
|
130 |
-
["image_10.jpg", 0.25, 0.45, True, 10]]
|
131 |
|
132 |
demo = gr.Interface(inference,
|
133 |
inputs = [gr.Image(width=320, height=320, label="Input Image"),
|
134 |
gr.Slider(0, 1, 0.25, label="Confidence Threshold"),
|
135 |
gr.Slider(0, 1, 0.45, label="IoU Thresold"),
|
|
|
136 |
gr.Checkbox(label="Show False Detection"),
|
137 |
gr.Slider(5, 35, value=10, step=5, label="Number of False Detection")],
|
138 |
outputs= [gr.Image(width=640, height=640, label="Output"),
|
|
|
64 |
|
65 |
return fig
|
66 |
|
67 |
+
def inference(input_img, conf_thres, iou_thres, is_eigen_cam=True, is_false_detection_images=True, num_false_detection_images=10):
|
68 |
stride, names, pt = model.stride, model.names, model.pt
|
69 |
|
70 |
# Load image
|
|
|
104 |
else:
|
105 |
misclassified_images = None
|
106 |
|
107 |
+
if is_eigen_cam:
|
108 |
+
img_GC = cv2.resize(input_img, (640, 640))
|
109 |
+
rgb_img = img_GC.copy()
|
110 |
+
img_GC = np.float32(img_GC) / 255
|
111 |
+
transform = transforms.ToTensor()
|
112 |
+
tensor = transform(img_GC).unsqueeze(0)
|
113 |
|
114 |
+
cam = EigenCAM(model, target_layers)
|
115 |
+
grayscale_cam = cam(tensor)[0, :, :]
|
116 |
+
cam_image = show_cam_on_image(img_GC, grayscale_cam, use_rgb=True)
|
117 |
+
else:
|
118 |
+
cam_image = None
|
119 |
|
120 |
return img0, cam_image, misclassified_images
|
121 |
|
122 |
title = "YOLOv9 model to detect shirt/tshirt"
|
123 |
description = "A simple Gradio interface to infer on YOLOv9 model and detect tshirt in image"
|
124 |
+
examples = [["image_1.jpg", 0.25, 0.45, True, True, 10],
|
125 |
+
["image_2.jpg", 0.25, 0.45, True, True, 10],
|
126 |
+
["image_3.jpg", 0.25, 0.45, True, True, 10],
|
127 |
+
["image_4.jpg", 0.25, 0.45, True, True, 10],
|
128 |
+
["image_5.jpg", 0.25, 0.45, True, True, 10],
|
129 |
+
["image_6.jpg", 0.25, 0.45, True, True, 10],
|
130 |
+
["image_7.jpg", 0.25, 0.45, True, True, 10],
|
131 |
+
["image_8.jpg", 0.25, 0.45, True, True, 10],
|
132 |
+
["image_9.jpg", 0.25, 0.45, True, True, 10],
|
133 |
+
["image_10.jpg", 0.25, 0.45, True, True, 10]]
|
134 |
|
135 |
demo = gr.Interface(inference,
|
136 |
inputs = [gr.Image(width=320, height=320, label="Input Image"),
|
137 |
gr.Slider(0, 1, 0.25, label="Confidence Threshold"),
|
138 |
gr.Slider(0, 1, 0.45, label="IoU Thresold"),
|
139 |
+
gr.Checkbox(label="Show Eigen CAM"),
|
140 |
gr.Checkbox(label="Show False Detection"),
|
141 |
gr.Slider(5, 35, value=10, step=5, label="Number of False Detection")],
|
142 |
outputs= [gr.Image(width=640, height=640, label="Output"),
|