Skip to content

Commit

Permalink
Added tensor transforms jupyter notebook (pytorch#2730)
Browse files Browse the repository at this point in the history
* [WIP] Added scriptable transforms python example

* Replaced script file with jupyter notebook

* Updated readme

* Updates according to review
+ updated docstrings

* Updated notebook and docstring according to the review

* torch script -> torchscript
  • Loading branch information
vfdev-5 authored and bryant1410 committed Nov 22, 2020
1 parent c3f84c2 commit 4921a7b
Show file tree
Hide file tree
Showing 4 changed files with 430 additions and 8 deletions.
19 changes: 19 additions & 0 deletions docs/source/transforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ All transformations accept PIL Image, Tensor Image or batch of Tensor Images as
Tensor Images is a tensor of ``(B, C, H, W)`` shape, where ``B`` is a number of images in the batch. Deterministic or
random transformations applied on the batch of Tensor Images identically transform all the images of the batch.

.. warning::

Since v0.8.0 all random transformations are using torch default random generator to sample random parameters.
It is a backward compatibility breaking change and user should set the random state as following:

.. code:: python
# Previous versions
# import random
# random.seed(12)
# Now
import torch
torch.manual_seed(17)
Please, keep in mind that the same seed for torch random generator and Python random generator will not
produce the same results.


Scriptable transforms
---------------------
Expand All @@ -33,6 +51,7 @@ Make sure to use only scriptable transformations, i.e. that work with ``torch.Te

For any custom transformations to be used with ``torch.jit.script``, they should be derived from ``torch.nn.Module``.


Compositions of transforms
--------------------------

Expand Down
13 changes: 13 additions & 0 deletions examples/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Python examples

- [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/pytorch/vision/blob/master/examples/python/tensor_transforms.ipynb)
[Examples of Tensor Images transformations](https://github.com/pytorch/vision/blob/master/examples/python/tensor_transforms.ipynb)

Prior to v0.8.0, transforms in torchvision have traditionally been PIL-centric and presented multiple limitations due to
that. Now, since v0.8.0, transforms implementations are Tensor and PIL compatible and we can achieve the following new
features:
- transform multi-band torch tensor images (with more than 3-4 channels)
- torchscript transforms together with your model for deployment
- support for GPU acceleration
- batched transformation such as for videos
- read and decode data directly as torch tensor with torchscript support (for PNG and JPEG image formats)
Loading

0 comments on commit 4921a7b

Please sign in to comment.