-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
59 lines (50 loc) · 1.75 KB
/
__init__.py
File metadata and controls
59 lines (50 loc) · 1.75 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
import fiftyone as fo
import fiftyone.operators as foo
from fiftyone.operators import types
import fiftyone.brain as fob
class DimensionalityReduction(foo.Operator):
@property
def config(self):
return foo.OperatorConfig(
name="dimensionality_reduction",
label="Dimensionality reduction",
description="Performs dimensionality reduction algorithm (UMAP) on selected subset of samples in FiftyOne",
allow_delegated_execution=True,
allow_immediate_execution=True,
default_choice_to_delegated=True,
)
def resolve_input(self, ctx):
inputs = types.Object()
prop = inputs.str(
"embeddings_field",
required=True,
label="Pre-computed embeddings field name",
)
view = types.View(label="Compute visualization")
return types.Property(inputs, view=view)
def resolve_placement(self, ctx):
return types.Placement(
types.Places.SAMPLES_GRID_ACTIONS,
types.Button(
label="Filter by float field",
icon="insights",
prompt=True,
),
)
def execute(self, ctx):
view = ctx.dataset.view()
embeddings_field = ctx.params["embeddings_field"]
tag_names = view.distinct("tags")
brain_key = "tags_" + ("_").join(tag_names) + "_dimensionality_reduction"
fob.compute_visualization(
view,
embeddings=embeddings_field,
method="umap",
brain_key=brain_key,
create_index=True,
num_dims=2,
overwrite=True,
)
return {}
def register(plugin):
plugin.register(DimensionalityReduction)