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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
Index: dyda-1.41.0/dyda/components/yolo_detector.py
===================================================================
--- dyda-1.41.0.orig/dyda/components/yolo_detector.py
+++ dyda-1.41.0/dyda/components/yolo_detector.py
@@ -41,6 +41,13 @@ class BOX(Structure):
("w", c_float),
("h", c_float)]
+class DETECTION(Structure):
+ _fields_ = [("bbox", BOX),
+ ("classes", c_int),
+ ("prob", POINTER(c_float)),
+ ("mask", POINTER(c_float)),
+ ("objectness", c_float),
+ ("sort_class", c_int)]
class IMAGE(Structure):
_fields_ = [("w", c_int),
@@ -98,28 +105,28 @@ class DetectorYOLO(detector_base.Detecto
self.lib.network_height.argtypes = [c_void_p]
self.lib.network_height.restype = c_int
- self.make_boxes = self.lib.make_boxes
- self.make_boxes.argtypes = [c_void_p]
- self.make_boxes.restype = POINTER(BOX)
-
+ self.make_network_boxes = self.lib.make_network_boxes
+ self.make_network_boxes.argtypes = [c_void_p]
+ self.make_network_boxes.restype = POINTER(DETECTION)
+
+ self.get_network_boxes = self.lib.get_network_boxes
+ self.get_network_boxes.argtypes = [c_void_p, c_int, c_int, c_float, c_float, POINTER(c_int), c_int, POINTER(c_int)]
+ self.get_network_boxes.restype = POINTER(DETECTION)
+
self.free_ptrs = self.lib.free_ptrs
self.free_ptrs.argtypes = [POINTER(c_void_p), c_int]
- self.free_boxes = self.lib.free_boxes
- self.free_ptrs.argtypes = [c_void_p]
-
- self.num_boxes = self.lib.num_boxes
- self.num_boxes.argtypes = [c_void_p]
- self.num_boxes.restype = c_int
-
- self.make_probs = self.lib.make_probs
- self.make_probs.argtypes = [c_void_p]
- self.make_probs.restype = POINTER(POINTER(c_float))
+ self.free_detections = self.lib.free_detections
+ self.free_detections.argtypes = [c_void_p]
self.detect = self.lib.network_predict
self.detect.argtypes = [c_void_p, IMAGE, c_float, c_float, c_float,
POINTER(BOX), POINTER(POINTER(c_float))]
+ self.predict_image = self.lib.network_predict_image
+ self.predict_image.argtypes = [c_void_p, IMAGE]
+ self.predict_image.restype = POINTER(c_float)
+
self.free_image = self.lib.free_image
self.free_image.argtypes = [IMAGE]
@@ -127,32 +134,10 @@ class DetectorYOLO(detector_base.Detecto
self.load_image.argtypes = [c_char_p, c_int, c_int]
self.load_image.restype = IMAGE
- self.network_detect = self.lib.network_detect
- self.network_detect.argtypes = [c_void_p, IMAGE, c_float, c_float,
- c_float, POINTER(BOX),
- POINTER(POINTER(c_float))]
-
- self.network_detect_objinfo = self.lib.network_detect_objinfo
- self.network_detect_objinfo.argtypes = [c_void_p,
- IMAGE,
- c_float,
- c_float,
- c_float,
- POINTER(BOX),
- POINTER(POINTER(c_float))]
- self.network_detect_objinfo.restype = OBJECT_INFO_LIST
- self.free_object_info_list = self.lib.free_object_info_list
- self.free_object_info_list.argtypes = [OBJECT_INFO_LIST]
-
libnp_filepath = pjoin(
os.path.dirname(param["lib_path"]),
- "libdarknet_numpy.so")
+ "libdarknet.so")
self.libnp = CDLL(libnp_filepath, RTLD_GLOBAL)
- self.ndarray_image = self.libnp.ndarray_to_image
- self.ndarray_image.argtypes = [POINTER(c_ubyte),
- POINTER(c_long),
- POINTER(c_long)]
- self.ndarray_image.restype = IMAGE
# load yolo net
load_net = self.lib.load_network
@@ -215,23 +200,25 @@ class DetectorYOLO(detector_base.Detecto
img_shape = img_array.shape
img_w = img_shape[1]
img_h = img_shape[0]
- boxes = self.make_boxes(self.net)
- probs = self.make_probs(self.net)
- num = self.num_boxes(self.net)
- obj_info_list = self.network_detect_objinfo(
- self.net, im, thresh, hier_thresh, nms, boxes, probs
+ num = c_int(0)
+ pnum = pointer(num)
+ self.predict_image(net, im)
+ obj_info_list = self.get_network_boxes(
+ self.net, im.w, im.h, thresh, hier_thresh, None, 0, pnum
)
- objs = obj_info_list.data[:obj_info_list.len]
+ num = pnum[0]
annos = []
- for obj in objs:
- label = str(self.meta.names[obj.label], 'utf-8')
- conf = obj.confidence
- bb = [obj.top, obj.bottom, obj.left, obj.right]
- annos.append([label, conf, bb])
+ for j in range(num):
+ for i in range(meta.classes):
+ if obj_info_list[j].prob[i] > 0:
+ boxes = dets[j].bbox
+ label = self.meta.names[i].decode('utf-8')
+ conf = dets[j].prob[i] #obj.confidence
+ bb = [boxes.y - (boxes.h / 2), boxes.y + (boxes.h / 2),
+ boxes.x - (boxes.w / 2), boxes.x + (boxes.w / 2)]
+ annos.append([label, conf, bb])
self.free_image(im)
- self.free_object_info_list(obj_info_list)
- self.free_ptrs(cast(probs, POINTER(c_void_p)), num)
- self.free_boxes(boxes)
+ self.free_detections(obj_info_list, num)
res = lab_tools.output_pred_detection(self.metadata[0], annos)
self.results.append(res)
Index: dyda-1.41.0/dyda/pipelines/configs/object_detection_and_tracking.config
===================================================================
--- dyda-1.41.0.orig/dyda/pipelines/configs/object_detection_and_tracking.config
+++ dyda-1.41.0/dyda/pipelines/configs/object_detection_and_tracking.config
@@ -46,10 +46,10 @@
"type": "normal",
"input_type": "use_previous_output",
"dyda_config": {
- "lib_path": "/usr/lib/libdarknet.so",
- "net_cfg": "/usr/share/dlmodels/yolococov2-people-car-20190723/yolo-voc.cfg",
- "net_weights": "/usr/share/dlmodels/yolococov2-people-car-20190723/yolo-voc_final.weights",
- "net_meta": "/usr/share/dlmodels/yolococov2-people-car-20190723/dt42.data",
+ "lib_path": "/usr/lib/darknet/libdarknet.so",
+ "net_cfg": "/usr/share/darknet/cfg/yolov3-tiny.cfg",
+ "net_weights": "/tmp/yolov3-tiny.weights",
+ "net_meta": "/usr/share/darknet/cfg/coco.data",
"thresh": 0.1,
"hier_thresh": 0.5,
"nms": 0.07
Index: dyda-1.41.0/dyda/pipelines/configs/object_detection_and_tracking_debug.config
===================================================================
--- dyda-1.41.0.orig/dyda/pipelines/configs/object_detection_and_tracking_debug.config
+++ dyda-1.41.0/dyda/pipelines/configs/object_detection_and_tracking_debug.config
@@ -46,10 +46,10 @@
"type": "normal",
"input_type": "use_previous_output",
"dyda_config": {
- "lib_path": "/usr/lib/libdarknet.so",
- "net_cfg": "/usr/share/dlmodels/yolococov2-people-car-20190723/yolo-voc.cfg",
- "net_weights": "/usr/share/dlmodels/yolococov2-people-car-20190723/yolo-voc_final.weights",
- "net_meta": "/usr/share/dlmodels/yolococov2-people-car-20190723/dt42.data",
+ "lib_path": "/usr/lib/darknet/libdarknet.so",
+ "net_cfg": "/usr/share/darknet/cfg/yolov3-tiny.cfg",
+ "net_weights": "/tmp/yolov3-tiny.weights",
+ "net_meta": "/usr/share/darknet/cfg/coco.data",
"thresh": 0.1,
"hier_thresh": 0.5,
"nms": 0.07
|