-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathevaluation_v2.py
More file actions
166 lines (128 loc) · 4.52 KB
/
Copy pathevaluation_v2.py
File metadata and controls
166 lines (128 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
"""Response and filter models for Evaluation V2."""
from typing import Any, Dict, List, Literal, Optional
from nucleus.pydantic_base import DictCompatibleModel
def _snake_to_camel(name: str) -> str:
parts = name.split("_")
if len(parts) == 1:
return name
return parts[0] + "".join(part.capitalize() for part in parts[1:])
def _camelize_filter_value(value: Any) -> Any:
if isinstance(value, dict):
return {
_snake_to_camel(key): (
val if key == "value" else _camelize_filter_value(val)
)
for key, val in value.items()
}
if isinstance(value, list):
return [_camelize_filter_value(item) for item in value]
return value
class RangeNum(DictCompatibleModel):
min: Optional[float] = None
max: Optional[float] = None
class MetadataPredicate(DictCompatibleModel):
key: str
op: Literal["EQ", "IN", "GT", "LT"]
value: Optional[Any] = None
_FILTER_API_KEYS = {
"confidence_range": "confidenceRange",
"iou_range": "iouRange",
"pred_labels": "predLabels",
"gt_labels": "gtLabels",
"item_metadata": "itemMetadata",
"prediction_metadata": "predictionMetadata",
"gt_area_range": "gtAreaRange",
"label_equality": "labelEquality",
"has_ground_truth": "hasGroundTruth",
"tide_background": "tideBackground",
"slice_ids": "sliceIds",
}
class EvaluationV2FilterArgs(DictCompatibleModel):
"""Optional filters for :meth:`nucleus.evaluation_v2.EvaluationV2.charts` and :meth:`nucleus.evaluation_v2.EvaluationV2.examples`."""
confidence_range: Optional[RangeNum] = None
iou_range: Optional[RangeNum] = None
pred_labels: Optional[List[str]] = None
gt_labels: Optional[List[str]] = None
item_metadata: Optional[List[MetadataPredicate]] = None
prediction_metadata: Optional[List[MetadataPredicate]] = None
gt_area_range: Optional[RangeNum] = None
label_equality: Optional[Literal["EQ", "NEQ"]] = None
has_ground_truth: Optional[bool] = None
tide_background: Optional[bool] = None
slice_ids: Optional[List[str]] = None
def to_api_filters(self) -> Dict[str, Any]:
"""Return filters as a dict ready for API requests."""
d = self.dict(exclude_none=True)
return {
api_key: _camelize_filter_value(d[snake_key])
for snake_key, api_key in _FILTER_API_KEYS.items()
if snake_key in d
}
class MapSummary(DictCompatibleModel):
mapAt50: Optional[float] = None
mapAt75: Optional[float] = None
mapAt5095: Optional[float] = None
class PerClassAp(DictCompatibleModel):
classLabel: str
ap: float
class ConfusionEntry(DictCompatibleModel):
gtLabel: str
predLabel: str
count: int
class ScoreHistogramBucket(DictCompatibleModel):
bucketMin: float
bucketMax: float
count: int
class TotalCounts(DictCompatibleModel):
tp: int
fp: int
fn: int
predsWithConfidence: int
class ApBySize(DictCompatibleModel):
small: Optional[float] = None
medium: Optional[float] = None
large: Optional[float] = None
class PrCurvePoint(DictCompatibleModel):
classLabel: str
recall: float
precision: float
class TideAttribution(DictCompatibleModel):
truePositive: int
localization: int
classification: int
both: int
duplicate: int
background: int
missed: int
class EvaluationV2Charts(DictCompatibleModel):
mapSummary: MapSummary
perClassAp: List[PerClassAp]
confusionMatrix: List[ConfusionEntry]
scoreHistogram: List[ScoreHistogramBucket]
computedIouRanges: List[float]
totalCounts: TotalCounts
apBySize: ApBySize
prCurve: List[PrCurvePoint]
tideAttribution: TideAttribution
class EvaluationV2MatchExample(DictCompatibleModel):
id: str
evaluation_id: str
dataset_item_id: str
model_prediction_id: Optional[str] = None
ground_truth_annotation_id: Optional[str] = None
pred_canonical_label: Optional[str] = None
gt_canonical_label: Optional[str] = None
pred_raw_label: Optional[str] = None
gt_raw_label: Optional[str] = None
iou: Optional[float] = None
confidence: Optional[float] = None
true_positive: bool
match_type: str
gt_area: Optional[float] = None
item_metadata: Optional[Dict[str, Any]] = None
prediction_metadata: Optional[Dict[str, Any]] = None
prediction_row: Optional[Dict[str, Any]] = None
annotation_row: Optional[Dict[str, Any]] = None
class EvaluationV2ExamplesPage(DictCompatibleModel):
rows: List[EvaluationV2MatchExample]
total: int