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

Fixed ValueError: operands could not be broadcast together with shapes (X, ) (Y, ) #8179

Merged
merged 3 commits into from
Jul 18, 2024

Conversation

bsekachev
Copy link
Member

@bsekachev bsekachev commented Jul 17, 2024

Motivation and context

  1. Draw a skeleton track, go 10 frames forward, set a keyframe (press K shortcut)
  2. Save, export in CVAT for Images
  3. Get exception because one skeleton shape has N points and another one does not have points.

image

Stacktrace:

Traceback (most recent call last):
  File "/home/bsekachev/app.cvat.ai/cvat_enterprise/cvat/cvat/apps/dataset_manager/views.py", line 108, in export
    export_fn(db_instance.id, temp_file, dst_format,
  File "/home/bsekachev/app.cvat.ai/cvat_enterprise/cvat/cvat/apps/dataset_manager/task.py", line 888, in export_job
    job.export(f, exporter, host=server_url, save_images=save_images)
  File "/home/bsekachev/app.cvat.ai/cvat_enterprise/cvat/cvat/apps/dataset_manager/task.py", line 694, in export
    exporter(dst_file, temp_dir, job_data, **options)
  File "/home/bsekachev/app.cvat.ai/cvat_enterprise/cvat/cvat/apps/dataset_manager/formats/registry.py", line 36, in __call__
    f_or_cls(*args, **kwargs)
  File "/home/bsekachev/app.cvat.ai/cvat_enterprise/cvat/cvat/apps/dataset_manager/formats/cvat.py", line 1433, in _export_images
    _export_task_or_job(dst_file, temp_dir, instance_data,
  File "/home/bsekachev/app.cvat.ai/cvat_enterprise/cvat/cvat/apps/dataset_manager/formats/cvat.py", line 1396, in _export_task_or_job
    dump_task_or_job_anno(f, instance_data, anno_callback)
  File "/home/bsekachev/app.cvat.ai/cvat_enterprise/cvat/cvat/apps/dataset_manager/formats/cvat.py", line 1364, in dump_task_or_job_anno
    callback(dumper, instance_data)
  File "/home/bsekachev/app.cvat.ai/cvat_enterprise/cvat/cvat/apps/dataset_manager/formats/cvat.py", line 719, in dump_as_cvat_annotation
    for frame_annotation in annotations.group_by_frame(include_empty=True):
  File "/home/bsekachev/app.cvat.ai/cvat_enterprise/cvat/cvat/apps/dataset_manager/bindings.py", line 435, in group_by_frame
    anno_manager.to_shapes(self.stop, self._annotation_ir.dimension,
  File "/home/bsekachev/app.cvat.ai/cvat_enterprise/cvat/cvat/apps/dataset_manager/annotation.py", line 185, in to_shapes
    return shapes + tracks.to_shapes(end_frame,
  File "/home/bsekachev/app.cvat.ai/cvat_enterprise/cvat/cvat/apps/dataset_manager/annotation.py", line 442, in to_shapes
    for shape in TrackManager.get_interpolated_shapes(
  File "/home/bsekachev/app.cvat.ai/cvat_enterprise/cvat/cvat/apps/dataset_manager/annotation.py", line 926, in get_interpolated_shapes
    shapes.extend(interpolate(prev_shape, shape))
  File "/home/bsekachev/app.cvat.ai/cvat_enterprise/cvat/cvat/apps/dataset_manager/annotation.py", line 874, in interpolate
    shapes = simple_interpolation(shape0, shape1)
  File "/home/bsekachev/app.cvat.ai/cvat_enterprise/cvat/cvat/apps/dataset_manager/annotation.py", line 592, in simple_interpolation
    diff = np.subtract(shape1["points"], shape0["points"])

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.

Summary by CodeRabbit

  • Bug Fixes
    • Improved initialization and handling of SKELETON type shapes to prevent errors by setting their points to an empty list.

Copy link
Contributor

coderabbitai bot commented Jul 17, 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

The changes in task.py enhance the initialization of shapes and tracks by ensuring that shapes of type SKELETON are initialized with an empty list of points. This update improves data handling and prevents potential errors when dealing with skeleton shapes during the initialization process.

Changes

Files Change Summary
cvat/apps/dataset_manager/task.py Added handling for SKELETON shapes by setting their points to an empty list in _init_shapes_from_db and _init_tracks_from_db.

Poem

In code's swift dance, shapes find their place,
Skeleton forms now leave no trace.
With empty points, they start anew,
Bringing forth tasks, precise and true.
From database depths, they rise with grace,
Enhancing the flow in this digital space.


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 July 17, 2024 09:59
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2490153 and 73c85f8.

Files selected for processing (1)
  • cvat/apps/dataset_manager/task.py (2 hunks)
Additional comments not posted (2)
cvat/apps/dataset_manager/task.py (2)

657-658: Correct initialization of SKELETON shapes in tracks.

The changes ensure that shapes of type SKELETON within tracks are initialized with an empty list of points, aligning with the fixes made in shape initialization.

Verify that this change does not impact other track functionalities, especially those related to shape interpolation.


566-567: Proper handling of SKELETON type shapes.

The changes correctly initialize SKELETON shapes with an empty list of points to prevent broadcasting errors. This is a crucial fix for the issue described.

However, ensure that this initialization does not inadvertently affect other functionalities related to shapes.

Verification successful

Proper handling of SKELETON type shapes.

The changes correctly initialize SKELETON shapes with an empty list of points to prevent broadcasting errors. This is a crucial fix for the issue described.

  • The verification confirms that no other shape types are affected by this change.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that other shape types are unaffected by the change to SKELETON shapes.

# Test: Search for other shape type handling in the same method. Expect: No other shape types should be affected.
rg --type python -A 5 -B 5 "if db_shape\['type'\] == str\(models\.ShapeType\.SKELETON\)" cvat/apps/dataset_manager/task.py

Length of output: 161


Script:

#!/bin/bash
# Description: Verify that other shape types are unaffected by the change to SKELETON shapes.

# Test: Search for other shape type handling in the same method. Expect: No other shape types should be affected.
rg -A 5 -B 5 "if db_shape\['type'\] == str(models\.ShapeType\.SKELETON\)" cvat/apps/dataset_manager/task.py

Length of output: 253


Script:

#!/bin/bash
# Description: Verify that other shape types are unaffected by the change to SKELETON shapes.

# Test: Search for other shape type handling in the same method. Expect: No other shape types should be affected.
rg -A 5 -B 5 "if db_shape\['type'\] == str(models\.ShapeType\.SKELETON)" cvat/apps/dataset_manager/task.py

Length of output: 114


Script:

#!/bin/bash
# Description: Verify that other shape types are unaffected by the change to SKELETON shapes.

# Test: Search for all instances of shape type handling in the file. Expect: No other shape types should be affected.
rg "db_shape\['type'\]" cvat/apps/dataset_manager/task.py

Length of output: 203

Copy link

sonarcloud bot commented Jul 17, 2024

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.37%. Comparing base (2490153) to head (9d7e59e).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8179      +/-   ##
===========================================
+ Coverage    83.35%   83.37%   +0.01%     
===========================================
  Files          388      388              
  Lines        41306    41311       +5     
  Branches      3854     3854              
===========================================
+ Hits         34432    34443      +11     
+ Misses        6874     6868       -6     
Components Coverage Δ
cvat-ui 79.67% <100.00%> (+0.03%) ⬆️
cvat-server 86.69% <100.00%> (+<0.01%) ⬆️

@bsekachev bsekachev merged commit 511a2d9 into develop Jul 18, 2024
33 checks passed
@bsekachev bsekachev deleted the bs/fixed_export_skeletons branch July 31, 2024 13:12
@cvat-bot cvat-bot bot mentioned this pull request Aug 6, 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.

None yet

2 participants