Skip to content

[io] Give a grayscale image a channel axis in tensor_from_numpy for every dtype - #2201

Merged
felixdittrich92 merged 1 commit into
mindee:mainfrom
RavSinghChandan:tensor-from-numpy-grayscale
Oct 30, 2026
Merged

felixdittrich92 merged 1 commit into
mindee:mainfrom
RavSinghChandan:tensor-from-numpy-grayscale

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

tensor_from_numpy turns a grayscale image of shape (H, W) into a (1, H, W) tensor with the default dtype=torch.float32 (through to_tensor), but with torch.float16 or torch.uint8 it permuted the array as if it had a channel axis and raised:

RuntimeError: permute(sparse_coo): number of dimensions in the tensor input does not match the length of the desired ordering of dimensions

tensor_from_pil with a grayscale image and one of these dtypes failed the same way. A grayscale array now gets a channel axis first, so it gives a (1, H, W) tensor with every dtype, like it already did with float32. Color images are unchanged

@codecov

codecov Bot commented Oct 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.74%. Comparing base (2e274dc) to head (773543d).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2201      +/-   ##
==========================================
- Coverage   97.75%   97.74%   -0.01%     
==========================================
  Files         170      170              
  Lines       10974    10975       +1     
==========================================
  Hits        10728    10728              
- Misses        246      247       +1     
Flag Coverage Δ
unittests 97.74% <100.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@felixdittrich92 felixdittrich92 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.

Thanks 👍

@felixdittrich92 felixdittrich92 self-assigned this Oct 30, 2026
@felixdittrich92 felixdittrich92 added this to the 1.2.0 milestone Oct 30, 2026
@felixdittrich92 felixdittrich92 added type: enhancement Improvement module: io Related to doctr.io ext: tests Related to tests folder labels Oct 30, 2026
@felixdittrich92
felixdittrich92 merged commit b31580a into mindee:main Oct 30, 2026
56 of 57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ext: tests Related to tests folder module: io Related to doctr.io type: enhancement Improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants