Skip to content

inspect() performance: torch.unique() consumes 37% of execution time #119

@perctrix

Description

@perctrix

Problem

Profiling inspect() with py-spy reveals that torch.unique() at line 243 consumes ~37% of total execution time. For 3D medical images like BRaTS (240x240x155), this operation scans the entire label volume for each sample.

The ids field is rarely used in practice - only referenced in documentation examples. Most training pipelines (ROIDataset, RandomROIDataset) never access this field, making the 37% overhead unnecessary.

Proposed Solution

Add compute_ids: bool = True parameter to inspect(), allowing users to skip the expensive unique() call. When False, set ids to None (requires changing type to tuple[int, ...] | None).

Metadata

Metadata

Assignees

Labels

code reviewCode review or commentenhancementNew feature or requesttodoNew task or assignment

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions