Skip to content
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

Merged
merged 1 commit into from
Mar 16, 2017
Merged

add normalize, range, scale_each to make_grid #99

merged 1 commit into from
Mar 16, 2017

Conversation

soumith
Copy link
Member

@soumith soumith commented Mar 11, 2017

fixes #24

cc: @rtqichen @alykhantejani @gpleiss does this look better?

@soumith
Copy link
Member Author

soumith commented Mar 11, 2017

also cc: @fmassa for code review :)

"""
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.

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.

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.

This comment was marked as off-topic.

@fmassa
Copy link
Member

fmassa commented Mar 11, 2017

@soumith apart from the two inline comments, seems good to me!

@alykhantejani
Copy link
Contributor

@soumith LGTM except for the 2 comments

@soumith soumith changed the title add range to make_grid add normalize, range, scale_each to make_grid Mar 16, 2017
@soumith
Copy link
Member Author

soumith commented Mar 16, 2017

Made this PR more complete.
Add three options:
normalize, range and scale_each.
Here is a notebook showcasing them:
https://gist.github.com/anonymous/bf16430f7750c023141c562f3e9f2a91

screen shot 2017-03-15 at 8 36 24 pm

@soumith soumith merged commit c4f4c73 into master Mar 16, 2017
@soumith soumith deleted the rangegrid branch March 16, 2017 20:25
@fmassa
Copy link
Member

fmassa commented Mar 16, 2017

Look very nice, thanks Soumith!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

save_image behavior
3 participants