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 counting of tracks when calculating analytics report #8088

Merged
merged 6 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 changelog.d/20240626_100703_boris_fixed_analytics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- Incorrect counting of tracked shapes when computing analytics report
(<https://github.com/cvat-ai/cvat/pull/8088>)
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,22 @@ def get_track_count():

count = 0
for track in db_tracks:
if not track["shapes"]:
continue

if track["shapes"] and track["shapes"][0]["type"] == ShapeType.SKELETON:
# skeleton's points are already counted as objects
continue

if len(track["shapes"]) == 1:
count += self._db_obj.segment.stop_frame - track["shapes"][0]["frame"] + 1
continue

# add initial frame here since only diff is added in the following loop
count += 1
for prev_shape, cur_shape in zip(track["shapes"], track["shapes"][1:]):
if not prev_shape["outside"]:
count += cur_shape["frame"] - prev_shape["frame"] + 1
count += cur_shape["frame"] - prev_shape["frame"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Refined track counting logic enhances accuracy.

The changes ensure that empty shapes are skipped and handle scenarios where only one shape exists in a track more robustly, improving the accuracy of the count. However, consider adding comments to explain the logic behind counting frames and handling different scenarios for future maintainability.

+                # Skip processing if no shapes are associated with the track
                 if not track["shapes"]:
                     continue
+                # Skip skeleton shapes as their points are already counted
                 if track["shapes"] and track["shapes"][0]["type"] == ShapeType.SKELETON:
                     continue
+                # If only one shape exists, calculate the frames from the first frame to the stop frame of the segment
                 if len(track["shapes"]) == 1:
                     count += self._db_obj.segment.stop_frame - track["shapes"][0]["frame"] + 1
                     continue
+                # Add the initial frame count and then iterate through shapes to count non-outside frames
                 count += 1
                 for prev_shape, cur_shape in zip(track["shapes"], track["shapes"][1:]):
                     if not prev_shape["outside"]:
                         count += cur_shape["frame"] - prev_shape["frame"]
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if not track["shapes"]:
continue
if track["shapes"] and track["shapes"][0]["type"] == ShapeType.SKELETON:
# skeleton's points are already counted as objects
continue
if len(track["shapes"]) == 1:
count += self._db_obj.segment.stop_frame - track["shapes"][0]["frame"] + 1
continue
# add initial frame here since only diff is added in the following loop
count += 1
for prev_shape, cur_shape in zip(track["shapes"], track["shapes"][1:]):
if not prev_shape["outside"]:
count += cur_shape["frame"] - prev_shape["frame"] + 1
count += cur_shape["frame"] - prev_shape["frame"]
# Skip processing if no shapes are associated with the track
if not track["shapes"]:
continue
# Skip skeleton shapes as their points are already counted
if track["shapes"] and track["shapes"][0]["type"] == ShapeType.SKELETON:
# skeleton's points are already counted as objects
continue
# If only one shape exists, calculate the frames from the first frame to the stop frame of the segment
if len(track["shapes"]) == 1:
count += self._db_obj.segment.stop_frame - track["shapes"][0]["frame"] + 1
continue
# Add the initial frame count and then iterate through shapes to count non-outside frames
count += 1
for prev_shape, cur_shape in zip(track["shapes"], track["shapes"][1:]):
if not prev_shape["outside"]:
count += cur_shape["frame"] - prev_shape["frame"]


return count

Expand Down
Loading