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

draw labels on video media type as well #136

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
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
18 changes: 14 additions & 4 deletions plugins/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2117,11 +2117,16 @@ def _is_valid_csv_field(field):
return isinstance(field, fof._PRIMITIVE_FIELDS)


def _get_fields_with_type(view, type):
def _get_fields_with_type(view, type, media_type="image"):
get_field_schema = (
view.get_frame_field_schema
if media_type == fom.VIDEO
else view.get_field_schema
)
if issubclass(type, fo.Field):
return view.get_field_schema(ftype=type).keys()
return get_field_schema(ftype=type).keys()

return view.get_field_schema(embedded_doc_type=type).keys()
return get_field_schema(embedded_doc_type=type).keys()


def _get_export_types(view, export_type, allow_coercion=False):
Expand Down Expand Up @@ -2523,6 +2528,8 @@ def execute(self, ctx):
target = ctx.params.get("target", None)
output_dir = _parse_path(ctx, "output_dir")
label_fields = ctx.params.get("label_fields", None)
if ctx.dataset.media_type == fom.VIDEO:
label_fields = [f"frames.{field}" for field in label_fields]
overwrite = ctx.params.get("overwrite", False)

target_view = _get_target_view(ctx, target)
Expand Down Expand Up @@ -2573,7 +2580,10 @@ def _draw_labels_inputs(ctx, inputs):
target_view = _get_target_view(ctx, target)

label_field_choices = types.Dropdown(multiple=True)
for field in _get_fields_with_type(target_view, fo.Label):
label_fields = _get_fields_with_type(
target_view, fo.Label, media_type=ctx.dataset.media_type
)
for field in label_fields:
label_field_choices.add_choice(field, label=field)

inputs.list(
Expand Down