Skip to content

Commit 8560d58

Browse files
committed
add support for single channel images
1 parent dffb2d1 commit 8560d58

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

torchvision/utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,13 @@ def make_grid(tensor, nrow=8, padding=2):
1515
tensor = tensorlist[0].new(size)
1616
for i in range(numImages):
1717
tensor[i].copy_(tensorlist[i])
18+
if tensor.dim() == 2: # single image H x W
19+
tensor = torch.view(1, tensor.size(0), tensor.size(1))
20+
tensor = torch.cat((tensor, tensor, tensor), 0)
1821
if tensor.dim() == 3: # single image
1922
return tensor
23+
if tensor.dim() == 4 and tensor.size(1) == 1: # single-channel images
24+
tensor = torch.cat((tensor, tensor, tensor), 1)
2025
# make the mini-batch of images into a grid
2126
nmaps = tensor.size(0)
2227
xmaps = min(nrow, nmaps)

0 commit comments

Comments
 (0)