Skip to content

fix: abstract away category indexing differences#254

Merged
mojomex merged 2 commits into
mainfrom
fix/category-behavior-difference
Jan 30, 2026
Merged

fix: abstract away category indexing differences#254
mojomex merged 2 commits into
mainfrom
fix/category-behavior-difference

Conversation

@mojomex

@mojomex mojomex commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Semseg and non-semseg datasets behave differently (position-based vs. explicit indexing).
This leads to mismatches when trying to visualize LiDAR segmentation data:

image

This PR fixes that by computing the index field in case position-based indexing is used,
and using the index field for visualization.

From what I can tell, the category index is currently only used for visualization. Relations to AnnotatedInstance etc. are done via token field and not affected by this PR.

See TIER IV INTERNAL discussion for details.

Semseg and non-semseg datasets behave differently (position-based vs. explicit indexing).
Now computing index field in case position-based indexing is used.

Signed-off-by: Max SCHMELLER <max.schmeller@tier4.jp>
Copilot AI review requested due to automatic review settings January 29, 2026 06:35
@github-actions github-actions Bot added the bug Something isn't working label Jan 29, 2026
@github-actions

github-actions Bot commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

☂️ Python Coverage

current status: ❌

Overall Coverage

Lines Covered Coverage Threshold Status
4175 3458 83% 50% 🟢

New Files

File Coverage Status
t4_devkit/schema/compatibility.py 89% 🟢
TOTAL 89% 🟢

Modified Files

File Coverage Status
t4_devkit/helper/rendering.py 15% 🔴
t4_devkit/tier4.py 82% 🟢
TOTAL 48% 🔴

updated for commit: 9ffef84 by action🐍

@github-actions

Copy link
Copy Markdown
Contributor

☂️ Python Coverage

current status: ❌

Overall Coverage

Lines Covered Coverage Threshold Status
4136 3427 83% 50% 🟢

New Files

File Coverage Status
t4_devkit/compatibility.py 89% 🟢
TOTAL 89% 🟢

Modified Files

File Coverage Status
t4_devkit/helper/rendering.py 15% 🔴
t4_devkit/tier4.py 82% 🟢
TOTAL 48% 🔴

updated for commit: 48b731d by action🐍

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR standardizes category indexing behavior across different T4Dataset revisions by introducing a compatibility layer that handles datasets with explicit vs. position-based category indexing.

Changes:

  • Added fix_category_table() function to compute missing category indices for datasets using position-based indexing
  • Updated category-to-index mappings to use the category.index field instead of enumeration position
  • Introduced new t4_devkit/compatibility.py module for dataset revision compatibility helpers

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
t4_devkit/compatibility.py New module containing fix_category_table() to normalize category index fields across dataset revisions
t4_devkit/tier4.py Applies category table fix during initialization and updates label-to-id mapping to use explicit index field
t4_devkit/helper/rendering.py Updates label-to-id mapping to use explicit category index instead of enumeration position

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread t4_devkit/tier4.py
self.annotation_dir, SchemaName.CALIBRATED_SENSOR
)
self.category: list[Category] = load_table(self.annotation_dir, SchemaName.CATEGORY)
self.category = fix_category_table(self.category)

Copilot AI Jan 29, 2026

Copy link

Choose a reason for hiding this comment

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

The fix_category_table() function mutates the input list in place and then returns it. This creates ambiguity about whether a new list is being assigned or the existing list is being modified. Consider either making the function purely mutating (returning None) or purely functional (creating a new list), and update the calling code accordingly.

Suggested change
self.category = fix_category_table(self.category)
fix_category_table(self.category)

Copilot uses AI. Check for mistakes.
"""
if any(category.index is None for category in categories):
if not all(category.index is None for category in categories):
raise ValueError("Category index is not set for some categories.")

Copilot AI Jan 29, 2026

Copy link

Choose a reason for hiding this comment

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

The error message is generic and doesn't help users diagnose which categories have missing indices. Consider including details about which categories are affected, such as 'Category index is not set for some categories: [list of category names or positions]'.

Suggested change
raise ValueError("Category index is not set for some categories.")
missing_positions = [i for i, category in enumerate(categories) if category.index is None]
raise ValueError(
f"Category index is not set for some categories at positions: {missing_positions}"
)

Copilot uses AI. Check for mistakes.
Comment on lines +31 to +32
for idx, category in enumerate(categories):
category.index = idx

Copilot AI Jan 29, 2026

Copy link

Choose a reason for hiding this comment

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

The function mutates the Category objects in place, which may have unintended side effects if the same category objects are referenced elsewhere. Consider documenting this mutation behavior in the docstring or making the function create new Category instances to avoid side effects.

Copilot uses AI. Check for mistakes.
@mojomex mojomex self-assigned this Jan 29, 2026
@mojomex

mojomex commented Jan 29, 2026

Copy link
Copy Markdown
Contributor Author

The discussion is still ongoing, but this PR demonstrates the problem and proposes a potential fix.

"

Signed-off-by: Max SCHMELLER <max.schmeller@tier4.jp>

@ktro2828 ktro2828 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

@mojomex mojomex merged commit ad000b4 into main Jan 30, 2026
4 of 5 checks passed
@mojomex mojomex deleted the fix/category-behavior-difference branch January 30, 2026 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants