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

Adding support for writing transformed images/videos to new location/field #2007

Merged
merged 4 commits into from
Aug 19, 2022

Conversation

brimoor
Copy link
Contributor

@brimoor brimoor commented Aug 19, 2022

Small enhancement that adds support for optionally writing transformed images/videos to a new output location, and storing the resulting filepaths in a new field.

This new syntax is useful, for example, for quickly generating thumbnail images for a dataset.

Python examples

import shutil

import fiftyone as fo
import fiftyone.zoo as foz
import fiftyone.utils.image as foui
import fiftyone.utils.video as fouv

# Image example
dataset = foz.load_zoo_dataset("quickstart")

foui.transform_images(
    dataset,
    size=(-1, 64),
    output_field="thumbnail_path",
    output_dir="/tmp/thumbnails",
    rel_dir=fo.config.dataset_zoo_dir,
)

print(dataset.select_fields("thumbnail_path").first())

# Video example
dataset = foz.load_zoo_dataset("quickstart-video")

fouv.transform_videos(
    dataset,
    size=(-1, 128),
    output_field="thumbnail_path",
    output_dir="/tmp/thumbnails",
    rel_dir=fo.config.dataset_zoo_dir,
)

print(dataset.select_fields("thumbnail_path").first())

# Cleanup
shutil.rmtree("/tmp/thumbnails")

CLI examples

ZOO_DIR=$(fiftyone config dataset_zoo_dir)

# Image example
fiftyone zoo datasets load quickstart

fiftyone utils transform-images quickstart \
    --max-size='-1,64' \
    --output-field thumbnail_path \
    --output-dir /tmp/thumbnails \
    --rel-dir $ZOO_DIR

ls -lah $ZOO_DIR/quickstart/data | head

# Video example
fiftyone zoo datasets load quickstart-video

fiftyone utils transform-videos quickstart-video \
    --max-size='-1,128' \
    --output-field thumbnail_path \
    --output-dir /tmp/thumbnails \
    --rel-dir $ZOO_DIR

ls -lah $ZOO_DIR/quickstart-video/data | head

# Cleanup
fiftyone datasets delete quickstart
fiftyone datasets delete quickstart-video
rm -rf /tmp/thumbnails

@brimoor brimoor added the enhancement Code enhancement label Aug 19, 2022
@brimoor brimoor requested a review from a team August 19, 2022 13:33
@brimoor brimoor self-assigned this Aug 19, 2022
Copy link
Contributor

@benjaminpkane benjaminpkane left a comment

Choose a reason for hiding this comment

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

LGTM

@brimoor brimoor merged commit e4b1c3b into develop Aug 19, 2022
@brimoor brimoor deleted the feature/transform-utils branch August 19, 2022 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Code enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants