Skip to content

Instantly share code, notes, and snippets.

@ritch
Created June 10, 2022 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ritch/d59747885c5a26c194a720ff854e400c to your computer and use it in GitHub Desktop.
Save ritch/d59747885c5a26c194a720ff854e400c to your computer and use it in GitHub Desktop.
Fiftyone Media Fields Example
import os
import shutil
import fiftyone as fo
import fiftyone.zoo as foz
import fiftyone.utils.image as foui
fo.core.dataset.delete_non_persistent_datasets()
exampleName = 'thumbnail-example'
exampleDir = "/tmp/quickstart"
dataset = foz.load_zoo_dataset("quickstart")
shutil.rmtree(exampleDir)
if fo.core.dataset.dataset_exists(exampleName):
fo.core.dataset.delete_dataset(exampleName)
# # Export to a new place to avoid messing up zoo dataset
dataset.export(
export_dir=exampleDir,
dataset_type=fo.types.FiftyOneDataset,
)
dataset2 = fo.Dataset.from_dir(
# name=exampleName,
dataset_dir=exampleDir,
dataset_type=fo.types.FiftyOneDataset,
)
# Generate some thumnbnails
for sample in dataset2.iter_samples(progress=True):
root, ext = os.path.splitext(sample.filepath)
sample["thumnbnail_path"] = root + "-thumbnail" + ext
foui.transform_image(sample.filepath, sample.thumnbnail_path, size=(128, -1))
sample.save()
# Here's a way that interacting with the `media_fields` might work
dataset2.app_config.media_fields.append("thumnbnail_path")
dataset2.app_config.grid_media_field = "thumnbnail_path"
dataset2.save()
# dataset2.compute_metadata(overwrite=True)
session = fo.launch_app(dataset2)
session.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment