COCO AP Evaluation class. All the data in the val2017 dataset are processed and evaluated by COCO API.
| 53 | |
| 54 | |
| 55 | class MOTEvaluator: |
| 56 | """ |
| 57 | COCO AP Evaluation class. All the data in the val2017 dataset are processed |
| 58 | and evaluated by COCO API. |
| 59 | """ |
| 60 | |
| 61 | def __init__( |
| 62 | self, args, dataloader, img_size, confthre, nmsthre, num_classes): |
| 63 | """ |
| 64 | Args: |
| 65 | dataloader (Dataloader): evaluate dataloader. |
| 66 | img_size (int): image size after preprocess. images are resized |
| 67 | to squares whose shape is (img_size, img_size). |
| 68 | confthre (float): confidence threshold ranging from 0 to 1, which |
| 69 | is defined in the config file. |
| 70 | nmsthre (float): IoU threshold of non-max supression ranging from 0 to 1. |
| 71 | """ |
| 72 | self.dataloader = dataloader |
| 73 | self.img_size = img_size |
| 74 | self.confthre = confthre |
| 75 | self.nmsthre = nmsthre |
| 76 | self.num_classes = num_classes |
| 77 | self.args = args |
| 78 | |
| 79 | def evaluate( |
| 80 | self, |
| 81 | model, |
| 82 | distributed=False, |
| 83 | half=False, |
| 84 | trt_file=None, |
| 85 | decoder=None, |
| 86 | test_size=None, |
| 87 | result_folder=None |
| 88 | ): |
| 89 | """ |
| 90 | COCO average precision (AP) Evaluation. Iterate inference on the test dataset |
| 91 | and the results are evaluated by COCO API. |
| 92 | |
| 93 | NOTE: This function will change training mode to False, please save states if needed. |
| 94 | |
| 95 | Args: |
| 96 | model : model to evaluate. |
| 97 | |
| 98 | Returns: |
| 99 | ap50_95 (float) : COCO AP of IoU=50:95 |
| 100 | ap50 (float) : COCO AP of IoU=50 |
| 101 | summary (sr): summary info of evaluation. |
| 102 | """ |
| 103 | # TODO half to amp_test |
| 104 | tensor_type = torch.cuda.HalfTensor if half else torch.cuda.FloatTensor |
| 105 | model = model.eval() |
| 106 | if half: |
| 107 | model = model.half() |
| 108 | ids = [] |
| 109 | data_list = [] |
| 110 | results = [] |
| 111 | video_names = defaultdict() |
| 112 | progress_bar = tqdm if is_main_process() else iter |