Skip to content

Commit

Permalink
2023-11-14 nightly release (9fa5f3f)
Browse files Browse the repository at this point in the history
  • Loading branch information
pytorchbot committed Nov 14, 2023
1 parent 90ba898 commit e208641
Show file tree
Hide file tree
Showing 33 changed files with 105 additions and 282 deletions.
10 changes: 0 additions & 10 deletions docs/source/beta_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,8 @@ def run(self):
return [self.node("", nodes.paragraph("", "", nodes.Text(text)))]


class V2BetaStatus(BetaStatus):
text = (
"The {api_name} is in Beta stage, and while we do not expect disruptive breaking changes, "
"some APIs may slightly change according to user feedback. Please submit any feedback you may have "
"in this issue: https://github.com/pytorch/vision/issues/6753."
)
node = nodes.note


def setup(app):
app.add_directive("betastatus", BetaStatus)
app.add_directive("v2betastatus", V2BetaStatus)
return {
"version": "0.1",
"parallel_read_safe": True,
Expand Down
11 changes: 3 additions & 8 deletions docs/source/transforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ V1 or V2? Which one should I use?

**TL;DR** We recommending using the ``torchvision.transforms.v2`` transforms
instead of those in ``torchvision.transforms``. They're faster and they can do
more things. Just change the import and you should be good to go.
more things. Just change the import and you should be good to go. Moving
forward, new features and improvements will only be considered for the v2
transforms.

In Torchvision 0.15 (March 2023), we released a new set of transforms available
in the ``torchvision.transforms.v2`` namespace. These transforms have a lot of
Expand All @@ -126,13 +128,6 @@ you're already using tranforms from ``torchvision.transforms``, all you need to
do to is to update the import to ``torchvision.transforms.v2``. In terms of
output, there might be negligible differences due to implementation differences.

.. note::

The v2 transforms are still BETA, but at this point we do not expect
disruptive changes to be made to their public APIs. We're planning to make
them fully stable in version 0.17. Please submit any feedback you may have
`here <https://github.com/pytorch/vision/issues/6753>`_.

.. _transforms_perf:

Performance considerations
Expand Down
33 changes: 1 addition & 32 deletions test/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import random
import re
import textwrap
from functools import partial

import numpy as np
Expand All @@ -24,7 +23,7 @@
except ImportError:
stats = None

from common_utils import assert_equal, assert_run_python_script, cycle_over, float_dtypes, int_dtypes
from common_utils import assert_equal, cycle_over, float_dtypes, int_dtypes


GRACE_HOPPER = get_file_path_2(
Expand Down Expand Up @@ -2241,35 +2240,5 @@ def test_random_grayscale_with_grayscale_input():
torch.testing.assert_close(F.pil_to_tensor(output_pil), image_tensor)


# TODO: remove in 0.17 when we can delete functional_pil.py and functional_tensor.py
@pytest.mark.parametrize(
"import_statement",
(
"from torchvision.transforms import functional_pil",
"from torchvision.transforms import functional_tensor",
"from torchvision.transforms.functional_tensor import resize",
"from torchvision.transforms.functional_pil import resize",
),
)
@pytest.mark.parametrize("from_private", (True, False))
def test_functional_deprecation_warning(import_statement, from_private):
if from_private:
import_statement = import_statement.replace("functional", "_functional")
source = f"""
import warnings
with warnings.catch_warnings():
warnings.simplefilter("error")
{import_statement}
"""
else:
source = f"""
import pytest
with pytest.warns(UserWarning, match="removed in 0.17"):
{import_statement}
"""
assert_run_python_script(textwrap.dedent(source))


if __name__ == "__main__":
pytest.main([__file__])
2 changes: 1 addition & 1 deletion torchvision/datasets/video_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def __init__(

def _compute_frame_pts(self) -> None:
self.video_pts = []
self.video_fps = []
self.video_fps: List[int] = []

# strategy: use a DataLoader to parallelize read_video_timestamps
# so need to create a dummy dataset first
Expand Down
11 changes: 0 additions & 11 deletions torchvision/transforms/functional_pil.py

This file was deleted.

11 changes: 0 additions & 11 deletions torchvision/transforms/functional_tensor.py

This file was deleted.

12 changes: 3 additions & 9 deletions torchvision/transforms/v2/_augment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@


class RandomErasing(_RandomApplyTransform):
"""[BETA] Randomly select a rectangle region in the input image or video and erase its pixels.
.. v2betastatus:: RandomErasing transform
"""Randomly select a rectangle region in the input image or video and erase its pixels.
This transform does not support PIL Image.
'Random Erasing Data Augmentation' by Zhong et al. See https://arxiv.org/abs/1708.04896
Expand Down Expand Up @@ -207,9 +205,7 @@ def _mixup_label(self, label: torch.Tensor, *, lam: float) -> torch.Tensor:


class MixUp(_BaseMixUpCutMix):
"""[BETA] Apply MixUp to the provided batch of images and labels.
.. v2betastatus:: MixUp transform
"""Apply MixUp to the provided batch of images and labels.
Paper: `mixup: Beyond Empirical Risk Minimization <https://arxiv.org/abs/1710.09412>`_.
Expand Down Expand Up @@ -256,9 +252,7 @@ def _transform(self, inpt: Any, params: Dict[str, Any]) -> Any:


class CutMix(_BaseMixUpCutMix):
"""[BETA] Apply CutMix to the provided batch of images and labels.
.. v2betastatus:: CutMix transform
"""Apply CutMix to the provided batch of images and labels.
Paper: `CutMix: Regularization Strategy to Train Strong Classifiers with Localizable Features
<https://arxiv.org/abs/1905.04899>`_.
Expand Down
16 changes: 4 additions & 12 deletions torchvision/transforms/v2/_auto_augment.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,9 @@ def _apply_image_or_video_transform(


class AutoAugment(_AutoAugmentBase):
r"""[BETA] AutoAugment data augmentation method based on
r"""AutoAugment data augmentation method based on
`"AutoAugment: Learning Augmentation Strategies from Data" <https://arxiv.org/pdf/1805.09501.pdf>`_.
.. v2betastatus:: AutoAugment transform
This transformation works on images and videos only.
If the input is :class:`torch.Tensor`, it should be of type ``torch.uint8``, and it is expected
Expand Down Expand Up @@ -350,12 +348,10 @@ def forward(self, *inputs: Any) -> Any:


class RandAugment(_AutoAugmentBase):
r"""[BETA] RandAugment data augmentation method based on
r"""RandAugment data augmentation method based on
`"RandAugment: Practical automated data augmentation with a reduced search space"
<https://arxiv.org/abs/1909.13719>`_.
.. v2betastatus:: RandAugment transform
This transformation works on images and videos only.
If the input is :class:`torch.Tensor`, it should be of type ``torch.uint8``, and it is expected
Expand Down Expand Up @@ -434,11 +430,9 @@ def forward(self, *inputs: Any) -> Any:


class TrivialAugmentWide(_AutoAugmentBase):
r"""[BETA] Dataset-independent data-augmentation with TrivialAugment Wide, as described in
r"""Dataset-independent data-augmentation with TrivialAugment Wide, as described in
`"TrivialAugment: Tuning-free Yet State-of-the-Art Data Augmentation" <https://arxiv.org/abs/2103.10158>`_.
.. v2betastatus:: TrivialAugmentWide transform
This transformation works on images and videos only.
If the input is :class:`torch.Tensor`, it should be of type ``torch.uint8``, and it is expected
Expand Down Expand Up @@ -505,11 +499,9 @@ def forward(self, *inputs: Any) -> Any:


class AugMix(_AutoAugmentBase):
r"""[BETA] AugMix data augmentation method based on
r"""AugMix data augmentation method based on
`"AugMix: A Simple Data Processing Method to Improve Robustness and Uncertainty" <https://arxiv.org/abs/1912.02781>`_.
.. v2betastatus:: AugMix transform
This transformation works on images and videos only.
If the input is :class:`torch.Tensor`, it should be of type ``torch.uint8``, and it is expected
Expand Down
45 changes: 11 additions & 34 deletions torchvision/transforms/v2/_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@


class Grayscale(Transform):
"""[BETA] Convert images or videos to grayscale.
.. v2betastatus:: Grayscale transform
"""Convert images or videos to grayscale.
If the input is a :class:`torch.Tensor`, it is expected
to have [..., 3 or 1, H, W] shape, where ... means an arbitrary number of leading dimensions
Expand All @@ -32,9 +30,7 @@ def _transform(self, inpt: Any, params: Dict[str, Any]) -> Any:


class RandomGrayscale(_RandomApplyTransform):
"""[BETA] Randomly convert image or videos to grayscale with a probability of p (default 0.1).
.. v2betastatus:: RandomGrayscale transform
"""Randomly convert image or videos to grayscale with a probability of p (default 0.1).
If the input is a :class:`torch.Tensor`, it is expected to have [..., 3 or 1, H, W] shape,
where ... means an arbitrary number of leading dimensions
Expand All @@ -59,9 +55,7 @@ def _transform(self, inpt: Any, params: Dict[str, Any]) -> Any:


class ColorJitter(Transform):
"""[BETA] Randomly change the brightness, contrast, saturation and hue of an image or video.
.. v2betastatus:: ColorJitter transform
"""Randomly change the brightness, contrast, saturation and hue of an image or video.
If the input is a :class:`torch.Tensor`, it is expected
to have [..., 1 or 3, H, W] shape, where ... means an arbitrary number of leading dimensions.
Expand Down Expand Up @@ -163,10 +157,7 @@ def _transform(self, inpt: Any, params: Dict[str, Any]) -> Any:


class RandomChannelPermutation(Transform):
"""[BETA] Randomly permute the channels of an image or video
.. v2betastatus:: RandomChannelPermutation transform
"""
"""Randomly permute the channels of an image or video"""

def _get_params(self, flat_inputs: List[Any]) -> Dict[str, Any]:
num_channels, *_ = query_chw(flat_inputs)
Expand All @@ -177,11 +168,9 @@ def _transform(self, inpt: Any, params: Dict[str, Any]) -> Any:


class RandomPhotometricDistort(Transform):
"""[BETA] Randomly distorts the image or video as used in `SSD: Single Shot
"""Randomly distorts the image or video as used in `SSD: Single Shot
MultiBox Detector <https://arxiv.org/abs/1512.02325>`_.
.. v2betastatus:: RandomPhotometricDistort transform
This transform relies on :class:`~torchvision.transforms.v2.ColorJitter`
under the hood to adjust the contrast, saturation, hue, brightness, and also
randomly permutes channels.
Expand Down Expand Up @@ -249,9 +238,7 @@ def _transform(self, inpt: Any, params: Dict[str, Any]) -> Any:


class RandomEqualize(_RandomApplyTransform):
"""[BETA] Equalize the histogram of the given image or video with a given probability.
.. v2betastatus:: RandomEqualize transform
"""Equalize the histogram of the given image or video with a given probability.
If the input is a :class:`torch.Tensor`, it is expected
to have [..., 1 or 3, H, W] shape, where ... means an arbitrary number of leading dimensions.
Expand All @@ -268,9 +255,7 @@ def _transform(self, inpt: Any, params: Dict[str, Any]) -> Any:


class RandomInvert(_RandomApplyTransform):
"""[BETA] Inverts the colors of the given image or video with a given probability.
.. v2betastatus:: RandomInvert transform
"""Inverts the colors of the given image or video with a given probability.
If img is a Tensor, it is expected to be in [..., 1 or 3, H, W] format,
where ... means it can have an arbitrary number of leading dimensions.
Expand All @@ -287,11 +272,9 @@ def _transform(self, inpt: Any, params: Dict[str, Any]) -> Any:


class RandomPosterize(_RandomApplyTransform):
"""[BETA] Posterize the image or video with a given probability by reducing the
"""Posterize the image or video with a given probability by reducing the
number of bits for each color channel.
.. v2betastatus:: RandomPosterize transform
If the input is a :class:`torch.Tensor`, it should be of type torch.uint8,
and it is expected to have [..., 1 or 3, H, W] shape, where ... means an arbitrary number of leading dimensions.
If img is PIL Image, it is expected to be in mode "L" or "RGB".
Expand All @@ -312,11 +295,9 @@ def _transform(self, inpt: Any, params: Dict[str, Any]) -> Any:


class RandomSolarize(_RandomApplyTransform):
"""[BETA] Solarize the image or video with a given probability by inverting all pixel
"""Solarize the image or video with a given probability by inverting all pixel
values above a threshold.
.. v2betastatus:: RandomSolarize transform
If img is a Tensor, it is expected to be in [..., 1 or 3, H, W] format,
where ... means it can have an arbitrary number of leading dimensions.
If img is PIL Image, it is expected to be in mode "L" or "RGB".
Expand All @@ -342,9 +323,7 @@ def _transform(self, inpt: Any, params: Dict[str, Any]) -> Any:


class RandomAutocontrast(_RandomApplyTransform):
"""[BETA] Autocontrast the pixels of the given image or video with a given probability.
.. v2betastatus:: RandomAutocontrast transform
"""Autocontrast the pixels of the given image or video with a given probability.
If the input is a :class:`torch.Tensor`, it is expected
to have [..., 1 or 3, H, W] shape, where ... means an arbitrary number of leading dimensions.
Expand All @@ -361,9 +340,7 @@ def _transform(self, inpt: Any, params: Dict[str, Any]) -> Any:


class RandomAdjustSharpness(_RandomApplyTransform):
"""[BETA] Adjust the sharpness of the image or video with a given probability.
.. v2betastatus:: RandomAdjustSharpness transform
"""Adjust the sharpness of the image or video with a given probability.
If the input is a :class:`torch.Tensor`,
it is expected to have [..., 1 or 3, H, W] shape, where ... means an arbitrary number of leading dimensions.
Expand Down
16 changes: 4 additions & 12 deletions torchvision/transforms/v2/_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@


class Compose(Transform):
"""[BETA] Composes several transforms together.
.. v2betastatus:: Compose transform
"""Composes several transforms together.
This transform does not support torchscript.
Please, see the note below.
Expand Down Expand Up @@ -62,9 +60,7 @@ def extra_repr(self) -> str:


class RandomApply(Transform):
"""[BETA] Apply randomly a list of transformations with a given probability.
.. v2betastatus:: RandomApply transform
"""Apply randomly a list of transformations with a given probability.
.. note::
In order to script the transformation, please use ``torch.nn.ModuleList`` as input instead of list/tuple of
Expand Down Expand Up @@ -118,9 +114,7 @@ def extra_repr(self) -> str:


class RandomChoice(Transform):
"""[BETA] Apply single transformation randomly picked from a list.
.. v2betastatus:: RandomChoice transform
"""Apply single transformation randomly picked from a list.
This transform does not support torchscript.
Expand Down Expand Up @@ -157,9 +151,7 @@ def forward(self, *inputs: Any) -> Any:


class RandomOrder(Transform):
"""[BETA] Apply a list of transformations in a random order.
.. v2betastatus:: RandomOrder transform
"""Apply a list of transformations in a random order.
This transform does not support torchscript.
Expand Down
Loading

0 comments on commit e208641

Please sign in to comment.