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

Small Upgrades #437

Merged
merged 3 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions eta/core/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# pragma pylint: enable=wildcard-import

from collections import defaultdict
import logging
import os

import numpy as np
Expand All @@ -32,6 +33,9 @@
import eta.core.utils as etau


logger = logging.getLogger(__name__)


def majority_vote_categorical_attrs(attrs, confidence_weighted=False):
'''Performs majority votes over the given attributes, which are assumed to
be `CategoricalAttribute`s.
Expand Down
17 changes: 17 additions & 0 deletions eta/core/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,23 @@ def build_active_schema(cls, image_labels):
schema.add_object_label(obj.label)
return schema

@classmethod
def from_video_labels_schema(cls, video_labels_schema):
'''Creates an ImageLabelsSchema from a VideoLabelsSchema.

Frame-level attributes of the VideoLabelsSchema are converted to
image-level attributes in the ImageLabelsSchema.

Args:
video_labels_schema: a VideoLabelsSchema

Returns:
an ImageLabelsSchema
'''
return cls(
attrs=video_labels_schema.frames,
objects=video_labels_schema.objects)

@classmethod
def from_dict(cls, d):
'''Constructs an ImageLabelsSchema from a JSON dictionary.
Expand Down
17 changes: 17 additions & 0 deletions eta/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2522,3 +2522,20 @@ class ExecutableRuntimeError(Exception):
def __init__(self, cmd, err):
message = "Command '%s' failed with error:\n%s" % (cmd, err)
super(ExecutableRuntimeError, self).__init__(message)


def validate_type(obj, expected_type):
'''Validates an object's type against an expected type.

Args:
obj: the python object to validate
expected_type: the type that `obj` must be (via `isinstance`)

Raises:
TypeError: if `obj` is not of `expected_type`
'''
if not isinstance(obj, expected_type):
raise TypeError(
"Unexpected argument type:\n\tExpected: %s\n\tActual: %s"
% (get_class_name(expected_type), get_class_name(obj))
)
17 changes: 17 additions & 0 deletions eta/core/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,23 @@ def attributes(self):
'''
return ["attrs", "frames", "objects", "events"]

@classmethod
def from_image_labels_schema(cls, image_labels_schema):
'''Creates a VideoLabelsSchema from an ImageLabelsSchema.

Image-level attributes of the ImageLabelsSchema are converted to
frame-level attributes in the VideoLabelsSchema.

Args:
image_labels_schema: an ImageLabelsSchema

Returns:
a VideoLabelsSchema
'''
return cls(
frames=image_labels_schema.attrs,
objects=image_labels_schema.objects)

@classmethod
def build_active_schema_for_frame(cls, frame_labels):
'''Builds a VideoLabelsSchema that describes the active schema of the
Expand Down