Skip to content
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

Add support for remote zoo model parameters #201

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions plugins/zoo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
|
"""
from collections import defaultdict
from packaging.version import Version

import fiftyone as fo
import fiftyone.operators as foo
Expand Down Expand Up @@ -537,10 +538,18 @@ def execute(self, ctx):

target_view = _get_target_view(ctx, target)

# @todo can remove this if we require `fiftyone>=1.4.0`
kwargs = {}
if Version(fo.__version__) >= Version("1.4.0"):
zoo_model = foz.get_zoo_model(model)
if isinstance(zoo_model, foz.RemoteZooModel):
kwargs = ctx.params.get("remote_params", {})
zoo_model._parse_parameters(ctx, kwargs)

if source is not None:
model = foz.load_zoo_model(source, model_name=model)
model = foz.load_zoo_model(source, model_name=model, **kwargs)
else:
model = foz.load_zoo_model(model)
model = foz.load_zoo_model(model, **kwargs)

# No multiprocessing allowed when running synchronously
if not ctx.delegated:
Expand Down Expand Up @@ -828,6 +837,14 @@ def _apply_zoo_model_inputs(ctx, inputs):
view=embeddings_field_choices,
)
else:
# @todo can remove this if we require `fiftyone>=1.4.0`
if Version(fo.__version__) >= Version("1.4.0"):
if isinstance(zoo_model, foz.RemoteZooModel):
obj = types.Object()
zoo_model._get_parameters(ctx, obj)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why _get_parameters() instead of get_parameters() mostly curious...?

I would rather have:

zoo_inputs = zoo_model.resolve_input(ctx) # returns a types.Property()

Which would be more consistent IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to have consistency too, but the issue is that resolve_input() returns a types.Property while in this situation, we don't want to define an entire form but rather inject a few parameters into an existing form.

Note that we just shipped a similar pattern for EvaluationMetric operators. Example usage here.

I'm definitely open to alternatives here, including changing the interface for evaluation metrics. Just not sure what to do! What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'm an idiot, we could just do this couldn't we 🤦

prop = zoo_model.resolve_input(ctx)
inputs.add_property("remote_params", prop)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ritch okay switched to using resolve_input() here and here

if len(obj.properties) > 0:
inputs.define_property("remote_params", obj)

label_field_choices = types.AutocompleteView()
for field in _get_fields_with_type(target_view, fo.Label):
label_field_choices.add_choice(field, label=field)
Expand Down