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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callable plugins and delegated SDK execution #98

Merged
merged 6 commits into from Dec 21, 2023
Merged

Callable plugins and delegated SDK execution #98

merged 6 commits into from Dec 21, 2023

Conversation

brimoor
Copy link
Contributor

@brimoor brimoor commented Dec 11, 2023

Change log

  • Adds a new @voxel51/utils/delegate operator that allows for programmatically delegating execution of an arbitrary function call that can be expressed in any of the following forms:
    • Execute an arbitrary function: fcn(*args, **kwargs)
    • Apply a function to a dataset or view: fcn(dataset_or_view, *args, **kwargs)
    • Call an instance method of a dataset or view: dataset_or_view.fcn(*args, **kwargs)
  • Adds some __call__ implementations to common operators for which SDK-based execution is useful
    • I thought about adding more __call__ methods, but pretty much every remaining builtin @voxel51/XXX operation boils down to a single function call that can be accomplished via @voxel51/utils/delegate 馃挭

Corresponding public-facing documentation is in voxel51/fiftyone#3939.

Setup

# Launch a delegated execution service
fiftyone delegated launch

@voxel51/utils/delegate

import fiftyone as fo
import fiftyone.operators as foo
import fiftyone.zoo as foz

dataset = foz.load_zoo_dataset("quickstart")
delegate = foo.get_operator("@voxel51/utils/delegate")

# Compute metadata
delegate("compute_metadata", dataset=dataset)

# Compute visualization
delegate(
    "fiftyone.brain.compute_visualization",
    dataset=dataset,
    brain_key="img_viz",
)

# Export a view
delegate(
    "export",
    view=dataset.to_patches("ground_truth"),
    export_dir="/tmp/patches",
    dataset_type="fiftyone.types.ImageClassificationDirectoryTree",
    label_field="ground_truth",
)

# Load the exported patches into a new dataset
delegate(
    "fiftyone.Dataset.from_dir",
    dataset_dir="/tmp/patches",
    dataset_type="fiftyone.types.ImageClassificationDirectoryTree",
    label_field="ground_truth",
    name="patches",
    persistent=True,
)

@voxel51/io/import_samples

import os

import fiftyone as fo
import fiftyone.operators as foo
import fiftyone.zoo as foz

quickstart = foz.load_zoo_dataset("quickstart")

# A directory of images
images_dir = os.path.dirname(quickstart.first().filepath)

# A file of corresponding labels
labels_path = "/tmp/labels.json"
quickstart.export(
    dataset_type=fo.types.COCODetectionDataset,
    labels_path=labels_path,
    label_field="ground_truth",
    abs_paths=True,
)

dataset = fo.Dataset()
import_samples = foo.get_operator("@voxel51/io/import_samples")

# Import media
import_samples(
    dataset,
    data_path=images_dir,
    tags="quickstart",
    delegate=True,
)

# Import labels
import_samples(
    dataset,
    dataset_type=fo.types.COCODetectionDataset,
    labels_path=labels_path,
    label_field="ground_truth",
    label_types="detections",
    delegate=True,
)

@voxel51/io/export_samples

import fiftyone as fo
import fiftyone.operators as foo
import fiftyone.zoo as foz

dataset = foz.load_zoo_dataset("quickstart")
export_samples = foo.get_operator("@voxel51/io/export_samples")

# Export labels
export_samples(
    dataset,
    dataset_type=fo.types.COCODetectionDataset,
    labels_path="/tmp/labels.json",
    label_field="ground_truth",
    abs_paths=True,
)

# Export filepaths
export_samples(
    dataset,
    dataset_type=fo.types.CSVDataset,
    labels_path="/tmp/filepaths.csv",
    fields=["filepath"],
    abs_paths=True,
)

# Export a view
view = dataset.take(100)
export_samples(
    view,
    dataset_type=fo.types.FiftyOneDataset,
    export_dir="/tmp/quickstart-view",
    delegate=True,
)

@voxel51/utils/compute_metadata

import fiftyone as fo
import fiftyone.operators as foo
import fiftyone.zoo as foz

dataset = foz.load_zoo_dataset("quickstart")
compute_metadata = foo.get_operator("@voxel51/utils/compute_metadata")

# Run immediately
compute_metadata(dataset)

# Delegate computation and overwrite existing values
compute_metadata(dataset, overwrite=True, delegate=True)

@brimoor brimoor added the feature Work on a feature request label Dec 11, 2023
@brimoor brimoor requested a review from a team December 11, 2023 15:15
@brimoor brimoor self-assigned this Dec 11, 2023
@brimoor brimoor changed the title [WIP] Callable plugins Callable plugins Dec 18, 2023
@brimoor brimoor changed the title Callable plugins Callable plugins and delegated SDK execution Dec 18, 2023
@brimoor brimoor merged commit 43e0db5 into main Dec 21, 2023
@brimoor brimoor deleted the call branch December 21, 2023 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Work on a feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant