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

Segment Anything: supported bounding box input #8270

Merged
merged 12 commits into from
Aug 12, 2024
Merged

Conversation

bsekachev
Copy link
Member

@bsekachev bsekachev commented Aug 7, 2024

Motivation and context

Peek 2024-08-07 11-33

Resolved #6281

How has this been tested?

Checklist

  • I submit my changes into the develop branch
  • I have created a changelog fragment
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • I have linked related issues (see GitHub docs)
  • I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

@bsekachev bsekachev requested a review from Marishka17 as a code owner August 7, 2024 08:31
Copy link
Contributor

coderabbitai bot commented Aug 7, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This update enhances the Segment Anything functionality by introducing support for bounding box segmentation, allowing for more precise user control. It refines interaction handling and state management across various components, promoting asynchronous operations and improved UI responsiveness. The updates facilitate better annotation processes, making tools more flexible and user-friendly while streamlining workflows in the application.

Changes

Files Change Summary
changelog.d/.../boris_support_sam_rect.md Introduced bounding box support for segmentation, enhancing user control and usability.
cvat-canvas/src/typescript/.../interactionHandler.ts Updated 'drawstop' event handler to include event parameter, refining interaction context and control logic.
cvat-core/src/core-types.ts Added optional properties to ModelParams and SerializedModel interfaces for box starting configuration.
cvat-core/src/ml-model.ts Introduced startWithBoxOptional property to MLModel for enhanced initialization options.
cvat-ui/src/actions/.../annotation-actions.ts Expanded interactWithCanvas function to include activeInteractorParameters, improving interaction logic.
cvat-ui/src/components/.../opencv-control.tsx Updated interaction logic; modified methods to return promises for asynchronous handling.
cvat-ui/src/components/.../tools-control.tsx Introduced startInteractingWithBox state; modified method signatures for asynchronous management.
cvat-ui/src/components/.../styles.scss Added new CSS class .cvat-tools-interactor-setups to improve layout and styling.
cvat-ui/src/cvat-canvas-wrapper.ts Updated convertShapesForInteractor to accept shape type, refining shape processing logic.
cvat-ui/src/reducers/.../annotation-reducer.ts Improved state handling for drawing and interaction with updated payload structure.
cvat-ui/src/reducers/index.ts Added activeInteractorParameters to AnnotationState for enhanced interaction data management.
cvat/apps/lambda_manager/views.py Introduced startswith_box_optional for attribute parsing and simplified validation logic.
serverless/pytorch/.../function-gpu.yaml Added startswith_box_optional configuration to enhance interactor flexibility.
serverless/pytorch/.../function.yaml Similar addition of startswith_box_optional for improved usability of interactor configurations.

Poem

In fields where rabbits bound and play,
New features hop in bright array.
With bounding boxes, swift and neat,
Our tools now dance to a user’s beat!
So let us cheer, with joyful thump,
For changes that make our workflows jump! 🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@bsekachev bsekachev requested a review from nmanovic as a code owner August 7, 2024 08:31
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

Outside diff range, codebase verification and nitpick comments (2)
changelog.d/20240807_113114_boris_support_sam_rect.md (1)

1-4: Improve grammar and clarity in changelog entry.

The current entry is slightly unclear. Consider rephrasing for better readability.

- Segment Anything now supports starts from bounding box setting
+ Segment Anything now supports starting from a bounding box setting
cvat-ui/src/actions/annotation-actions.ts (1)

Function calls to repeatDrawShapeAsync do not handle the new parameter properly.

The function repeatDrawShapeAsync has been updated to incorporate checks for activeInteractorParameters. However, the call sites in the following files do not pass any parameters to it:

  • cvat-ui/src/containers/annotation-page/standard3D-workspace/controls-side-bar/controls-side-bar.tsx
  • cvat-ui/src/containers/annotation-page/standard-workspace/controls-side-bar/controls-side-bar.tsx

Please ensure that all function calls to repeatDrawShapeAsync properly handle the new parameter.

Analysis chain

Line range hint 1414-1439:
LGTM! But verify the function usage in the codebase.

The changes to incorporate checks for activeInteractorParameters are approved.

However, ensure that all function calls to repeatDrawShapeAsync properly handle the new parameter.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `repeatDrawShapeAsync` properly handle the new parameter.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type typescript -A 5 $'repeatDrawShapeAsync'

Length of output: 83


Script:

#!/bin/bash
# Description: Verify all function calls to `repeatDrawShapeAsync` properly handle the new parameter.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type ts -A 5 $'repeatDrawShapeAsync'

Length of output: 3837

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6e30164 and 4c32860.

Files selected for processing (14)
  • changelog.d/20240807_113114_boris_support_sam_rect.md (1 hunks)
  • cvat-canvas/src/typescript/interactionHandler.ts (2 hunks)
  • cvat-core/src/core-types.ts (2 hunks)
  • cvat-core/src/ml-model.ts (1 hunks)
  • cvat-ui/src/actions/annotation-actions.ts (3 hunks)
  • cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/opencv-control.tsx (6 hunks)
  • cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/tools-control.tsx (13 hunks)
  • cvat-ui/src/components/annotation-page/standard-workspace/styles.scss (1 hunks)
  • cvat-ui/src/cvat-canvas-wrapper.ts (2 hunks)
  • cvat-ui/src/reducers/annotation-reducer.ts (3 hunks)
  • cvat-ui/src/reducers/index.ts (1 hunks)
  • cvat/apps/lambda_manager/views.py (3 hunks)
  • serverless/pytorch/facebookresearch/sam/nuclio/function-gpu.yaml (1 hunks)
  • serverless/pytorch/facebookresearch/sam/nuclio/function.yaml (1 hunks)
Additional comments not posted (27)
cvat-ui/src/cvat-canvas-wrapper.ts (2)

27-27: LGTM! The filtering logic is correct.

The filtering logic correctly checks both the button and shapeType parameters.


Line range hint 17-27:
Ensure the new parameter type is always provided.

The function signature has been updated to include a new parameter type. Ensure that this parameter is always provided when the function is called.

Verification successful

Verification successful: The type parameter is always provided when calling the convertShapesForInteractor function.

  • Instances found in:
    • cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/tools-control.tsx
    • cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/opencv-control.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `convertShapesForInteractor` include the new `type` parameter.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type typescript -A 5 $'convertShapesForInteractor'

Length of output: 89


Script:

#!/bin/bash
# Description: Verify all function calls to `convertShapesForInteractor` include the new `type` parameter.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg -t ts -A 5 'convertShapesForInteractor'

Length of output: 4348

cvat-core/src/core-types.ts (2)

18-18: LGTM! The new property startWithBoxOptional is correctly added.

The new optional property startWithBoxOptional has been correctly added to the ModelParams interface.


53-53: LGTM! The new property startswith_box_optional is correctly added.

The new optional property startswith_box_optional has been correctly added to the SerializedModel interface.

serverless/pytorch/facebookresearch/sam/nuclio/function.yaml (1)

15-15: Enhancement: Added startswith_box_optional configuration

The new configuration option startswith_box_optional set to true enhances the flexibility of the interactor by allowing it to function without a starting box. This change improves usability in scenarios where a starting box is not required.

serverless/pytorch/facebookresearch/sam/nuclio/function-gpu.yaml (1)

15-15: Enhancement: Added startswith_box_optional configuration

The new configuration option startswith_box_optional set to true enhances the flexibility of the interactor by allowing it to function without a starting box. This change improves usability in scenarios where a starting box is not required.

cvat-core/src/ml-model.ts (1)

60-60: Enhancement: Added startWithBoxOptional property

The new property startWithBoxOptional enhances the flexibility of the MLModel class by allowing it to handle an optional starting box. This change improves the model's configurability and aligns with the new configuration option introduced in the YAML files.

cvat-ui/src/components/annotation-page/standard-workspace/styles.scss (1)

168-177: LGTM!

The new CSS class .cvat-tools-interactor-setups and its nested styles improve the layout and spacing of components related to tools interactor setups.

cvat-ui/src/reducers/index.ts (1)

740-740: LGTM!

The addition of the new optional property activeInteractorParameters to the AnnotationState interface enhances the functionality by allowing the state to store parameters related to the currently active interactor.

cvat-canvas/src/typescript/interactionHandler.ts (1)

Line range hint 196-211:
LGTM!

The changes to the event handling logic for the 'drawstop' event, including the event parameter and additional conditional logic, enhance the functionality by allowing interactions to be contextually dependent on the control key state.

cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/opencv-control.tsx (5)

22-22: Approved: Added import for ObjectState.

The addition of ObjectState is appropriate for managing object states within this component.


61-67: Updated DispatchToProps interface.

The changes to the DispatchToProps interface reflect a shift towards asynchronous handling of actions and a more streamlined approach to state management. The removal of methods like updateAnnotations and changeFrame suggests a simplification of the interface, while the introduction of asynchronous methods like createAnnotations and fetchAnnotations improves the component's responsiveness.


Line range hint 388-390: Approved: Updated onTracking method.

The updates streamline the logic for handling tracking interactions and improve error handling.


241-241: Approved: Updated convertShapesForInteractor function call.

The modification to accept a new parameter format likely reflects updates in how shapes are processed during interactions.

However, ensure that all usages of convertShapesForInteractor are updated to match the new parameter format.

Verification successful

Verified: All usages of convertShapesForInteractor match the new parameter format.

The function calls in opencv-control.tsx and tools-control.tsx have been updated consistently to reflect the new parameter format.

  • cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/opencv-control.tsx
  • cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/tools-control.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `convertShapesForInteractor` match the new parameter format.

# Test: Search for the function usage. Expect: Only occurrences of the new parameter format.
rg --type tsx -A 5 $'convertShapesForInteractor'

Length of output: 75


Script:

#!/bin/bash
# Description: Verify all usages of `convertShapesForInteractor` match the new parameter format.

# Test: Search for the function usage in all TypeScript files. Expect: Only occurrences of the new parameter format.
rg 'convertShapesForInteractor' -t ts -A 5

Length of output: 4348


587-591: Approved: Updated onInteractionStart method.

The update to onInteractionStart to utilize interactWithCanvas with additional parameters enhances the interaction model by allowing more detailed parameters to be passed during canvas interactions.

However, ensure that all usages of interactWithCanvas are updated to match the new parameter requirements.

cvat-ui/src/reducers/annotation-reducer.ts (2)

499-499: Approved: Updated state initialization for drawing.

Using defaultState.drawing instead of spreading state.drawing ensures that the drawing state resets to its default values whenever this part of the reducer is invoked, which is beneficial for scenarios requiring a fresh start.


Line range hint 933-943: Approved: Updated INTERACT_WITH_CANVAS case.

The inclusion of activeInteractorParameters in the payload structure allows the reducer to manage more detailed interaction data with the canvas, enhancing the functionality related to how interactions with the canvas are processed.

cvat/apps/lambda_manager/views.py (3)

197-197: Approved: Added startswith_box_optional attribute.

The addition of startswith_box_optional allows for the configuration of an optional behavior related to the startswith_box attribute, enhancing the flexibility of attribute parsing.


218-218: Approved: Updated to_dict method to include startswith_box_optional.

Including the startswith_box_optional attribute in the dictionary output ensures that this attribute is correctly represented in the method's output.


388-390: Approved: Simplified logic for pos_points and modified handling of obj_bbox.

The simplification of the logic for determining the value of pos_points and the modification of the handling of obj_bbox streamline the code by reducing conditional checks and enhancing clarity.

cvat-ui/src/actions/annotation-actions.ts (1)

1388-1398: LGTM! But verify the function usage in the codebase.

The changes to the function signature are approved.

However, ensure that all function calls to interactWithCanvas match the new signature.

cvat-ui/src/components/annotation-page/standard-workspace/controls-side-bar/tools-control.tsx (6)

147-147: LGTM!

The addition of the new state variable startInteractingWithBox is approved.


239-239: LGTM!

The initialization of the new state variable startInteractingWithBox in the constructor is approved.


481-482: LGTM!

The inclusion of the new parameter pos_boxes in the interaction data is approved.


1111-1131: LGTM!

The addition of the switch for startInteractingWithBox in the renderInteractorBlock method is approved.


1148-1159: LGTM!

The inclusion of the new parameter interactorParameters with startWithBox settings in the onClick handler is approved.


74-79: LGTM! But verify the function usage in the codebase.

The changes to the DispatchToProps interface to return promises are approved.

However, ensure that all function calls to these methods properly handle the asynchronous nature.

@codecov-commenter
Copy link

codecov-commenter commented Aug 7, 2024

Codecov Report

Attention: Patch coverage is 38.09524% with 13 lines in your changes missing coverage. Please review.

Project coverage is 83.37%. Comparing base (4dae854) to head (55a7be8).
Report is 2 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8270      +/-   ##
===========================================
- Coverage    83.39%   83.37%   -0.02%     
===========================================
  Files          390      390              
  Lines        41551    41560       +9     
  Branches      3861     3863       +2     
===========================================
+ Hits         34650    34651       +1     
- Misses        6901     6909       +8     
Components Coverage Δ
cvat-ui 79.67% <35.00%> (-0.04%) ⬇️
cvat-server 86.66% <100.00%> (+<0.01%) ⬆️

Copy link

@bsekachev bsekachev merged commit 10a5f66 into develop Aug 12, 2024
33 checks passed
@bsekachev bsekachev deleted the bs/support_sam_rect branch August 13, 2024 09:23
@cvat-bot cvat-bot bot mentioned this pull request Aug 13, 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.

Feature Request: Extend SAM Interaction in CVAT with Bounding Box Inputs
2 participants