(self, im_blob, img0)
| 208 | return results |
| 209 | |
| 210 | def update(self, im_blob, img0): |
| 211 | self.frame_id += 1 |
| 212 | activated_starcks = [] |
| 213 | refind_stracks = [] |
| 214 | lost_stracks = [] |
| 215 | removed_stracks = [] |
| 216 | |
| 217 | width = img0.shape[1] |
| 218 | height = img0.shape[0] |
| 219 | inp_height = im_blob.shape[2] |
| 220 | inp_width = im_blob.shape[3] |
| 221 | c = np.array([width / 2., height / 2.], dtype=np.float32) |
| 222 | s = max(float(inp_width) / float(inp_height) * height, width) * 1.0 |
| 223 | meta = {'c': c, 's': s, |
| 224 | 'out_height': inp_height // self.opt.down_ratio, |
| 225 | 'out_width': inp_width // self.opt.down_ratio} |
| 226 | |
| 227 | ''' Step 1: Network forward, get detections & embeddings''' |
| 228 | with torch.no_grad(): |
| 229 | output = self.model(im_blob)[-1] |
| 230 | hm = output['hm'].sigmoid_() |
| 231 | wh = output['wh'] |
| 232 | |
| 233 | reg = output['reg'] if self.opt.reg_offset else None |
| 234 | dets, inds = mot_decode(hm, wh, reg=reg, ltrb=self.opt.ltrb, K=self.opt.K) |
| 235 | |
| 236 | dets = self.post_process(dets, meta) |
| 237 | dets = self.merge_outputs([dets])[1] |
| 238 | |
| 239 | remain_inds = dets[:, 4] > self.opt.conf_thres |
| 240 | inds_low = dets[:, 4] > 0.2 |
| 241 | inds_high = dets[:, 4] < self.opt.conf_thres |
| 242 | inds_second = np.logical_and(inds_low, inds_high) |
| 243 | dets_second = dets[inds_second] |
| 244 | dets = dets[remain_inds] |
| 245 | |
| 246 | if len(dets) > 0: |
| 247 | '''Detections''' |
| 248 | detections = [STrack(STrack.tlbr_to_tlwh(tlbrs[:4]), tlbrs[4]) for |
| 249 | tlbrs in dets[:, :5]] |
| 250 | else: |
| 251 | detections = [] |
| 252 | |
| 253 | ''' Add newly detected tracklets to tracked_stracks''' |
| 254 | unconfirmed = [] |
| 255 | tracked_stracks = [] # type: list[STrack] |
| 256 | for track in self.tracked_stracks: |
| 257 | if not track.is_activated: |
| 258 | unconfirmed.append(track) |
| 259 | else: |
| 260 | tracked_stracks.append(track) |
| 261 | |
| 262 | ''' Step 2: First association, with IOU''' |
| 263 | strack_pool = joint_stracks(tracked_stracks, self.lost_stracks) |
| 264 | # Predict the current location with KF |
| 265 | STrack.multi_predict(strack_pool) |
| 266 | dists = matching.iou_distance(strack_pool, detections) |
| 267 | matches, u_track, u_detection = matching.linear_assignment(dists, thresh=self.opt.match_thres) |
nothing calls this directly
no test coverage detected