-
Notifications
You must be signed in to change notification settings - Fork 0
Code cleanup, README updates, interfaces for predictions and metric results #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop-v0.1.0
Are you sure you want to change the base?
Changes from all commits
6157ba1
62f0bd3
bc7803e
c210735
4da1f51
b6ea98b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,17 @@ | ||
| from .core import LuxonisEval | ||
| from .results import ( | ||
| EvaluationResult, | ||
| MetricResult, | ||
| MetricsResult, | ||
| MetricValues, | ||
| ThroughputResult, | ||
| ) | ||
|
|
||
| __all__ = ["LuxonisEval"] | ||
| __all__ = [ | ||
| "EvaluationResult", | ||
| "LuxonisEval", | ||
| "MetricResult", | ||
| "MetricsResult", | ||
| "MetricValues", | ||
| "ThroughputResult", | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,11 @@ | |
| from tabulate import tabulate | ||
| from tqdm.auto import tqdm | ||
|
|
||
| from luxonis_eval.core.results import ( | ||
| EvaluationResult, | ||
| ThroughputResult, | ||
| ) | ||
|
|
||
|
|
||
| class TQDMProgressAdapter(AbstractContextManager["TQDMProgressAdapter"]): | ||
| def __init__(self, description: str, total: int) -> None: | ||
|
|
@@ -79,45 +84,56 @@ def section( | |
| return [[centered, ""]] | ||
|
|
||
|
|
||
| def make_report_table( | ||
| engine_name: str, | ||
| model_name: str, | ||
| tp: dict[str, float | int], | ||
| results: list[tuple[str, dict[str, Any]]], | ||
| ) -> str: | ||
| def format_stage(name: str) -> str: | ||
| ms = float(tp[f"{name}_ms_per_sample"]) | ||
| total = float(tp["ms_per_sample"]) | ||
| pct = (ms / total * 100.0) if total else 0.0 | ||
| return f"{ms:5.2f} ms | {pct:4.1f}%" | ||
| def _format_stage_latency(name: str, throughput: ThroughputResult) -> str: | ||
| ms = float(getattr(throughput, f"{name}_ms_per_sample")) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why getattr here? |
||
| total = float(throughput.ms_per_sample) | ||
| pct = (ms / total * 100.0) if total else 0.0 | ||
| return f"{ms:5.2f} ms | {pct:4.1f}%" | ||
|
|
||
|
|
||
| def format_evaluation_result(result: EvaluationResult) -> str: | ||
| rows: list[list[str]] = [] | ||
|
|
||
| rows += section("SETTINGS") | ||
| rows += [ | ||
| ["Model", model_name], | ||
| ["Engine", str(engine_name).upper()], | ||
| ["Model", result.model_name], | ||
| ["Engine", str(result.engine).upper()], | ||
| ] | ||
|
|
||
| rows += section("PERFORMANCE") | ||
| rows += [ | ||
| ["Throughput", f"{tp['samples_per_s']:.2f} samples/s"], | ||
| ["End-to-end Latency", f"{tp['ms_per_sample']:.2f} ms/sample"], | ||
| [ | ||
| "Throughput", | ||
| f"{result.throughput.samples_per_s:.2f} samples/s", | ||
| ], | ||
| [ | ||
| "End-to-end Latency", | ||
| f"{result.throughput.ms_per_sample:.2f} ms/sample", | ||
| ], | ||
| ] | ||
|
|
||
| rows += section("STAGE BREAKDOWN", line_char="-") | ||
| rows += [ | ||
| ["Inference", format_stage("inference")], | ||
| ["Parsing", format_stage("parsing")], | ||
| ["Metric Update", format_stage("metric_update")], | ||
| ["Metric Compute", format_stage("metric_compute")], | ||
| ["Pipeline Overhead", format_stage("overhead")], | ||
| ["Inference", _format_stage_latency("inference", result.throughput)], | ||
| ["Parsing", _format_stage_latency("parsing", result.throughput)], | ||
| [ | ||
| "Metric Update", | ||
| _format_stage_latency("metric_update", result.throughput), | ||
| ], | ||
| [ | ||
| "Metric Compute", | ||
| _format_stage_latency("metric_compute", result.throughput), | ||
| ], | ||
| [ | ||
| "Pipeline Overhead", | ||
| _format_stage_latency("overhead", result.throughput), | ||
| ], | ||
| ] | ||
|
|
||
| rows += section("QUALITY") | ||
| for metric_name, result in results: | ||
| for metric_name, metric_values in result.metrics: | ||
| rows += section(metric_name, line_char="-") | ||
| for k, v in result.items(): | ||
| for k, v in metric_values.items(): | ||
| val = f"{v * 100:.2f}%" if isinstance(v, float) else str(v) | ||
| rows.append([str(k), val]) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
|
|
||
| MetricValues = dict[str, float] | ||
| MetricResult = tuple[str, MetricValues] | ||
| MetricsResult = list[MetricResult] | ||
|
|
||
|
|
||
| @dataclass(slots=True) | ||
| class ThroughputResult: | ||
| """End-to-end throughput and latency measurements.""" | ||
|
|
||
| elapsed_s: float | ||
| samples: int | ||
| samples_per_s: float | ||
| ms_per_sample: float | ||
| overhead_ms_per_sample: float | ||
| inference_ms_per_sample: float | ||
| parsing_ms_per_sample: float | ||
| metric_update_ms_per_sample: float | ||
| metric_compute_ms_per_sample: float | ||
|
|
||
|
Comment on lines
+10
to
+22
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a note: This will likely completely change when we introduce proper benchmarking but yeah, we can have it like this for the v0.1.0 of lux-eval |
||
|
|
||
| @dataclass(slots=True) | ||
| class EvaluationResult: | ||
| """Structured output returned by ``LuxonisEval.evaluate()``.""" | ||
|
|
||
| evaluator_name: str | ||
| engine: str | ||
| model_name: str | ||
| metrics: MetricsResult | ||
| throughput: ThroughputResult | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.evaluator_cfg.name is optional config item. So we should have a fallback since EvaluationResult expects string. We can have either empty string or if you can think of any other logical fallback string