Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
14c003bd
"git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "a0c22997fd45770fffd9b454625e9ab525fa2b16"
Unverified
Commit
14c003bd
authored
Feb 23, 2023
by
Nicolas Hug
Committed by
GitHub
Feb 23, 2023
Browse files
Add v2 docs for color transforms (#7310)
parent
c786d755
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
9 deletions
+35
-9
docs/source/transforms.rst
docs/source/transforms.rst
+1
-0
torchvision/transforms/v2/_color.py
torchvision/transforms/v2/_color.py
+34
-9
No files found.
docs/source/transforms.rst
View file @
14c003bd
...
@@ -131,6 +131,7 @@ Color
...
@@ -131,6 +131,7 @@ Color
ColorJitter
ColorJitter
v2.ColorJitter
v2.ColorJitter
v2.RandomPhotometricDistort
Grayscale
Grayscale
v2.Grayscale
v2.Grayscale
RandomGrayscale
RandomGrayscale
...
...
torchvision/transforms/v2/_color.py
View file @
14c003bd
...
@@ -46,7 +46,7 @@ class Grayscale(Transform):
...
@@ -46,7 +46,7 @@ class Grayscale(Transform):
class
RandomGrayscale
(
_RandomApplyTransform
):
class
RandomGrayscale
(
_RandomApplyTransform
):
"""[BETA] Randomly convert image to grayscale with a probability of p (default 0.1).
"""[BETA] Randomly convert image
or videos
to grayscale with a probability of p (default 0.1).
.. betastatus:: RandomGrayscale transform
.. betastatus:: RandomGrayscale transform
...
@@ -85,7 +85,7 @@ class RandomGrayscale(_RandomApplyTransform):
...
@@ -85,7 +85,7 @@ class RandomGrayscale(_RandomApplyTransform):
class
ColorJitter
(
Transform
):
class
ColorJitter
(
Transform
):
"""[BETA] Randomly change the brightness, contrast, saturation and hue of an image.
"""[BETA] Randomly change the brightness, contrast, saturation and hue of an image
or video
.
.. betastatus:: ColorJitter transform
.. betastatus:: ColorJitter transform
...
@@ -190,6 +190,31 @@ class ColorJitter(Transform):
...
@@ -190,6 +190,31 @@ class ColorJitter(Transform):
# TODO: This class seems to be untested
# TODO: This class seems to be untested
class
RandomPhotometricDistort
(
Transform
):
class
RandomPhotometricDistort
(
Transform
):
"""[BETA] Randomly distorts the image or video as used in `SSD: Single Shot
MultiBox Detector <https://arxiv.org/abs/1512.02325>`_.
.. betastatus:: 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.
Args:
brightness (tuple of float (min, max), optional): How much to jitter brightness.
brightness_factor is chosen uniformly from [min, max]. Should be non negative numbers.
contrast tuple of float (min, max), optional): How much to jitter contrast.
contrast_factor is chosen uniformly from [min, max]. Should be non-negative numbers.
saturation (tuple of float (min, max), optional): How much to jitter saturation.
saturation_factor is chosen uniformly from [min, max]. Should be non negative numbers.
hue (tuple of float (min, max), optional): How much to jitter hue.
hue_factor is chosen uniformly from [min, max]. Should have -0.5 <= min <= max <= 0.5.
To jitter hue, the pixel values of the input image has to be non-negative for conversion to HSV space;
thus it does not work if you normalize your image to an interval with negative values,
or use an interpolation that generates negative values before using this function.
p (float, optional) probability each distortion operation (contrast, saturation, ...) to be applied.
Default is 0.5.
"""
_transformed_types
=
(
_transformed_types
=
(
datapoints
.
Image
,
datapoints
.
Image
,
PIL
.
Image
.
Image
,
PIL
.
Image
.
Image
,
...
@@ -199,10 +224,10 @@ class RandomPhotometricDistort(Transform):
...
@@ -199,10 +224,10 @@ class RandomPhotometricDistort(Transform):
def
__init__
(
def
__init__
(
self
,
self
,
brightness
:
Tuple
[
float
,
float
]
=
(
0.875
,
1.125
),
contrast
:
Tuple
[
float
,
float
]
=
(
0.5
,
1.5
),
contrast
:
Tuple
[
float
,
float
]
=
(
0.5
,
1.5
),
saturation
:
Tuple
[
float
,
float
]
=
(
0.5
,
1.5
),
saturation
:
Tuple
[
float
,
float
]
=
(
0.5
,
1.5
),
hue
:
Tuple
[
float
,
float
]
=
(
-
0.05
,
0.05
),
hue
:
Tuple
[
float
,
float
]
=
(
-
0.05
,
0.05
),
brightness
:
Tuple
[
float
,
float
]
=
(
0.875
,
1.125
),
p
:
float
=
0.5
,
p
:
float
=
0.5
,
):
):
super
().
__init__
()
super
().
__init__
()
...
@@ -266,7 +291,7 @@ class RandomPhotometricDistort(Transform):
...
@@ -266,7 +291,7 @@ class RandomPhotometricDistort(Transform):
class
RandomEqualize
(
_RandomApplyTransform
):
class
RandomEqualize
(
_RandomApplyTransform
):
"""[BETA] Equalize the histogram of the given image
randomly
with a given probability.
"""[BETA] Equalize the histogram of the given image
or video
with a given probability.
.. betastatus:: RandomEqualize transform
.. betastatus:: RandomEqualize transform
...
@@ -285,7 +310,7 @@ class RandomEqualize(_RandomApplyTransform):
...
@@ -285,7 +310,7 @@ class RandomEqualize(_RandomApplyTransform):
class
RandomInvert
(
_RandomApplyTransform
):
class
RandomInvert
(
_RandomApplyTransform
):
"""[BETA] Inverts the colors of the given image
randomly
with a given probability.
"""[BETA] Inverts the colors of the given image
or video
with a given probability.
.. betastatus:: RandomInvert transform
.. betastatus:: RandomInvert transform
...
@@ -304,7 +329,7 @@ class RandomInvert(_RandomApplyTransform):
...
@@ -304,7 +329,7 @@ class RandomInvert(_RandomApplyTransform):
class
RandomPosterize
(
_RandomApplyTransform
):
class
RandomPosterize
(
_RandomApplyTransform
):
"""[BETA] Posterize the image
randomly
with a given probability by reducing the
"""[BETA] Posterize the image
or video
with a given probability by reducing the
number of bits for each color channel.
number of bits for each color channel.
.. betastatus:: RandomPosterize transform
.. betastatus:: RandomPosterize transform
...
@@ -329,7 +354,7 @@ class RandomPosterize(_RandomApplyTransform):
...
@@ -329,7 +354,7 @@ class RandomPosterize(_RandomApplyTransform):
class
RandomSolarize
(
_RandomApplyTransform
):
class
RandomSolarize
(
_RandomApplyTransform
):
"""[BETA] Solarize the image
randomly
with a given probability by inverting all pixel
"""[BETA] Solarize the image
or video
with a given probability by inverting all pixel
values above a threshold.
values above a threshold.
.. betastatus:: RandomSolarize transform
.. betastatus:: RandomSolarize transform
...
@@ -354,7 +379,7 @@ class RandomSolarize(_RandomApplyTransform):
...
@@ -354,7 +379,7 @@ class RandomSolarize(_RandomApplyTransform):
class
RandomAutocontrast
(
_RandomApplyTransform
):
class
RandomAutocontrast
(
_RandomApplyTransform
):
"""[BETA] Autocontrast the pixels of the given image
randomly
with a given probability.
"""[BETA] Autocontrast the pixels of the given image
or video
with a given probability.
.. betastatus:: RandomAutocontrast transform
.. betastatus:: RandomAutocontrast transform
...
@@ -373,7 +398,7 @@ class RandomAutocontrast(_RandomApplyTransform):
...
@@ -373,7 +398,7 @@ class RandomAutocontrast(_RandomApplyTransform):
class
RandomAdjustSharpness
(
_RandomApplyTransform
):
class
RandomAdjustSharpness
(
_RandomApplyTransform
):
"""[BETA] Adjust the sharpness of the image
randomly
with a given probability.
"""[BETA] Adjust the sharpness of the image
or video
with a given probability.
.. betastatus:: RandomAdjustSharpness transform
.. betastatus:: RandomAdjustSharpness transform
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment