Spaces:
Sleeping
Sleeping
Commit
·
f6aa311
1
Parent(s):
e1e2e01
Update: class lables
Browse files
yolov5.py
CHANGED
@@ -13,7 +13,7 @@ COLORS = np.random.uniform(0, 255, size=(80, 3))
|
|
13 |
|
14 |
def parse_detections(results):
|
15 |
detections = results.pandas().xyxy[0].to_dict()
|
16 |
-
boxes, colors, names = [], [], []
|
17 |
for i in range(len(detections["xmin"])):
|
18 |
confidence = detections["confidence"][i]
|
19 |
if confidence < 0.2:
|
@@ -24,7 +24,8 @@ def parse_detections(results):
|
|
24 |
boxes.append((xmin, ymin, xmax, ymax))
|
25 |
colors.append(COLORS[category])
|
26 |
names.append(name)
|
27 |
-
|
|
|
28 |
|
29 |
|
30 |
def draw_detections(boxes, colors, names, classes, img):
|
@@ -68,8 +69,8 @@ def xai_yolov5(image):
|
|
68 |
|
69 |
# Run YOLO detection
|
70 |
results = model([image])
|
71 |
-
boxes, colors, names = parse_detections(results)
|
72 |
-
detections_img = draw_detections(boxes, colors, names,
|
73 |
|
74 |
# Prepare input tensor for Grad-CAM
|
75 |
img_float = np.float32(image) / 255
|
|
|
13 |
|
14 |
def parse_detections(results):
|
15 |
detections = results.pandas().xyxy[0].to_dict()
|
16 |
+
boxes, colors, names, classes = [], [], [], []
|
17 |
for i in range(len(detections["xmin"])):
|
18 |
confidence = detections["confidence"][i]
|
19 |
if confidence < 0.2:
|
|
|
24 |
boxes.append((xmin, ymin, xmax, ymax))
|
25 |
colors.append(COLORS[category])
|
26 |
names.append(name)
|
27 |
+
classes.append(category)
|
28 |
+
return boxes, colors, names, classes
|
29 |
|
30 |
|
31 |
def draw_detections(boxes, colors, names, classes, img):
|
|
|
69 |
|
70 |
# Run YOLO detection
|
71 |
results = model([image])
|
72 |
+
boxes, colors, names, classes = parse_detections(results)
|
73 |
+
detections_img = draw_detections(boxes, colors, names,classes, image.copy())
|
74 |
|
75 |
# Prepare input tensor for Grad-CAM
|
76 |
img_float = np.float32(image) / 255
|
yolov8.py
CHANGED
@@ -11,7 +11,7 @@ from ultralytics import YOLO
|
|
11 |
|
12 |
COLORS = np.random.uniform(0, 255, size=(80, 3))
|
13 |
def parse_detections(detections, model):
|
14 |
-
boxes, colors, names = [], [], []
|
15 |
for detection in detections.boxes:
|
16 |
xmin, ymin, xmax, ymax = map(int, detection.xyxy[0].tolist())
|
17 |
confidence = detection.conf.item()
|
@@ -22,7 +22,8 @@ def parse_detections(detections, model):
|
|
22 |
boxes.append((xmin, ymin, xmax, ymax))
|
23 |
colors.append(COLORS[class_id])
|
24 |
names.append(name)
|
25 |
-
|
|
|
26 |
|
27 |
def draw_detections(boxes, colors, names, classes, img):
|
28 |
for box, color, name, cls in zip(boxes, colors, names, classes):
|
@@ -55,8 +56,8 @@ def xai_yolov8s(image):
|
|
55 |
model.eval()
|
56 |
results = model(image)
|
57 |
detections = results[0]
|
58 |
-
boxes, colors, names = parse_detections(detections, model)
|
59 |
-
detections_img = draw_detections(boxes, colors, names, image.copy())
|
60 |
img_float = np.float32(image) / 255
|
61 |
transform = transforms.ToTensor()
|
62 |
tensor = transform(img_float).unsqueeze(0)
|
|
|
11 |
|
12 |
COLORS = np.random.uniform(0, 255, size=(80, 3))
|
13 |
def parse_detections(detections, model):
|
14 |
+
boxes, colors, names, classes = [], [], [], []
|
15 |
for detection in detections.boxes:
|
16 |
xmin, ymin, xmax, ymax = map(int, detection.xyxy[0].tolist())
|
17 |
confidence = detection.conf.item()
|
|
|
22 |
boxes.append((xmin, ymin, xmax, ymax))
|
23 |
colors.append(COLORS[class_id])
|
24 |
names.append(name)
|
25 |
+
classes.append(class_id)
|
26 |
+
return boxes, colors, names, classes
|
27 |
|
28 |
def draw_detections(boxes, colors, names, classes, img):
|
29 |
for box, color, name, cls in zip(boxes, colors, names, classes):
|
|
|
56 |
model.eval()
|
57 |
results = model(image)
|
58 |
detections = results[0]
|
59 |
+
boxes, colors, names, classes = parse_detections(detections, model)
|
60 |
+
detections_img = draw_detections(boxes, colors, names, classes, image.copy())
|
61 |
img_float = np.float32(image) / 255
|
62 |
transform = transforms.ToTensor()
|
63 |
tensor = transform(img_float).unsqueeze(0)
|