-
Notifications
You must be signed in to change notification settings - Fork 4
Fix: Add transformers for videos and bounding boxes #720
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
Open
ad-claw000
wants to merge
41
commits into
develop
Choose a base branch
from
fix/issue-335
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
5aceeb7
feat: Add transformers for videos and bounding boxes
ad-claw000 7c2d8ce
Fix pre-commit failures and remove optional dependencies from transfo…
ad-claw000 6278058
Fix: Address transformer PR review comments
ad-claw000 d0d7eb7
fix(transformers): evaluate annotation counts dynamically per transac…
ad-claw000 6e8010b
Fix pre-commit issues
ad-claw000 ab6958d
fix(transformers): evaluate image and video counts dynamically per tr…
ad-claw000 cfc08ad
Fix: Address review comments on transformers
ad-claw000 5c3f442
fix(transformers): remove unused _add_image_index and compute dynamic…
ad-claw000 30721e5
fix: apply autopep8 formatting
d28a4fd
Fix remaining unused variable and unused index review comments
ad-claw000 32f1400
Merge branch 'develop' into fix/issue-335
luisremis 871c955
Merge remote-tracking branch 'origin/develop' into fix/issue-335
ad-claw000 1e2f6a7
fix: lazily initialize descriptor sets on first AddImage in getitem
ad-claw000 cf75c40
fix: lazily initialize descriptor sets on first AddImage in getitem f…
ad-claw000 8d37ab8
fix(transformers): avoid duplicate embedding generation for the first…
ad-claw000 02b8fa2
style: fix autopep8 formatting in facenet_pytorch_embeddings.py
ad-claw000 f68a079
fix(transformers): restore _add_image_index for backward compat and a…
ad-claw000 65e6c26
Merge branch 'develop' into fix/issue-335
luisremis 1f30391
Merge remote-tracking branch 'origin/develop' into fix/issue-335
ad-claw000 f845763
test: add coverage for ImageProperties, clip, and facenet transformers
ad-claw000 f5b565e
test: remove unused sys import in test_Transformers.py
ad-claw000 b59526f
fix: set _descriptorset_initialized only on success or if exists
ad-claw000 f202783
test: add more unit tests for new transformer features
ad-claw000 3bb502a
fix: avoid mutating traceback in logger.exception
ad-claw000 cd2cd16
fix: run pre-commit autopep8 to resolve CI failure
ad-claw000 00cb81d
test: mock clip.generate_embedding to return float32 bytes
ad-claw000 d95e292
test: add placeholder blobs for image/video commands in test data
ad-claw000 340b007
fix: address pre-commit formatting issues in test_Transformers.py
ad-claw000 56ae22b
Merge remote-tracking branch 'origin/develop' into fix/issue-335
ad-claw000 339e593
test: add tests for descriptor initialization retries
ad-claw000 c7f5266
test: update mocked descriptor set name to match default in FacenetPy…
ad-claw000 0a49c19
Merge branch 'develop' into fix/issue-335
luisremis 8789927
fix: make common_properties and bounding_box_properties true no-ops w…
ad-claw000 28c8592
fix(ci): fix EACCES permission denied by making teardown chmod robust
ad-claw000 b5df355
fix: address review comments on clip/facenet embeddings and run_test_…
ad-claw000 a5df6fd
test: assert AddDescriptor is omitted on initialization failure
ad-claw000 38b625b
test: add tests for early return and exception handling
ad-claw000 7658971
test: add exception handling and explicit id tests for transformers
ad-claw000 30ba71e
fix: address review comments on PR #720
ad-claw000 5379c92
test: update image properties exception handling test
ad-claw000 52ea1e1
fix: address review comments on exception handling in transformers
ad-claw000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from .transformer import Transformer | ||
| from .common_properties import CommonProperties | ||
| from .image_properties import ImageProperties | ||
| from .video_properties import VideoProperties | ||
| from .bounding_box_properties import BoundingBoxProperties | ||
|
|
||
| __all__ = [ | ||
| "Transformer", | ||
| "CommonProperties", | ||
| "ImageProperties", | ||
| "VideoProperties", | ||
| "BoundingBoxProperties", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| from aperturedb.transformers.transformer import Transformer | ||
| from aperturedb.Subscriptable import Subscriptable | ||
| import logging | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class BoundingBoxProperties(Transformer): | ||
| """ | ||
| This computes bounding box and polygon properties and adds them to the metadata. | ||
| """ | ||
|
|
||
| def __init__(self, data: Subscriptable, **kwargs) -> None: | ||
| super().__init__(data, **kwargs) | ||
| self.annotation_source = kwargs.get("annotation_source", "coco") | ||
| self.annotation_mode = kwargs.get("annotation_mode", "auto") | ||
|
|
||
| def getitem(self, subscript): | ||
| if not (self.annotation_source or self.annotation_mode): | ||
| return self.data[subscript] | ||
|
|
||
| x = self.data[subscript] | ||
| try: | ||
| for cmd_dict in x[0]: | ||
| cmd_name = list(cmd_dict.keys())[0] | ||
| if cmd_name in ["AddBoundingBox", "AddPolygon"]: | ||
| src_properties = cmd_dict[cmd_name].setdefault( | ||
| "properties", {}) | ||
| if self.annotation_source: | ||
| src_properties["annotation_source"] = self.annotation_source | ||
| if self.annotation_mode: | ||
| src_properties["annotation_mode"] = self.annotation_mode | ||
| except Exception as e: | ||
| logger.exception( | ||
| "Error applying bounding box properties", stack_info=True) | ||
|
|
||
| return x | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| from aperturedb.transformers.transformer import Transformer | ||
| from aperturedb.Subscriptable import Subscriptable | ||
|
|
||
| import logging | ||
| import uuid | ||
| import hashlib | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class VideoProperties(Transformer): | ||
| """ | ||
| This computes some video properties and adds them to the metadata. | ||
| """ | ||
|
|
||
| def __init__(self, data: Subscriptable, **kwargs) -> None: | ||
| super().__init__(data, **kwargs) | ||
| utils = self.get_utils() | ||
|
|
||
| if "adb_data_source" not in utils.get_indexed_props("_Video"): | ||
| utils.create_entity_index("_Video", "adb_data_source") | ||
|
|
||
| def getitem(self, subscript): | ||
| x = self.data[subscript] | ||
| blob_index = 0 | ||
| for cmd_dict in x[0]: | ||
| cmd_name = list(cmd_dict.keys())[0] | ||
| try: | ||
| if cmd_name == "AddVideo": | ||
| src_properties = cmd_dict["AddVideo"].setdefault( | ||
| "properties", {}) | ||
| # Compute the dynamic properties and apply them to metadata | ||
| src_properties["adb_video_size"] = len(x[1][blob_index]) | ||
| src_properties["adb_video_sha256"] = hashlib.sha256( | ||
| x[1][blob_index]).hexdigest() | ||
|
|
||
| src_properties["adb_video_id"] = str( | ||
| src_properties["id"] if "id" in src_properties else uuid.uuid4().hex) | ||
|
|
||
|
ad-claw000 marked this conversation as resolved.
|
||
| except Exception as e: | ||
| # Importantly, do not raise an exception here, since it will kill ingestion. | ||
| # Create a log message instead, for post-mortem analysis. | ||
| logger.exception( | ||
| "Error applying video properties", stack_info=True) | ||
|
|
||
| if cmd_name in ["AddImage", "AddDescriptor", "AddVideo", "AddBlob"]: | ||
| blob_index += 1 | ||
|
|
||
| return x | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.