RashiAgarwal
commited on
Commit
·
7b271ac
1
Parent(s):
f58c0a4
Update display.py
Browse files- display.py +11 -1
display.py
CHANGED
@@ -5,6 +5,8 @@ from utils import *
|
|
5 |
import random
|
6 |
from albumentations.pytorch import ToTensorV2
|
7 |
from yolov3 import YOLOV3_PL
|
|
|
|
|
8 |
|
9 |
def inference(image: np.ndarray, iou_thresh: float = 0.75, thresh: float = 0.75, transparency: float = 0.5):
|
10 |
model = YOLOV3_PL()
|
@@ -40,7 +42,15 @@ def inference(image: np.ndarray, iou_thresh: float = 0.75, thresh: float = 0.75,
|
|
40 |
bboxes[0], iou_threshold=iou_thresh, threshold=thresh, box_format="midpoint",
|
41 |
)
|
42 |
plot_img = draw_predictions(image, nms_boxes, class_labels=config.PASCAL_CLASSES)
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
|
46 |
|
|
|
5 |
import random
|
6 |
from albumentations.pytorch import ToTensorV2
|
7 |
from yolov3 import YOLOV3_PL
|
8 |
+
from pytorch_grad_cam.utils.image import show_cam_on_image
|
9 |
+
from utils import YoloCAM, cells_to_bboxes, draw_predictions, non_max_suppression
|
10 |
|
11 |
def inference(image: np.ndarray, iou_thresh: float = 0.75, thresh: float = 0.75, transparency: float = 0.5):
|
12 |
model = YOLOV3_PL()
|
|
|
42 |
bboxes[0], iou_threshold=iou_thresh, threshold=thresh, box_format="midpoint",
|
43 |
)
|
44 |
plot_img = draw_predictions(image, nms_boxes, class_labels=config.PASCAL_CLASSES)
|
45 |
+
if not show_cam:
|
46 |
+
return [plot_img]
|
47 |
+
|
48 |
+
grayscale_cam = cam(transformed_image, scaled_anchors)[0, :, :]
|
49 |
+
img = cv2.resize(image, (416, 416))
|
50 |
+
img = np.float32(img) / 255
|
51 |
+
cam_image = show_cam_on_image(img, grayscale_cam, use_rgb=True, image_weight=transparency)
|
52 |
+
return [plot_img, cam_image]
|
53 |
+
|
54 |
|
55 |
|
56 |
|