Spaces:
Sleeping
Sleeping
Commit
·
37b71af
1
Parent(s):
2910097
Debug: yolov8 target lyr
Browse files
yolov8.py
CHANGED
@@ -5,6 +5,8 @@ from PIL import Image
|
|
5 |
import torch
|
6 |
from torchcam.methods import GradCAM
|
7 |
from torchcam.utils import overlay_mask
|
|
|
|
|
8 |
COLORS = np.random.uniform(0, 255, size=(80, 3))
|
9 |
|
10 |
def parse_detections_yolov8(results):
|
@@ -45,9 +47,8 @@ def xai_yolov8(image):
|
|
45 |
# Convert image to PyTorch tensor for Grad-CAM
|
46 |
image_tensor = torch.tensor(np.array(image)).permute(2, 0, 1).unsqueeze(0).float() / 255.0
|
47 |
image_tensor = image_tensor.to('cpu')
|
48 |
-
|
49 |
-
|
50 |
-
grad_cam = GradCAM(model.model, target_layer='backbone') # You can change the target_layer if needed
|
51 |
|
52 |
# Perform Grad-CAM
|
53 |
cam_map = grad_cam(image_tensor)
|
|
|
5 |
import torch
|
6 |
from torchcam.methods import GradCAM
|
7 |
from torchcam.utils import overlay_mask
|
8 |
+
|
9 |
+
# Set random colors for detection bounding boxes
|
10 |
COLORS = np.random.uniform(0, 255, size=(80, 3))
|
11 |
|
12 |
def parse_detections_yolov8(results):
|
|
|
47 |
# Convert image to PyTorch tensor for Grad-CAM
|
48 |
image_tensor = torch.tensor(np.array(image)).permute(2, 0, 1).unsqueeze(0).float() / 255.0
|
49 |
image_tensor = image_tensor.to('cpu')
|
50 |
+
print(model.model) # Output model layers to find the target layer
|
51 |
+
grad_cam = GradCAM(model.model, target_layer='model.model[0]')
|
|
|
52 |
|
53 |
# Perform Grad-CAM
|
54 |
cam_map = grad_cam(image_tensor)
|