torchvision save_image produces incorrect results when saving png files using the mps backend
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17.9k
- Forks
- 7.3k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 13
Description
Issue description
torchvision save_image produces incorrect results when saving png files
in the attached images, you will see color pixels, but the input data is a rank two tensor so the images should be grayscale. please zoom in very far (800%) if you cannot see the red, yellow, etc color pixels.
Code example
for mnist (using mps as the device):
def test(model, device, test_loader):
model.eval()
test_loss = 0
correct = 0
with torch.no_grad():
for data, target in test_loader:
data, target = data.to(device), target.to(device)
output = model(data)
for i in range(0, 10):
foo = data[i].reshape(28, 28).clone()
torchvision.utils.save_image(foo, "foo" +str(i)+".png", normalize=True)
System Info
- PyTorch or Caffe2: pytorch
- How you installed PyTorch: conda
- Build command you used: not compiled from source
- OS: macOS Ventura 13.4
- PyTorch version: 2.0.1
- Python version: 3.9.16
- CUDA/cuDNN version: n/a (using mps backend)
- GPU models and configuration: M1 cpu (mps backend)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue through torchvision.utils.save_image with the provided MNIST-style rank-two tensor, normalize=True, and the MPS device on macOS. Compare the generated PNG with CPU output and verify that the completed fix preserves grayscale pixels without color artifacts on MPS.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- macos, python, pytorch
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100