Spaces:
Sleeping
Sleeping
Commit
·
a83e547
1
Parent(s):
57419d8
Debug: parsing detections
Browse files- requirements.txt +1 -0
- yolov8.py +29 -2
requirements.txt
CHANGED
|
@@ -8,3 +8,4 @@ grad-cam==1.4.8
|
|
| 8 |
gradio
|
| 9 |
ultralytics
|
| 10 |
torchcam
|
|
|
|
|
|
| 8 |
gradio
|
| 9 |
ultralytics
|
| 10 |
torchcam
|
| 11 |
+
YOLOv8-Explainer
|
yolov8.py
CHANGED
|
@@ -49,7 +49,7 @@ def generate_cam_image(model, target_layers, tensor, rgb_img, boxes):
|
|
| 49 |
return cam_image, renormalized_cam_image
|
| 50 |
|
| 51 |
|
| 52 |
-
def
|
| 53 |
model = YOLO('yolov8n.pt') # Load YOLOv8n pre-trained weights
|
| 54 |
model.eval()
|
| 55 |
|
|
@@ -86,4 +86,31 @@ def xai_yolov8n(image):
|
|
| 86 |
|
| 87 |
# Return final image and a caption
|
| 88 |
caption = "Results using YOLOv8n"
|
| 89 |
-
return Image.fromarray(final_image), caption
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
return cam_image, renormalized_cam_image
|
| 50 |
|
| 51 |
|
| 52 |
+
def xai_yolov8nnnn(image):
|
| 53 |
model = YOLO('yolov8n.pt') # Load YOLOv8n pre-trained weights
|
| 54 |
model.eval()
|
| 55 |
|
|
|
|
| 86 |
|
| 87 |
# Return final image and a caption
|
| 88 |
caption = "Results using YOLOv8n"
|
| 89 |
+
return Image.fromarray(final_image), caption
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
from YOLOv8_Explainer import yolov8_heatmap, display_images
|
| 94 |
+
|
| 95 |
+
def xai_yolov8n(image):
|
| 96 |
+
model = yolov8_heatmap(
|
| 97 |
+
weight="yolov8n.pt",
|
| 98 |
+
conf_threshold=0.4,
|
| 99 |
+
device = "cpu",
|
| 100 |
+
method = "EigenCAM",
|
| 101 |
+
layer=[10, 12, 14, 16, 18, -3],
|
| 102 |
+
backward_type="all",
|
| 103 |
+
ratio=0.02,
|
| 104 |
+
show_box=True,
|
| 105 |
+
renormalize=False,
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
# Pass the NumPy array to the model
|
| 109 |
+
imagelist = model(image) # Use the image array directly
|
| 110 |
+
|
| 111 |
+
# Display the resulting images
|
| 112 |
+
# Pass the NumPy array to the model
|
| 113 |
+
imagelist = model(image) # Use the image array directly
|
| 114 |
+
|
| 115 |
+
# Display the resulting images
|
| 116 |
+
print(imagelist)
|