COCO AP Evaluation class. All the data in the val2017 dataset are processed and evaluated by COCO API.
| 25 | |
| 26 | |
| 27 | class COCOEvaluator: |
| 28 | """ |
| 29 | COCO AP Evaluation class. All the data in the val2017 dataset are processed |
| 30 | and evaluated by COCO API. |
| 31 | """ |
| 32 | |
| 33 | def __init__( |
| 34 | self, dataloader, img_size, confthre, nmsthre, num_classes, testdev=False |
| 35 | ): |
| 36 | """ |
| 37 | Args: |
| 38 | dataloader (Dataloader): evaluate dataloader. |
| 39 | img_size (int): image size after preprocess. images are resized |
| 40 | to squares whose shape is (img_size, img_size). |
| 41 | confthre (float): confidence threshold ranging from 0 to 1, which |
| 42 | is defined in the config file. |
| 43 | nmsthre (float): IoU threshold of non-max supression ranging from 0 to 1. |
| 44 | """ |
| 45 | self.dataloader = dataloader |
| 46 | self.img_size = img_size |
| 47 | self.confthre = confthre |
| 48 | self.nmsthre = nmsthre |
| 49 | self.num_classes = num_classes |
| 50 | self.testdev = testdev |
| 51 | |
| 52 | def evaluate( |
| 53 | self, |
| 54 | model, |
| 55 | distributed=False, |
| 56 | half=False, |
| 57 | trt_file=None, |
| 58 | decoder=None, |
| 59 | test_size=None, |
| 60 | ): |
| 61 | """ |
| 62 | COCO average precision (AP) Evaluation. Iterate inference on the test dataset |
| 63 | and the results are evaluated by COCO API. |
| 64 | |
| 65 | NOTE: This function will change training mode to False, please save states if needed. |
| 66 | |
| 67 | Args: |
| 68 | model : model to evaluate. |
| 69 | |
| 70 | Returns: |
| 71 | ap50_95 (float) : COCO AP of IoU=50:95 |
| 72 | ap50 (float) : COCO AP of IoU=50 |
| 73 | summary (sr): summary info of evaluation. |
| 74 | """ |
| 75 | # TODO half to amp_test |
| 76 | tensor_type = torch.cuda.HalfTensor if half else torch.cuda.FloatTensor |
| 77 | model = model.eval() |
| 78 | if half: |
| 79 | model = model.half() |
| 80 | ids = [] |
| 81 | data_list = [] |
| 82 | progress_bar = tqdm if is_main_process() else iter |
| 83 | |
| 84 | inference_time = 0 |
no outgoing calls
no test coverage detected