Skip to content

Commit 67441a4

Browse files
authored
Adapted yolo.py to be re-used within another project
1 parent 8b327f6 commit 67441a4

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

motrackers/detectors/yolo.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, weights_path, configfile_path, labels_path, confidence_thresh
2323
object_names = load_labelsjson(labels_path)
2424

2525
layer_names = self.net.getLayerNames()
26-
self.layer_names = [layer_names[i[0] - 1] for i in self.net.getUnconnectedOutLayers()]
26+
self.layer_names = [layer_names[i-1] for i in self.net.getUnconnectedOutLayers()]
2727

2828
self.scale_factor = 1/255.0
2929
self.image_size = (416, 416)
@@ -54,12 +54,13 @@ def detect(self, image):
5454
scores = detect[5:]
5555
class_id = np.argmax(scores)
5656
confidence = scores[class_id]
57-
if confidence > self.confidence_threshold:
58-
xmid, ymid, w, h = detect[0:4] * np.array([self.width, self.height, self.width, self.height])
59-
x, y = int(xmid - 0.5*w), int(ymid - 0.5*h)
60-
bboxes.append([x, y, w, h])
61-
confidences.append(float(confidence))
62-
class_ids.append(class_id)
57+
if class_id == 0: # to enforce that we need only human labels
58+
if confidence > self.confidence_threshold:
59+
xmid, ymid, w, h = detect[0:4] * np.array([self.width, self.height, self.width, self.height])
60+
x, y = int(xmid - 0.5*w), int(ymid - 0.5*h)
61+
bboxes.append([x, y, w, h])
62+
confidences.append(float(confidence))
63+
class_ids.append(class_id)
6364

6465
indices = cv.dnn.NMSBoxes(bboxes, confidences, self.confidence_threshold, self.nms_threshold).flatten()
6566
class_ids = np.array(class_ids).astype('int')

0 commit comments

Comments
 (0)