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

[Cherry-pick] Bunch of doc and fixes cherry-picks for release/0.15 #7334

Merged
merged 27 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cead4bf
add ffmpeg to Linux CPU and GPU unittest workflows (#7295)
pmeier Feb 21, 2023
df1f2d6
Update transforms docs sub-structure (#7291)
NicolasHug Feb 21, 2023
c7a20ba
Added docs for v2 transforms (part 1) (#7297)
NicolasHug Feb 21, 2023
0702325
reduce GHA log output (#7267)
pmeier Feb 22, 2023
011ebd7
align transforms v2 signatures with v1 (#7301)
pmeier Feb 22, 2023
72d48e2
Extend default heuristic of SanitizeBoundingBoxes to support tuples (…
NicolasHug Feb 23, 2023
b598de4
add end-to-end example gallery for transforms v2 (#7302)
pmeier Feb 23, 2023
dd5cec3
Add v2 docs for color transforms (#7310)
NicolasHug Feb 23, 2023
4fb043e
Add docs for containers and undeprecate p for RandomChoice (#7311)
NicolasHug Feb 23, 2023
684f8d2
Updated geometric transforms v2 docstring (#7303)
vfdev-5 Feb 23, 2023
15dfd27
Cleanup for e2e gallery example for transforms v2 (#7318)
pmeier Feb 24, 2023
1150f1c
Singular Sanitize BoundingBox (#7316)
mpearce25 Feb 24, 2023
384162e
Misc docs transforms v2(#7314)
NicolasHug Feb 24, 2023
a01e485
Minor updates in autoaugment, augment docstring v2 (#7317)
vfdev-5 Feb 24, 2023
0dfc317
Fixed broken test_random_choice (#7315)
vfdev-5 Feb 24, 2023
9d768dd
Updated _meta.py docstrings (#7320)
vfdev-5 Feb 24, 2023
4c0638b
remove strEnum from BoundingBoxFormat (#7322)
NicolasHug Feb 24, 2023
d21e38a
Updated _type_conversion.py docs (#7324)
vfdev-5 Feb 24, 2023
4e040ee
add docs for datapoints (#7312)
pmeier Feb 24, 2023
f62a045
Various doc enhancements (#7326)
NicolasHug Feb 24, 2023
818b989
Add docs for UniformTemporalSubsample (#7325)
NicolasHug Feb 24, 2023
198e6e4
fix BoundingBox.wrap_like (#7327)
pmeier Feb 24, 2023
d8083d5
Add docs for functionals v2 (#7328)
NicolasHug Feb 24, 2023
5ec46ad
add gallery example for datapoints (#7321)
pmeier Feb 24, 2023
db6630e
Change betastatus doc warning and v2 import warning (#7329)
NicolasHug Feb 24, 2023
9de9566
add gallery for transforms v2 (#7331)
pmeier Feb 24, 2023
fdf72de
Fixed uncaught warnings in tests v2 (#7330)
vfdev-5 Feb 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test-linux-cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
fi

# Create Conda Env
conda create -yp ci_env python="${PYTHON_VERSION}" numpy libpng jpeg scipy
conda create -yp ci_env --quiet python="${PYTHON_VERSION}" numpy libpng jpeg scipy 'ffmpeg<4.3'
conda activate /work/ci_env

# Install PyTorch, Torchvision, and testing libraries
Expand All @@ -50,8 +50,8 @@ jobs:
-c nvidia "pytorch-${CHANNEL}"::pytorch[build="*${VERSION}*"] \
"${CUDATOOLKIT}"
python3 setup.py develop
python3 -m pip install pytest pytest-mock 'av<10'
python3 -m pip install --progress-bar=off pytest pytest-mock 'av<10'

# Run Tests
python3 -m torch.utils.collect_env
python3 -m pytest --junitxml=test-results/junit.xml -v --durations 20
python3 -m pytest --junitxml=test-results/junit.xml --durations 20
6 changes: 3 additions & 3 deletions .github/workflows/test-linux-gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
fi

# Create Conda Env
conda create -yp ci_env python="${PYTHON_VERSION}" numpy libpng jpeg scipy
conda create -yp ci_env --quiet python="${PYTHON_VERSION}" numpy libpng jpeg scipy 'ffmpeg<4.3'
conda activate /work/ci_env

# Install PyTorch, Torchvision, and testing libraries
Expand All @@ -54,8 +54,8 @@ jobs:
-c nvidia "pytorch-${CHANNEL}"::pytorch[build="*${VERSION}*"] \
"${CUDATOOLKIT}"
python3 setup.py develop
python3 -m pip install pytest pytest-mock 'av<10'
python3 -m pip install --progress-bar=off pytest pytest-mock 'av<10'

# Run Tests
python3 -m torch.utils.collect_env
python3 -m pytest --junitxml=test-results/junit.xml -v --durations 20
python3 -m pytest --junitxml=test-results/junit.xml --durations 20
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ sphinx-gallery>=0.11.1
sphinx==5.0.0
tabulate
-e git+https://github.com/pytorch/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme
pycocotools
15 changes: 13 additions & 2 deletions docs/source/beta_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@

class BetaStatus(Directive):
has_content = True
text = "The {api_name} is in Beta stage, and backward compatibility is not guaranteed."

def run(self):
api_name = " ".join(self.content)
text = f"The {api_name} is in Beta stage, and backward compatibility is not guaranteed."
text = self.text.format(api_name=" ".join(self.content))
return [nodes.warning("", nodes.paragraph("", "", nodes.Text(text)))]


class V2BetaStatus(BetaStatus):
text = (
"The {api_name} is in Beta stage, and while we do not expect major breaking changes, "
"some APIs may still change according to user feedback. Please submit any feedback you may have "
"in this issue: https://github.com/pytorch/vision/issues/6753, and you can also check "
"out https://github.com/pytorch/vision/issues/7319 to learn "
"more about the APIs that we suspect might involve future changes."
)


def setup(app):
app.add_directive("betastatus", BetaStatus)
app.add_directive("v2betastatus", V2BetaStatus)
return {
"version": "0.1",
"parallel_read_safe": True,
Expand Down
4 changes: 4 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@

sys.path.append(os.path.abspath("."))

torchvision.disable_beta_transforms_warning()
import torchvision.datapoints # Don't remove, otherwise the docs for datapoints aren't linked properly

# -- General configuration ------------------------------------------------

# Required version of sphinx is set from docs/requirements.txt
Expand Down Expand Up @@ -60,6 +63,7 @@
"gallery_dirs": "auto_examples", # path to where to save gallery generated output
"backreferences_dir": "gen_modules/backreferences",
"doc_module": ("torchvision",),
"remove_config_comments": True,
}

napoleon_use_ivar = True
Expand Down
19 changes: 19 additions & 0 deletions docs/source/datapoints.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Datapoints
==========

.. currentmodule:: torchvision.datapoints

Datapoints are tensor subclasses which the :mod:`~torchvision.transforms.v2` v2 transforms use under the hood to
dispatch their inputs to the appropriate lower-level kernels. Most users do not
need to manipulate datapoints directly and can simply rely on dataset wrapping -
see e.g. :ref:`sphx_glr_auto_examples_plot_transforms_v2_e2e.py`.

.. autosummary::
:toctree: generated/
:template: class.rst

Image
Video
BoundingBoxFormat
BoundingBox
Mask
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ architectures, and common image transformations for computer vision.
:caption: Package Reference

transforms
datapoints
models
datasets
utils
Expand Down
170 changes: 120 additions & 50 deletions docs/source/transforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ Transforming and augmenting images

.. currentmodule:: torchvision.transforms


.. note::
In 0.15, we released a new set of transforms available in the
``torchvision.transforms.v2`` namespace, which add support for transforming
not just images but also bounding boxes, masks, or videos. These transforms
are fully backward compatible with the current ones, and you'll see them
documented below with a `v2.` prefix. To get started with those new
transforms, you can check out
:ref:`sphx_glr_auto_examples_plot_transforms_v2_e2e.py`.
Note that these transforms are still BETA, and while we don't expect major
breaking changes in the future, some APIs may still change according to user
feedback. Please submit any feedback you may have `here
<https://github.com/pytorch/vision/issues/6753>`_, and you can also check
out `this issue <https://github.com/pytorch/vision/issues/7319>`_ to learn
more about the APIs that we suspect might involve future changes.

Transforms are common image transformations available in the
``torchvision.transforms`` module. They can be chained together using
:class:`Compose`.
Expand All @@ -14,11 +30,10 @@ transformations.
This is useful if you have to build a more complex transformation pipeline
(e.g. in the case of segmentation tasks).

Most transformations accept both `PIL <https://pillow.readthedocs.io>`_
images and tensor images, although some transformations are :ref:`PIL-only
<transforms_pil_only>` and some are :ref:`tensor-only
<transforms_tensor_only>`. The :ref:`conversion_transforms` may be used to
convert to and from PIL images.
Most transformations accept both `PIL <https://pillow.readthedocs.io>`_ images
and tensor images, although some transformations are PIL-only and some are
tensor-only. The :ref:`conversion_transforms` may be used to convert to and from
PIL images, or for converting dtypes and ranges.

The transformations that accept tensor images also accept batches of tensor
images. A Tensor Image is a tensor with ``(C, H, W)`` shape, where ``C`` is a
Expand Down Expand Up @@ -70,8 +85,10 @@ The following examples illustrate the use of the available transforms:
produce the same results.


Scriptable transforms
---------------------
Transforms scriptability
------------------------

.. TODO: Add note about v2 scriptability (in next PR)

In order to script the transformations, please use ``torch.nn.Sequential`` instead of :class:`Compose`.

Expand All @@ -89,100 +106,141 @@ 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
--------------------------
Geometry
--------

.. autosummary::
:toctree: generated/
:template: class.rst

Compose
Resize
v2.Resize
v2.ScaleJitter
v2.RandomShortestSize
v2.RandomResize
RandomCrop
v2.RandomCrop
RandomResizedCrop
v2.RandomResizedCrop
v2.RandomIoUCrop
CenterCrop
v2.CenterCrop
FiveCrop
v2.FiveCrop
TenCrop
v2.TenCrop
Pad
v2.Pad
v2.RandomZoomOut
RandomRotation
v2.RandomRotation
RandomAffine
v2.RandomAffine
RandomPerspective
v2.RandomPerspective
ElasticTransform
v2.ElasticTransform
RandomHorizontalFlip
v2.RandomHorizontalFlip
RandomVerticalFlip
v2.RandomVerticalFlip


Transforms on PIL Image and torch.\*Tensor
------------------------------------------
Color
-----

.. autosummary::
:toctree: generated/
:template: class.rst

CenterCrop
ColorJitter
FiveCrop
v2.ColorJitter
v2.RandomPhotometricDistort
Grayscale
Pad
RandomAffine
RandomApply
RandomCrop
v2.Grayscale
RandomGrayscale
RandomHorizontalFlip
RandomPerspective
RandomResizedCrop
RandomRotation
RandomVerticalFlip
Resize
TenCrop
v2.RandomGrayscale
GaussianBlur
v2.GaussianBlur
RandomInvert
v2.RandomInvert
RandomPosterize
v2.RandomPosterize
RandomSolarize
v2.RandomSolarize
RandomAdjustSharpness
v2.RandomAdjustSharpness
RandomAutocontrast
v2.RandomAutocontrast
RandomEqualize
v2.RandomEqualize


.. _transforms_pil_only:

Transforms on PIL Image only
----------------------------
Composition
-----------

.. autosummary::
:toctree: generated/
:template: class.rst

Compose
v2.Compose
RandomApply
v2.RandomApply
RandomChoice
v2.RandomChoice
RandomOrder
v2.RandomOrder

.. _transforms_tensor_only:

Transforms on torch.\*Tensor only
---------------------------------
Miscellaneous
-------------

.. autosummary::
:toctree: generated/
:template: class.rst

LinearTransformation
v2.LinearTransformation
Normalize
v2.Normalize
RandomErasing
ConvertImageDtype
v2.RandomErasing
Lambda
v2.Lambda
v2.SanitizeBoundingBox
v2.ClampBoundingBox
v2.UniformTemporalSubsample

.. _conversion_transforms:

Conversion Transforms
---------------------
Conversion
----------

.. note::
Beware, some of these conversion transforms below will scale the values
while performing the conversion, while some may not do any scaling. By
scaling, we mean e.g. that a ``uint8`` -> ``float32`` would map the [0,
255] range into [0, 1] (and vice-versa).

.. autosummary::
:toctree: generated/
:template: class.rst

ToPILImage
v2.ToPILImage
v2.ToImagePIL
ToTensor
v2.ToTensor
PILToTensor
v2.PILToTensor
v2.ToImageTensor
ConvertImageDtype
v2.ConvertDtype
v2.ConvertImageDtype
v2.ToDtype
v2.ConvertBoundingBoxFormat


Generic Transforms
------------------

.. autosummary::
:toctree: generated/
:template: class.rst

Lambda


Automatic Augmentation Transforms
---------------------------------
Auto-Augmentation
-----------------

`AutoAugment <https://arxiv.org/pdf/1805.09501.pdf>`_ is a common Data Augmentation technique that can improve the accuracy of Image Classification models.
Though the data augmentation policies are directly linked to their trained dataset, empirical studies show that
Expand All @@ -196,9 +254,13 @@ The new transform can be used standalone or mixed-and-matched with existing tran

AutoAugmentPolicy
AutoAugment
v2.AutoAugment
RandAugment
v2.RandAugment
TrivialAugmentWide
v2.TrivialAugmentWide
AugMix
v2.AugMix

.. _functional_transforms:

Expand All @@ -207,6 +269,14 @@ Functional Transforms

.. currentmodule:: torchvision.transforms.functional


.. note::
You'll find below the documentation for the existing
``torchvision.transforms.functional`` namespace. The
``torchvision.transforms.v2.functional`` namespace exists as well and can be
used! The same functionals are present, so you simply need to change your
import to rely on the ``v2`` namespace.

Functional transforms give you fine-grained control of the transformation pipeline.
As opposed to the transformations above, functional transforms don't contain a random number
generator for their parameters.
Expand Down
1 change: 1 addition & 0 deletions gallery/assets/coco/images/000000000001.jpg
1 change: 1 addition & 0 deletions gallery/assets/coco/images/000000000002.jpg
1 change: 1 addition & 0 deletions gallery/assets/coco/instances.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"images": [{"file_name": "000000000001.jpg", "height": 512, "width": 512, "id": 1}, {"file_name": "000000000002.jpg", "height": 500, "width": 500, "id": 2}], "annotations": [{"segmentation": [[40.0, 511.0, 26.0, 487.0, 28.0, 438.0, 17.0, 397.0, 24.0, 346.0, 38.0, 306.0, 61.0, 250.0, 111.0, 206.0, 111.0, 187.0, 120.0, 183.0, 136.0, 159.0, 159.0, 150.0, 181.0, 148.0, 182.0, 132.0, 175.0, 132.0, 168.0, 120.0, 154.0, 102.0, 153.0, 62.0, 188.0, 35.0, 191.0, 29.0, 208.0, 20.0, 210.0, 22.0, 227.0, 16.0, 240.0, 16.0, 276.0, 31.0, 285.0, 39.0, 301.0, 88.0, 297.0, 108.0, 281.0, 128.0, 273.0, 138.0, 266.0, 138.0, 264.0, 153.0, 257.0, 162.0, 256.0, 174.0, 284.0, 197.0, 300.0, 221.0, 303.0, 236.0, 337.0, 258.0, 357.0, 306.0, 361.0, 351.0, 358.0, 511.0]], "iscrowd": 0, "image_id": 1, "bbox": [17.0, 16.0, 344.0, 495.0], "category_id": 1, "id": 1}, {"segmentation": [[0.0, 411.0, 43.0, 401.0, 99.0, 395.0, 105.0, 351.0, 124.0, 326.0, 181.0, 294.0, 227.0, 280.0, 245.0, 262.0, 259.0, 234.0, 262.0, 207.0, 271.0, 140.0, 283.0, 139.0, 301.0, 162.0, 309.0, 181.0, 341.0, 175.0, 362.0, 139.0, 369.0, 139.0, 377.0, 163.0, 378.0, 203.0, 381.0, 212.0, 380.0, 220.0, 382.0, 242.0, 404.0, 264.0, 392.0, 293.0, 384.0, 295.0, 385.0, 316.0, 399.0, 343.0, 391.0, 448.0, 452.0, 475.0, 457.0, 494.0, 436.0, 498.0, 402.0, 491.0, 369.0, 488.0, 366.0, 496.0, 319.0, 496.0, 302.0, 485.0, 226.0, 469.0, 128.0, 456.0, 74.0, 458.0, 29.0, 439.0, 0.0, 445.0]], "iscrowd": 0, "image_id": 2, "bbox": [0.0, 139.0, 457.0, 359.0], "category_id": 18, "id": 2}]}
Loading