voxel51 / fiftyone-brain

Open source AI/ML capabilities for the FiftyOne ecosystem
https://fiftyone.ai/brain.html
Apache License 2.0
128 stars 3 forks source link

Adding support for providing custom models to uniqueness method #70

Closed brimoor closed 3 years ago

brimoor commented 3 years ago

Adds support for providing an arbitrary Model that exposes embeddings to compute_uniqueness():

Example usage

Samples

import fiftyone as fo
import fiftyone.zoo as foz
import fiftyone.brain as fob

dataset = foz.load_zoo_dataset("quickstart")

# Default model
fob.compute_uniqueness(
    dataset,
    uniqueness_field="uniqueness_brain",
)

# Custom Torch model
model = foz.load_zoo_model("inception-v3-imagenet-torch")
fob.compute_uniqueness(
    dataset, uniqueness_field="uniqueness_torch", model=model, batch_size=12
)

# Custom TF model
model = foz.load_zoo_model("resnet-v2-50-imagenet-tf1")
fob.compute_uniqueness(
    dataset, uniqueness_field="uniqueness_tf", model=model, batch_size=12
)

Patches

import fiftyone as fo
import fiftyone.zoo as foz
import fiftyone.brain as fob

dataset = foz.load_zoo_dataset("quickstart")

# Default model
fob.compute_uniqueness(
    dataset,
    roi_field="ground_truth",
    uniqueness_field="uniqueness_roi",
)

# Custom Torch model
model = foz.load_zoo_model("inception-v3-imagenet-torch")
fob.compute_uniqueness(
    dataset,
    roi_field="ground_truth",
    uniqueness_field="uniqueness_roi_torch",
    model=model,
    batch_size=12,
)

# Custom TF model
model = foz.load_zoo_model("resnet-v2-50-imagenet-tf1")
fob.compute_uniqueness(
    dataset,
    roi_field="ground_truth",
    uniqueness_field="uniqueness_roi_tf",
    model=model,
    batch_size=12,
)

session = fo.launch_app(dataset)