@@ -68,6 +68,10 @@ cdef class Network:
6868 def shape (self ):
6969 return dn.network_width(self ._c_network), dn.network_height(self ._c_network)
7070
71+ @property
72+ def depth (self ):
73+ return dn.network_depth(self ._c_network)
74+
7175 def input_size (self ):
7276 return dn.network_input_size(self ._c_network)
7377
@@ -126,4 +130,47 @@ cdef class Network:
126130 letterbox)
127131 rv = convert_detections_to_tuples(detections, num_dets, nms_type, nms_threshold)
128132 dn.free_detections(detections, num_dets)
129- return sorted (rv, key = lambda x : x[1 ], reverse = True )
133+
134+ return rv
135+
136+ def detect_batch (self ,
137+ int batch_size ,
138+ np.ndarray[dtype = np.float32_t, ndim = 1 , mode = " c" ] frames,
139+ frame_size = None ,
140+ float threshold = .5 ,
141+ float hierarchical_threshold = .5 ,
142+ int relative = 0 ,
143+ int letterbox = 1 ,
144+ str nms_type = " sort" ,
145+ float nms_threshold = .45
146+ ):
147+ pred_width, pred_height = self .shape if frame_size is None else frame_size
148+
149+ cdef dn.image imr
150+ # This looks awkward, but the batch predict *does not* use c, w, h.
151+ imr.c = 0
152+ imr.w = 0
153+ imr.h = 0
154+ imr.data = < float * > frames.data
155+
156+ cdef dn.det_num_pair* batch_detections
157+ batch_detections = dn.network_predict_batch(
158+ self ._c_network,
159+ imr,
160+ batch_size,
161+ pred_width,
162+ pred_height,
163+ threshold,
164+ hierarchical_threshold,
165+ < int * > 0 ,
166+ relative,
167+ letterbox
168+ )
169+ rv = [
170+ convert_detections_to_tuples(batch_detections[b].dets, batch_detections[b].num, nms_type, nms_threshold)
171+ for b in range (batch_size)
172+ ]
173+ dn.free_batch_detections(batch_detections, batch_size)
174+ return rv
175+
176+
0 commit comments