Processes the image frame and finds bounding box(detections). Associates the detection with corresponding tracklets and also handles lost, removed, refound and active tracklets Parameters ---------- im_blob : torch.float32 Tensor o
(self, im_blob, img0)
| 156 | self.kalman_filter = KalmanFilter() |
| 157 | |
| 158 | def update(self, im_blob, img0): |
| 159 | """ |
| 160 | Processes the image frame and finds bounding box(detections). |
| 161 | |
| 162 | Associates the detection with corresponding tracklets and also handles lost, removed, refound and active tracklets |
| 163 | |
| 164 | Parameters |
| 165 | ---------- |
| 166 | im_blob : torch.float32 |
| 167 | Tensor of shape depending upon the size of image. By default, shape of this tensor is [1, 3, 608, 1088] |
| 168 | |
| 169 | img0 : ndarray |
| 170 | ndarray of shape depending on the input image sequence. By default, shape is [608, 1080, 3] |
| 171 | |
| 172 | Returns |
| 173 | ------- |
| 174 | output_stracks : list of Strack(instances) |
| 175 | The list contains information regarding the online_tracklets for the recieved image tensor. |
| 176 | |
| 177 | """ |
| 178 | |
| 179 | self.frame_id += 1 |
| 180 | activated_starcks = [] # for storing active tracks, for the current frame |
| 181 | refind_stracks = [] # Lost Tracks whose detections are obtained in the current frame |
| 182 | lost_stracks = [] # The tracks which are not obtained in the current frame but are not removed.(Lost for some time lesser than the threshold for removing) |
| 183 | removed_stracks = [] |
| 184 | |
| 185 | t1 = time.time() |
| 186 | ''' Step 1: Network forward, get detections & embeddings''' |
| 187 | with torch.no_grad(): |
| 188 | pred = self.model(im_blob) |
| 189 | # pred is tensor of all the proposals (default number of proposals: 54264). Proposals have information associated with the bounding box and embeddings |
| 190 | pred = pred[pred[:, :, 4] > self.low_thresh] |
| 191 | # pred now has lesser number of proposals. Proposals rejected on basis of object confidence score |
| 192 | if len(pred) > 0: |
| 193 | dets = non_max_suppression(pred.unsqueeze(0), self.low_thresh, self.opt.nms_thres)[0].cpu() |
| 194 | # Final proposals are obtained in dets. Information of bounding box and embeddings also included |
| 195 | # Next step changes the detection scales |
| 196 | scale_coords(self.opt.img_size, dets[:, :4], img0.shape).round() |
| 197 | '''Detections is list of (x1, y1, x2, y2, object_conf, class_score, class_pred)''' |
| 198 | # class_pred is the embeddings. |
| 199 | |
| 200 | dets = dets.numpy() |
| 201 | remain_inds = dets[:, 4] > self.det_thresh |
| 202 | inds_low = dets[:, 4] > self.low_thresh |
| 203 | inds_high = dets[:, 4] < self.det_thresh |
| 204 | inds_second = np.logical_and(inds_low, inds_high) |
| 205 | dets_second = dets[inds_second] |
| 206 | dets = dets[remain_inds] |
| 207 | |
| 208 | detections = [STrack(STrack.tlbr_to_tlwh(tlbrs[:4]), tlbrs[4]) for |
| 209 | tlbrs in dets[:, :5]] |
| 210 | else: |
| 211 | detections = [] |
| 212 | dets_second = [] |
| 213 | |
| 214 | t2 = time.time() |
| 215 | # print('Forward: {} s'.format(t2-t1)) |
no test coverage detected