Preserve offline geometry, marking, replay and evaluation pipelines with source manifests and synthetic tests. Research qualification does not activate these methods as production navigation.
33 lines
1.8 KiB
Python
33 lines
1.8 KiB
Python
"""One-to-one evaluation against reviewed object identities, never inference."""
|
|
import numpy as np
|
|
import shapely
|
|
from shapely.geometry import shape
|
|
from scipy.optimize import linear_sum_assignment
|
|
|
|
|
|
def compare(reference, result, minimum_iou=.5):
|
|
previous=reference['features'];current=result['features']
|
|
matrix=np.zeros((len(previous),len(current)))
|
|
for i,a in enumerate(previous):
|
|
p=shapely.force_2d(shape(a['geometry']))
|
|
for j,b in enumerate(current):
|
|
if a['properties']['subtype']!=b['properties']['subtype']:continue
|
|
q=shape(b['geometry']);matrix[i,j]=p.intersection(q).area/max(p.union(q).area,1e-9)
|
|
eligible=matrix>=minimum_iou
|
|
weights=eligible.astype(float)+matrix*eligible/(max(matrix.shape,default=0)+1)
|
|
rows,columns=linear_sum_assignment(-weights)
|
|
pairs=[];matched_before=set();matched_after=set()
|
|
for i,j in zip(rows,columns):
|
|
if matrix[i,j]<minimum_iou:continue
|
|
matched_before.add(int(i));matched_after.add(int(j))
|
|
pairs.append(dict(reference_id=previous[i]['id'],result_id=current[j]['id'],
|
|
kind=current[j]['properties']['subtype'],iou=float(matrix[i,j])))
|
|
missing=[f['id'] for i,f in enumerate(previous) if i not in matched_before]
|
|
return dict(passed=not missing,reference_objects=len(previous),result_objects=len(current),
|
|
matched=len(pairs),missing=missing,
|
|
unmatched_results=[f['id'] for j,f in enumerate(current) if j not in matched_after],
|
|
pairs=pairs,matching='one-to-one, same class',minimum_identity_iou=minimum_iou,
|
|
reference_contours_are_metric_ground_truth=False,
|
|
metric_quality='separate original-pixel and fixed-preset verification',
|
|
independent_generalization_measured=False)
|