def extract_auprc(targets, scores, radius, threshold, match_radius=None, pool=None): N = 0 mse = 0 hits = [] preds = [] if pool is not None: process = ExtractMatches(radius, threshold, match_radius) iterator = iterate_score_target_pairs(scores, targets) for assignment,score,this_mse,n in pool.imap_unordered(process, iterator): mse += this_mse hits.append(assignment) preds.append(score) N += n else: for score,target in iterate_score_target_pairs(scores, targets): score,coords = non_maximum_suppression(score, radius, threshold=threshold) if match_radius is None: assignment, dist = match_coordinates(target, coords, radius) else: assignment, dist = match_coordinates(target, coords, match_radius) mse += np.sum(dist[assignment==1]**2) hits.append(assignment) preds.append(score) N += len(target) hits = np.concatenate(hits, 0) preds = np.concatenate(preds, 0) auprc = average_precision(hits, preds, N=N) rmse = np.sqrt(mse/hits.sum()) return auprc, rmse, int(hits.sum()), N
def nms_iterator(scores, radius, threshold, pool=None): process = NonMaximumSuppression(radius, threshold) if pool is not None: for name,score,coords in pool.imap_unordered(process, scores): yield name,score,coords else: for name,score in scores: score,coords = non_maximum_suppression(score, radius, threshold=threshold) yield name,score,coords
def __call__(self, args): score,target = args score,coords = non_maximum_suppression(score, self.radius, threshold=self.threshold) if self.match_radius is None: assignment, dist = match_coordinates(target, coords, self.radius) else: assignment, dist = match_coordinates(target, coords, self.match_radius) mse = np.sum(dist[assignment==1]**2) return assignment, score, mse, len(target)
def __call__(self, args): name, score = args score, coords = non_maximum_suppression(score, self.radius, threshold=self.threshold) return name, score, coords