-
Notifications
You must be signed in to change notification settings - Fork 12
/
svd_test.py
41 lines (35 loc) · 998 Bytes
/
svd_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
from zipfile import ZipFile
import cv2
import datature
import matplotlib.pyplot as plt
import numpy as np
import wget
from ultralytics import YOLO
from yolov8_cam.eigen_cam import EigenCAM
from yolov8_cam.utils.image import show_cam_on_image
model = YOLO("yolov8m.pt")
img = cv2.imread('images/bird-dog-cat.jpg')
img = cv2.resize(img, (320, 320))
rgb_img = img.copy()
img = np.float32(img) / 255
#plt.imshow(cv2.cvtColor(img, cv2.COLOR_RGB2BGR))
#plt.show()
target_layers = [model.model.model[-3]]
cam = EigenCAM(model, target_layers,task='od')
grayscale_cam = cam(
rgb_img,
eigen_smooth=True,
principal_comp=[0],
)[0, :, :]
#cam_image = show_cam_on_image(img, grayscale_cam, use_rgb=True)
cam = EigenCAM(model, target_layers,task='od')
grayscale_cam = cam(
rgb_img,
eigen_smooth=True,
principal_comp=[1],
)
print("grayscale_cam", grayscale_cam.shape)
cam_image = show_cam_on_image(img, grayscale_cam[0,:,:,0], use_rgb=True)
plt.imshow(cam_image)
plt.show()