Returns the prediction results for the current task. Args: task (TaskInfo object): task object that contain the necessary information for action prediction. (e.g. frames, boxes) Returns: task (TaskInfo object): the same task info objec
(self, task)
| 48 | logger.info("Finish loading model weights") |
| 49 | |
| 50 | def __call__(self, task): |
| 51 | """ |
| 52 | Returns the prediction results for the current task. |
| 53 | Args: |
| 54 | task (TaskInfo object): task object that contain |
| 55 | the necessary information for action prediction. (e.g. frames, boxes) |
| 56 | Returns: |
| 57 | task (TaskInfo object): the same task info object but filled with |
| 58 | prediction values (a tensor) and the corresponding boxes for |
| 59 | action detection task. |
| 60 | """ |
| 61 | if self.cfg.DETECTION.ENABLE: |
| 62 | task = self.object_detector(task) |
| 63 | |
| 64 | frames, bboxes = task.frames, task.bboxes |
| 65 | if bboxes is not None: |
| 66 | bboxes = cv2_transform.scale_boxes( |
| 67 | self.cfg.DATA.TEST_CROP_SIZE, |
| 68 | bboxes, |
| 69 | task.img_height, |
| 70 | task.img_width, |
| 71 | ) |
| 72 | if self.cfg.DEMO.INPUT_FORMAT == "BGR": |
| 73 | frames = [ |
| 74 | cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) for frame in frames |
| 75 | ] |
| 76 | |
| 77 | frames = [ |
| 78 | cv2_transform.scale(self.cfg.DATA.TEST_CROP_SIZE, frame) |
| 79 | for frame in frames |
| 80 | ] |
| 81 | inputs = process_cv2_inputs(frames, self.cfg) |
| 82 | if bboxes is not None: |
| 83 | index_pad = torch.full( |
| 84 | size=(bboxes.shape[0], 1), |
| 85 | fill_value=float(0), |
| 86 | device=bboxes.device, |
| 87 | ) |
| 88 | |
| 89 | # Pad frame index for each box. |
| 90 | bboxes = torch.cat([index_pad, bboxes], axis=1) |
| 91 | if self.cfg.NUM_GPUS > 0: |
| 92 | # Transfer the data to the current GPU device. |
| 93 | if isinstance(inputs, (list,)): |
| 94 | for i in range(len(inputs)): |
| 95 | inputs[i] = inputs[i].cuda( |
| 96 | device=torch.device(self.gpu_id), non_blocking=True |
| 97 | ) |
| 98 | else: |
| 99 | inputs = inputs.cuda( |
| 100 | device=torch.device(self.gpu_id), non_blocking=True |
| 101 | ) |
| 102 | if self.cfg.DETECTION.ENABLE and not bboxes.shape[0]: |
| 103 | preds = torch.tensor([]) |
| 104 | else: |
| 105 | preds = self.model(inputs, bboxes) |
| 106 | |
| 107 | if self.cfg.NUM_GPUS: |
nothing calls this directly
no test coverage detected