Skip to content

Conversation

@vvihorev
Copy link
Contributor

Problem

Export to nifti volumes has a large memory footprint. We encountered out of memory errors during export.

Solution

Each exported nifti volume is casted to int16 to be written to disk, moreover, each volume we export has just one mask. Thus we can use np.uint8 datatype for volumes during export processing to save space.

Changelog

Use np.uint8 as datatype for output nifti volumes to reduce allocations

Copilot AI review requested due to automatic review settings April 30, 2025 13:55
@linear
Copy link

linear bot commented Apr 30, 2025

Copy link
Contributor

Copilot AI left a comment

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 reduces the memory footprint during nifti volume export by switching the internal pixel array data type from the default (implicitly int16) to np.uint8. Key changes include:

  • Updating np.zeros calls for the output volumes and multilabel volumes to use dtype=np.uint8.
  • Using np.zeros_like calls with dtype=np.uint8 in mask conversion.

@vvihorev vvihorev requested a review from umbertoDifa April 30, 2025 14:03
@vvihorev vvihorev merged commit 5b85cff into master Apr 30, 2025
36 checks passed
@vvihorev vvihorev deleted the dar-6557-optimize-memory-footprint-for-nifti-export branch April 30, 2025 14:20
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.

3 participants