Skip to content
Snippets Groups Projects
Commit 89cc8ea8 authored by Guillaume HEUSCH's avatar Guillaume HEUSCH
Browse files

Merge branch 'to-tensor-gray' into 'master'

modified the ToTensor transform to properly work with grasyscale images

See merge request !15
parents 31bbafd2 dee2c5de
No related branches found
No related tags found
1 merge request!15modified the ToTensor transform to properly work with grasyscale images
Pipeline #26546 passed
......@@ -98,6 +98,8 @@ class ToTensor(object):
self.op = transforms.ToTensor()
def __call__(self, sample):
if len(sample['image'].shape) == 2:
sample['image'] = sample['image'][..., numpy.newaxis]
sample['image'] = self.op(sample['image'])
return sample
......
......@@ -111,6 +111,11 @@ def test_transforms():
tt = ToTensor()
tt(sample)
assert isinstance(sample['image'], torch.Tensor)
# grayscale
image_gray = numpy.random.rand(128, 128).astype("uint8")
sample_gray = {'image': image_gray}
tt(sample_gray)
assert isinstance(sample['image'], torch.Tensor)
from ..datasets import Normalize
image_copy = torch.Tensor(sample['image'])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment