-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Add illustrations of transforms with sphinx-gallery #3652
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
16dd404
WIP
NicolasHug 472eebd
Merge branch 'master' of github.com:pytorch/vision into gallery
NicolasHug 42245df
put back error on warnings for sphinx
NicolasHug a57558a
Merge branch 'sphinx_warnings_again' into gallery
NicolasHug a06a34c
temporarily remove backlings
NicolasHug 3fd623a
updated gitignore
NicolasHug b6b2746
Merge branch 'master' of github.com:pytorch/vision into gallery
NicolasHug 08f22a4
not not pround of that one
NicolasHug 35c8e2d
Avoid generating gallery on objects that aren't used in any example
NicolasHug f1408f1
Add backlinks to functions too
NicolasHug 74d16f0
updates to Mkaefile
NicolasHug b8ceeec
Better example
NicolasHug dd1ebb5
flake8
NicolasHug 967c534
update requirements.txt
NicolasHug 339cb9b
title fix
NicolasHug 0963f14
tf -> T
NicolasHug ce33d6b
Merge branch 'master' into gallery
NicolasHug 053224e
set sphinx version to 2.4.4
NicolasHug 7594f20
Merge branch 'gallery' of github.com:NicolasHug/vision into gallery
NicolasHug 571af18
Merge branch 'master' into gallery
NicolasHug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,15 @@ docset: html | |
| cp $(SPHINXPROJ).docset/icon.png $(SPHINXPROJ).docset/[email protected] | ||
| convert $(SPHINXPROJ).docset/[email protected] -resize 16x16 $(SPHINXPROJ).docset/icon.png | ||
|
|
||
| html-noplot: # Avoids running the gallery examples, which may take time | ||
| $(SPHINXBUILD) -D plot_gallery=0 -b html $(ASPHINXOPTS) "$(BUILDDIR)"/html | ||
| @echo | ||
| @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." | ||
|
|
||
| clean: | ||
| rm -rf $(BUILDDIR)/* | ||
| rm -rf auto_examples/ | ||
|
|
||
| .PHONY: help Makefile docset | ||
|
|
||
| # Catch-all target: route all unknown targets to Sphinx using the new | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| sphinx | ||
| sphinx==2.4.4 | ||
| sphinx-gallery | ||
| matplotlib | ||
| numpy | ||
| -e git+git://github.com/pytorch/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Example gallery | ||
| =============== | ||
|
|
||
| Below is a gallery of examples |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| """ | ||
| ========================== | ||
| Illustration of transforms | ||
| ========================== | ||
|
|
||
| This example illustrates the various transforms available in :mod:`torchvision.transforms`. | ||
| """ | ||
|
|
||
| from PIL import Image | ||
| from pathlib import Path | ||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
|
|
||
| import torchvision.transforms as T | ||
|
|
||
|
|
||
| orig_img = Image.open(Path('assets') / 'astronaut.jpg') | ||
|
|
||
|
|
||
| def plot(img, title="", with_orig=True, **kwargs): | ||
| def _plot(img, title, **kwargs): | ||
| plt.figure().suptitle(title, fontsize=25) | ||
| plt.imshow(np.asarray(img), **kwargs) | ||
| plt.axis('off') | ||
|
|
||
| if with_orig: | ||
| _plot(orig_img, "Original image") | ||
| _plot(img, title, **kwargs) | ||
|
|
||
|
|
||
| #################################### | ||
| # Pad | ||
| # --- | ||
| # The :class:`~torchvision.transforms.Pad` transform | ||
| # (see also :func:`~torchvision.transforms.functional.pad`) | ||
| # fills image borders with some pixel values. | ||
| padded_img = T.Pad(padding=30)(orig_img) | ||
| plot(padded_img, "Padded image") | ||
|
|
||
| #################################### | ||
| # Resize | ||
| # ------ | ||
| # The :class:`~torchvision.transforms.Resize` transform | ||
| # (see also :func:`~torchvision.transforms.functional.resize`) | ||
| # resizes an image. | ||
| resized_img = T.Resize(size=30)(orig_img) | ||
| plot(resized_img, "Resized image") | ||
|
|
||
| #################################### | ||
| # ColorJitter | ||
| # ----------- | ||
| # The :class:`~torchvision.transforms.ColorJitter` transform | ||
| # randomly changes the brightness, saturation, and other properties of an image. | ||
| jitted_img = T.ColorJitter(brightness=.5, hue=.3)(orig_img) | ||
| plot(jitted_img, "Jitted image") | ||
|
|
||
| #################################### | ||
| # Grayscale | ||
| # --------- | ||
| # The :class:`~torchvision.transforms.Grayscale` transform | ||
| # (see also :func:`~torchvision.transforms.functional.to_grayscale`) | ||
| # converts an image to grayscale | ||
| gray_img = T.Grayscale()(orig_img) | ||
| plot(gray_img, "Grayscale image", cmap='gray') |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.