Spaces:
Build error
Build error
Update ref-metrics.py
Browse files- ref-metrics.py +41 -43
ref-metrics.py
CHANGED
|
@@ -90,62 +90,60 @@ class UserFriendlyMetrics(evaluate.Metric):
|
|
| 90 |
"""Optional: download external resources useful to compute the scores"""
|
| 91 |
# TODO: Download external resources if needed
|
| 92 |
pass
|
| 93 |
-
|
| 94 |
|
| 95 |
def compute_from_payload(
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
| 112 |
def dummy_values(self, area_ranges_tuples=None):
|
| 113 |
"""Dummy randome values in the expected format that all new metrics need to return"""
|
| 114 |
|
| 115 |
# Use default ranges if none are provided
|
| 116 |
if area_ranges_tuples is None:
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
("large", [12**2, 1e5**2]),
|
| 122 |
-
]
|
| 123 |
-
|
| 124 |
# Generate random dummy values
|
| 125 |
def generate_random_values():
|
| 126 |
return {
|
| 127 |
"tp": random.randint(0, 100), # Random integer between 0 and 100
|
| 128 |
-
"fp": random.randint(0, 50),
|
| 129 |
-
"fn": random.randint(0, 50),
|
| 130 |
-
"precision": round(
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
}
|
| 134 |
-
|
| 135 |
# Initialize output structure
|
| 136 |
-
dummy_output = {
|
| 137 |
-
|
| 138 |
-
"overall": {},
|
| 139 |
-
"per_sequence": {
|
| 140 |
-
"sequence_1": {}
|
| 141 |
-
}
|
| 142 |
-
}
|
| 143 |
-
}
|
| 144 |
-
|
| 145 |
# Populate only the ranges specified in area_ranges_tuples with random values
|
| 146 |
-
for
|
| 147 |
-
dummy_output["model_1"]["overall"][
|
| 148 |
-
dummy_output["model_1"]["per_sequence"]["sequence_1"][
|
| 149 |
-
|
|
|
|
|
|
|
| 150 |
return dummy_output
|
| 151 |
|
|
|
|
| 90 |
"""Optional: download external resources useful to compute the scores"""
|
| 91 |
# TODO: Download external resources if needed
|
| 92 |
pass
|
|
|
|
| 93 |
|
| 94 |
def compute_from_payload(
|
| 95 |
+
self,
|
| 96 |
+
payload,
|
| 97 |
+
max_iou: float = 0.5,
|
| 98 |
+
filters={},
|
| 99 |
+
recognition_thresholds=[0.3, 0.5, 0.8],
|
| 100 |
+
area_ranges_tuples=None, # Optional parameter
|
| 101 |
+
debug: bool = False,
|
| 102 |
+
):
|
| 103 |
+
"""
|
| 104 |
+
Call the required functions to compute the metrics and return it.
|
| 105 |
+
|
| 106 |
+
Returns:
|
| 107 |
+
dict: A dictionary containing the computed metrics based on the provided area in the area_ranges_tuples,
|
| 108 |
+
if a range area is provided it will be displayed in the output.
|
| 109 |
+
"""
|
| 110 |
+
return self.dummy_values(area_ranges_tuples)
|
| 111 |
+
|
| 112 |
def dummy_values(self, area_ranges_tuples=None):
|
| 113 |
"""Dummy randome values in the expected format that all new metrics need to return"""
|
| 114 |
|
| 115 |
# Use default ranges if none are provided
|
| 116 |
if area_ranges_tuples is None:
|
| 117 |
+
area_names = ["all", "small", "medium", "large"]
|
| 118 |
+
else:
|
| 119 |
+
area_names = list(area_ranges_tuples.keys())
|
| 120 |
+
|
|
|
|
|
|
|
|
|
|
| 121 |
# Generate random dummy values
|
| 122 |
def generate_random_values():
|
| 123 |
return {
|
| 124 |
"tp": random.randint(0, 100), # Random integer between 0 and 100
|
| 125 |
+
"fp": random.randint(0, 50), # Random integer between 0 and 50
|
| 126 |
+
"fn": random.randint(0, 50), # Random integer between 0 and 50
|
| 127 |
+
"precision": round(
|
| 128 |
+
random.uniform(0.5, 1.0), 2
|
| 129 |
+
), # Random float between 0.5 and 1.0
|
| 130 |
+
"recall": round(
|
| 131 |
+
random.uniform(0.5, 1.0), 2
|
| 132 |
+
), # Random float between 0.5 and 1.0
|
| 133 |
+
"f1": round(
|
| 134 |
+
random.uniform(0.5, 1.0), 2
|
| 135 |
+
), # Random float between 0.5 and 1.0
|
| 136 |
}
|
| 137 |
+
|
| 138 |
# Initialize output structure
|
| 139 |
+
dummy_output = {"model_1": {"overall": {}, "per_sequence": {"sequence_1": {}}}}
|
| 140 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
# Populate only the ranges specified in area_ranges_tuples with random values
|
| 142 |
+
for area_name in area_names:
|
| 143 |
+
dummy_output["model_1"]["overall"][area_name] = generate_random_values()
|
| 144 |
+
dummy_output["model_1"]["per_sequence"]["sequence_1"][
|
| 145 |
+
area_name
|
| 146 |
+
] = generate_random_values()
|
| 147 |
+
|
| 148 |
return dummy_output
|
| 149 |
|