Skip to content

save_image manipulates input tensor inplace #1337

@ptrblck

Description

@ptrblck

Reported in forum: topic by Shisho_Sama.

Reason:
save_image manipulates the input tensor inplace in this line of code.

Code snippet to reproduce:

x = torch.randn(10, 1, 100, 100)
grid = torchvision.utils.make_grid(x)
print(grid.min(), grid.max(), grid.mean())
> tensor(-4.4464) tensor(4.4604) tensor(-0.0003)
torchvision.utils.save_image(grid, 'tmp.png')
print(grid.min(), grid.max(), grid.mean())
> tensor(0.) tensor(255.) tensor(48.1135)

Working on a copy would solve this issue.

Let me know, if you would be interested in a quick fix adding a clone() to the mentioned line of code or if another approach would be preferable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions