Run per image evaluation on given images and store results in self.evalImgs_cpp, a datastructure that isn't readable from Python but is used by a c++ implementation of accumulate(). Unlike the original COCO PythonAPI, we don't populate the datastructure self.evalImg
(self)
| 23 | """ |
| 24 | |
| 25 | def evaluate(self): |
| 26 | """ |
| 27 | Run per image evaluation on given images and store results in self.evalImgs_cpp, a |
| 28 | datastructure that isn't readable from Python but is used by a c++ implementation of |
| 29 | accumulate(). Unlike the original COCO PythonAPI, we don't populate the datastructure |
| 30 | self.evalImgs because this datastructure is a computational bottleneck. |
| 31 | :return: None |
| 32 | """ |
| 33 | tic = time.time() |
| 34 | |
| 35 | print("Running per image evaluation...") |
| 36 | p = self.params |
| 37 | # add backward compatibility if useSegm is specified in params |
| 38 | if p.useSegm is not None: |
| 39 | p.iouType = "segm" if p.useSegm == 1 else "bbox" |
| 40 | print( |
| 41 | "useSegm (deprecated) is not None. Running {} evaluation".format( |
| 42 | p.iouType |
| 43 | ) |
| 44 | ) |
| 45 | print("Evaluate annotation type *{}*".format(p.iouType)) |
| 46 | p.imgIds = list(np.unique(p.imgIds)) |
| 47 | if p.useCats: |
| 48 | p.catIds = list(np.unique(p.catIds)) |
| 49 | p.maxDets = sorted(p.maxDets) |
| 50 | self.params = p |
| 51 | |
| 52 | self._prepare() |
| 53 | |
| 54 | # loop through images, area range, max detection number |
| 55 | catIds = p.catIds if p.useCats else [-1] |
| 56 | |
| 57 | if p.iouType == "segm" or p.iouType == "bbox": |
| 58 | computeIoU = self.computeIoU |
| 59 | elif p.iouType == "keypoints": |
| 60 | computeIoU = self.computeOks |
| 61 | self.ious = { |
| 62 | (imgId, catId): computeIoU(imgId, catId) |
| 63 | for imgId in p.imgIds |
| 64 | for catId in catIds |
| 65 | } |
| 66 | |
| 67 | maxDet = p.maxDets[-1] |
| 68 | |
| 69 | # <<<< Beginning of code differences with original COCO API |
| 70 | def convert_instances_to_cpp(instances, is_det=False): |
| 71 | # Convert annotations for a list of instances in an image to a format that's fast |
| 72 | # to access in C++ |
| 73 | instances_cpp = [] |
| 74 | for instance in instances: |
| 75 | instance_cpp = _C.InstanceAnnotation( |
| 76 | int(instance["id"]), |
| 77 | instance["score"] if is_det else instance.get("score", 0.0), |
| 78 | instance["area"], |
| 79 | bool(instance.get("iscrowd", 0)), |
| 80 | bool(instance.get("ignore", 0)), |
| 81 | ) |
| 82 | instances_cpp.append(instance_cpp) |
nothing calls this directly
no outgoing calls
no test coverage detected