Skip to content

Conversation

@SamirMoustafa
Copy link

The rgb2lab() and lab2rgb() functions in torchstain/torch/utils/ were failing with RuntimeError: Expected all tensors to be on the same device when processing CUDA tensors.

This occurred because:
Constant tensors (_rgb2xyz, _white, _xyz2rgb) were created on CPU by default

Input tensors were on CUDA devices
PyTorch operations between tensors on different devices are not allowed

Solution
Modified both functions to automatically detect the input tensor's device and move constant tensors to the same device:

  1. rgb2lab.py: Added device detection and moved _rgb2xyz and _white tensors to input device
  2. lab2rgb.py: Added device detection and moved _white and _xyz2rgb tensors to input device

@carloalbertobarbano
Copy link
Member

Thank you for your contribution @SamirMoustafa. I will merge the PR to the development branch.

@carloalbertobarbano carloalbertobarbano changed the base branch from main to development October 28, 2025 18:12
@carloalbertobarbano carloalbertobarbano merged commit 33520d5 into EIDOSLAB:development Oct 28, 2025
3 checks passed
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.

2 participants