-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
""" | ||
Example metrics. | ||
| Copyright 2017-2024, Voxel51, Inc. | ||
| `voxel51.com <https://voxel51.com/>`_ | ||
| | ||
""" | ||
import fiftyone as fo | ||
import fiftyone.operators as foo | ||
import fiftyone.operators.types as types | ||
|
||
|
||
class EvaluationMetric(foo.Operator): | ||
def get_parameters(self, ctx, inputs): | ||
pass | ||
|
||
def parse_parameters(self, ctx, params): | ||
pass | ||
|
||
def compute(self, samples, eval_key, results, **kwargs): | ||
raise NotImplementedError("Subclass must implement compute()") | ||
|
||
def get_fields(self, samples, eval_key): | ||
return [] | ||
|
||
def rename(self, samples, eval_key, new_eval_key): | ||
pass | ||
|
||
def cleanup(self, samples, eval_key): | ||
pass | ||
|
||
|
||
class ExampleMetric(EvaluationMetric): | ||
@property | ||
def config(self): | ||
return foo.OperatorConfig( | ||
name="example_metric", | ||
label="Example metric", | ||
description="This is an example metric", | ||
tags=["metric"], | ||
) | ||
|
||
def get_parameters(self, ctx, inputs): | ||
inputs.str("value", default="foo", required=True) | ||
|
||
def compute(self, samples, eval_key, results, value="foo"): | ||
dataset = samples._dataset | ||
metric_field = f"{eval_key}_example_metric" | ||
dataset.add_sample_field(metric_field, fo.StringField) | ||
samples.set_field(metric_field, value).save() | ||
return value | ||
|
||
def get_fields(self, samples, eval_key): | ||
metric_field = f"{eval_key}_example_metric" | ||
return [metric_field] | ||
|
||
def rename(self, samples, eval_key, new_eval_key): | ||
dataset = samples._dataset | ||
metric_field = f"{eval_key}_example_metric" | ||
new_metric_field = f"{new_eval_key}_example_metric" | ||
dataset.rename_sample_field(metric_field, new_metric_field) | ||
|
||
def cleanup(self, samples, eval_key): | ||
dataset = samples._dataset | ||
metric_field = f"{eval_key}_example_metric" | ||
dataset.delete_sample_field(metric_field, error_level=1) | ||
|
||
|
||
def register(p): | ||
p.register(ExampleMetric) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: "@voxel51/metric-examples" | ||
description: Example metrics | ||
version: 1.0.0 | ||
fiftyone: | ||
version: ">=1.2.0" | ||
url: https://github.com/voxel51/fiftyone-plugins/tree/main/plugins/metric-examples | ||
license: Apache 2.0 | ||
panels: | ||
- example_metric |