pytorch / pytorch/vision

Please add 'keep_channels' flag to make_grid

Open
#2,315 3 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

module: utils needs discussion
Dominant language
Python
Stars
17.9k
Forks
7.3k
Avg merge
1d 15h
Merged PRs (30d)
13

Description

🚀 Feature

For images with 1 channel, it would be useful to tell make_grid to not convert grayscale images to RGB

Motivation

I just wanted to do a simple MNIST example but torchvision.utils.make_grid modified the data such that it became 3-dimensional RGB. That's cool for color images but I wish there were a simple way to keep the channels the same

Pitch

if the user passes "keep_channels=True" then the number of channels doesn't change

Alternatives

first i looked for other issues, and found others have the same problem
i tried using cv2 but it had some error,
i tried doing the y = 0.2989 * r + 0.5870 * g + 0.1140 * b math but it didn't look great,

so eventually i settled on converting the tensor to PIL,
converting the PIL to grayscale,
then converting the grayscale image back to a tensor,
which is a ton of extra code and compute,
when we could just not convert images to RGB in the first place!

Additional context

https://github.com/pytorch/vision/issues/863

Thank you for making torchvision

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the torchvision.utils.make_grid entry point and its existing tests, then trace where single-channel images are expanded to RGB. Add coverage for the proposed keep_channels option and verify that a one-channel input retains its channel count while existing color-image behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
computer-vision, machine-learning
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.