Skip to content

fix(image_processor): return uint16 from LDM3D rgblike_to_depthmap#14225

Open
sergioperezcheco wants to merge 1 commit into
huggingface:mainfrom
sergioperezcheco:fix/ldm3d-depthmap-dtype
Open

fix(image_processor): return uint16 from LDM3D rgblike_to_depthmap#14225
sergioperezcheco wants to merge 1 commit into
huggingface:mainfrom
sergioperezcheco:fix/ldm3d-depthmap-dtype

Conversation

@sergioperezcheco

Copy link
Copy Markdown

VaeImageProcessorLDM3D.rgblike_to_depthmap combines two 8-bit channels into a 16-bit depth value (high*256 + low) but then cast the result back to the 8-bit input dtype, truncating any value above 255. The downstream numpy_to_depth feeds that depth map into PIL Image.fromarray with mode="I;16", which raises "buffer is not large enough" because the buffer is sized for uint16 but the values got clamped.

This returns torch.uint16 / np.uint16 unconditionally, matching the function's documented purpose and its only consumer. The commented-out uint16 lines right above the old return already flagged this as known-but-unfinished. Introduced by #12546 (the NumPy 2.0 overflow fix).

Adds a regression test covering the numpy and torch branches of rgblike_to_depthmap plus the full numpy_to_depth -> I;16 PIL path. All tests in tests/others/test_image_processor.py pass and ruff is clean.

Fixes #14206

@github-actions github-actions Bot added fixes-issue tests size/M PR with diff < 200 LOC labels Jul 18, 2026
VaeImageProcessorLDM3D.rgblike_to_depthmap combines two 8-bit channels
into a 16-bit depth value (high*256 + low), but then cast the result
back to the 8-bit input dtype, truncating it. numpy_to_depth builds a
mode='I;16' PIL image from that depth map, which raised 'buffer is not
large enough' once any value exceeded 255.

Return torch.uint16 / np.uint16 unconditionally, matching the function's
purpose and the downstream I;16 consumer. Adds a regression test for both
the numpy and torch branches plus the numpy_to_depth path.

Fixes huggingface#14206
@sergioperezcheco
sergioperezcheco force-pushed the fix/ldm3d-depthmap-dtype branch from 044f21a to 8b98c66 Compare July 18, 2026 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixes-issue size/M PR with diff < 200 LOC tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LDM3D rgblike_to_depthmap truncates the 16-bit depth map back to the 8-bit input dtype

1 participant