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

add support for collection overlays #5289

Merged
merged 8 commits into from
Dec 18, 2024

Conversation

sashankaryal
Copy link
Contributor

@sashankaryal sashankaryal commented Dec 17, 2024

We don't have a precedent for sources in labels accounting for collection label types like Detections. This PR adds support for that.

Summary by CodeRabbit

  • New Features

    • Enhanced handling of overlay data processing with new parameters for improved flexibility.
    • Updated media fields related to detections for better metadata retrieval.
  • Bug Fixes

    • Improved error handling during overlay image fetching and decoding processes.
  • Refactor

    • Streamlined functions for additional media fields and detection handling.
    • Adjusted function signatures for better structure in media field handling.

@sashankaryal sashankaryal changed the base branch from develop to release/v1.2.0 December 17, 2024 20:46
@sashankaryal sashankaryal self-assigned this Dec 17, 2024
Copy link
Contributor

coderabbitai bot commented Dec 17, 2024

Caution

Review failed

The head commit changed during the review from 5d6f683 to bc44e3e.

Walkthrough

The pull request introduces modifications to two files: disk-overlay-decoder.ts and metadata.py. In disk-overlay-decoder.ts, the decodeOverlayOnDisk function is enhanced with a new optional parameter overlayCollectionProcessingParams, allowing more flexible overlay collection processing. The changes improve the function's ability to handle specific overlay scenarios by refining conditional checks and adjusting image source determination. In metadata.py, the metadata handling is updated to better support additional media fields, particularly for detections, with improved field retrieval and URL creation logic.

Changes

File Change Summary
app/packages/looker/src/worker/disk-overlay-decoder.ts - Added overlayCollectionProcessingParams to function signature
- Refined conditional checks for detection processing
- Updated overlay image source determination
- Modified loop iteration method
fiftyone/server/metadata.py - Updated _ADDITIONAL_MEDIA_FIELDS to include detection types
- Modified _get_additional_media_fields to return expanded tuple
- Enhanced _create_media_urls to handle detection fields
- Replaced custom _deep_get with pydash.get

Suggested labels

app

Suggested reviewers

  • benjaminpkane

Poem

🐰 In the realm of bits and bytes so bright,

Overlays dance with newfound might,

Masks decoded, sources clear,

Metadata singing loud and dear,

Code rabbit's magic takes its flight! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sashankaryal sashankaryal changed the title fix detection.mask_path sources bug add support for collection overlays Dec 17, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f704079 and 89d1853.

📒 Files selected for processing (2)
  • app/packages/looker/src/worker/disk-overlay-decoder.ts (2 hunks)
  • fiftyone/server/metadata.py (8 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/looker/src/worker/disk-overlay-decoder.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

🔇 Additional comments (10)
fiftyone/server/metadata.py (7)

15-15: Ensure 'pydash' is included in project dependencies

The pydash library is being imported. Please verify that it is listed in your project's dependencies (e.g., in setup.py or requirements.txt) to avoid import errors.


35-36: Addition of 'mask_path' for Detection classes is correct

The 'mask_path' field is appropriately added for fol.Detection and fol.Detections in _ADDITIONAL_MEDIA_FIELDS, enabling proper handling of mask paths for detection labels.


74-78: Unpacking additional fields from _get_additional_media_fields

The unpacking of opm_field, detections_fields, and additional_fields from _get_additional_media_fields(collection) aligns with the updated return values of the function.


400-400: Update function signature to include detections_fields

The addition of the detections_fields parameter to _create_media_urls ensures that detection masks are processed correctly.


408-424: Properly handle detection masks in _create_media_urls

The added code correctly iterates over detection fields to include individual detection mask paths in media_fields. This allows for accurate retrieval of mask paths for each detection object.


442-442: Use pydash.get for nested field access

Using get(sample, field) from pydash facilitates safe retrieval of nested fields, which is beneficial for handling dynamic or deeply nested sample structures.


Line range hint 464-487: Correctly collect detections_fields in _get_additional_media_fields

The function now separates detections_fields from other additional fields, allowing specialized processing of detection masks. This enhances the modularity and readability of the code.

app/packages/looker/src/worker/disk-overlay-decoder.ts (3)

28-31: Add optional parameters maskTargetsBuffers and overlayCollectionProcessingParams

Including maskTargetsBuffers and overlayCollectionProcessingParams as optional parameters in decodeOverlayOnDisk increases the function's flexibility to handle overlay collections effectively.


34-50: Process detections within DETECTIONS labels correctly

The updated logic correctly handles the DETECTIONS class by iterating over each detection and recursively calling decodeOverlayOnDisk with appropriate parameters. This ensures that each detection's overlay is processed individually.


85-93: Safely construct source for overlay images

The conditional construction of source using overlayCollectionProcessingParams correctly accesses the specific overlay path for each detection. Ensure that the key exists in sources to prevent undefined values.

app/packages/looker/src/worker/disk-overlay-decoder.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
fiftyone/server/metadata.py (2)

408-424: Consider optimizing the detections processing logic

The current implementation could be improved in several ways:

  1. Nested get calls could be simplified
  2. The loop could be optimized for better performance
  3. Error handling could be enhanced

Consider this optimization:

    if detections_fields is not None:
        for field in detections_fields:
-            detections = get(sample, field)
-
-            if not detections:
-                continue
-
-            detections_list = get(detections, "detections")
-
-            if not detections_list or len(detections_list) == 0:
-                continue
-
-            len_detections = len(detections_list)
-
-            for i in range(len_detections):
-                media_fields.append(f"{field}.detections[{i}].mask_path")
+            detections_list = get(sample, f"{field}.detections", [])
+            media_fields.extend(
+                f"{field}.detections[{i}].mask_path"
+                for i in range(len(detections_list))
+            )

This optimization:

  1. Reduces nested get calls to a single call with default value
  2. Uses list comprehension for better performance
  3. Handles missing or malformed data gracefully through the default value

Line range hint 467-490: Consider adding type hints and updating docstring

The function implementation looks good, but could benefit from better documentation:

  1. Add return type hints:
def _get_additional_media_fields(
    collection: SampleCollection,
-) -> t.List[str]:
+) -> t.Tuple[t.Optional[str], t.Optional[t.List[str]], t.List[str]]:
  1. Add docstring explaining the return values:
"""
Get additional media fields from the collection.

Args:
    collection: A SampleCollection instance

Returns:
    A tuple containing:
    - opm_field: Optional field name for orthographic projection metadata
    - detections_fields: Optional list of detection field names
    - additional: List of additional media field paths
"""
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 89d1853 and d2038b0.

📒 Files selected for processing (1)
  • fiftyone/server/metadata.py (8 hunks)
🔇 Additional comments (2)
fiftyone/server/metadata.py (2)

15-15: LGTM! Good choice using pydash.get for safe nested dictionary access

The addition of Detection and Detections types to _ADDITIONAL_MEDIA_FIELDS aligns well with the PR objective to support collection overlays. Using pydash.get is a safer approach for accessing nested dictionary values.

Also applies to: 35-36


74-78: LGTM! Clean implementation of detection fields support

The changes maintain backward compatibility while elegantly adding support for detection fields through proper tuple unpacking and parameter passing.

Also applies to: 87-87

@sashankaryal sashankaryal requested a review from a team December 17, 2024 21:56
// example: for detections, we need to access the source from the parent label
// like: if field is "prediction_masks", we're trying to get "predictiion_masks.detections[INDEX].mask"
source =
sources[
Copy link
Contributor

Choose a reason for hiding this comment

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

any concern that the key we're constructing here doesn't exist on sources?

Copy link
Contributor Author

@sashankaryal sashankaryal Dec 18, 2024

Choose a reason for hiding this comment

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

in which case it'd return undefined. In fact, it won't exist in OSS

a = {}

assert typeof a['foo.bar'] === 'undefined';

Copy link
Contributor

Choose a reason for hiding this comment

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

my eyes told me the ]. deref was outside the key so thought we might be derefing an undefined. my mistake 🙏

@sashankaryal sashankaryal merged commit 2115658 into release/v1.2.0 Dec 18, 2024
14 checks passed
@sashankaryal sashankaryal deleted the fix/detections-sources branch December 18, 2024 01:34
This was referenced Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants