-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add normalize, range, scale_each to make_grid #99
Conversation
also cc: @fmassa for code review :) |
torchvision/utils.py
Outdated
""" | ||
Saves a given Tensor into an image file. | ||
If given a mini-batch tensor, will save the tensor as a grid of images. | ||
""" | ||
from PIL import Image | ||
tensor = tensor.cpu() | ||
grid = make_grid(tensor, nrow=nrow, padding=padding) | ||
ndarr = grid.mul(255).byte().transpose(0,2).transpose(0,1).numpy() | ||
if range is not None: | ||
assert isinstance(tuple, range), "range has to be a tuple (min, max) if specified" |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torchvision/utils.py
Outdated
assert isinstance(tuple, range), "range has to be a tuple (min, max) if specified" | ||
grid = torch.clamp(grid, min=range[0], max=range[1]) | ||
# make grid to be [0, 1] | ||
grid.add_(-range[0]).div(range[1] - range[0]) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torchvision/utils.py
Outdated
assert isinstance(tuple, range), "range has to be a tuple (min, max) if specified" | ||
grid = torch.clamp(grid, min=range[0], max=range[1]) | ||
# make grid to be [0, 1] | ||
grid.add_(-range[0]).div(range[1] - range[0]) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
@soumith apart from the two inline comments, seems good to me! |
@soumith LGTM except for the 2 comments |
Made this PR more complete. |
Look very nice, thanks Soumith! |
fixes #24
cc: @rtqichen @alykhantejani @gpleiss does this look better?