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
a18b4af1
"torchvision/vscode:/vscode.git/clone" did not exist on "0467c9d74c9b34f91df905ed8cf8433de48d7fa5"
Unverified
Commit
a18b4af1
authored
Apr 20, 2021
by
Zhengyang Feng
Committed by
GitHub
Apr 20, 2021
Browse files
Add examples for RandomPerspective, RandomRotation, and RandomAffine (#3694)
parent
7dd4912c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
0 deletions
+27
-0
gallery/plot_transforms.py
gallery/plot_transforms.py
+27
-0
No files found.
gallery/plot_transforms.py
View file @
a18b4af1
...
@@ -62,3 +62,30 @@ plot(jitted_img, "Jitted image")
...
@@ -62,3 +62,30 @@ plot(jitted_img, "Jitted image")
# converts an image to grayscale
# converts an image to grayscale
gray_img
=
T
.
Grayscale
()(
orig_img
)
gray_img
=
T
.
Grayscale
()(
orig_img
)
plot
(
gray_img
,
"Grayscale image"
,
cmap
=
'gray'
)
plot
(
gray_img
,
"Grayscale image"
,
cmap
=
'gray'
)
####################################
# RandomPerspective
# -----------------
# The :class:`~torchvision.transforms.RandomPerspective` transform
# (see also :func:`~torchvision.transforms.functional.perspective`)
# performs random perspective transform on an image.
perspectived_img
=
T
.
RandomPerspective
(
distortion_scale
=
0.6
,
p
=
1.0
)(
orig_img
)
plot
(
perspectived_img
,
"Perspective transformed image"
)
####################################
# RandomRotation
# --------------
# The :class:`~torchvision.transforms.RandomRotation` transform
# (see also :func:`~torchvision.transforms.functional.rotate`)
# rotates an image with random angle.
rotated_img
=
T
.
RandomRotation
(
degrees
=
(
30
,
70
))(
orig_img
)
plot
(
rotated_img
,
"Rotated image"
)
####################################
# RandomAffine
# ------------
# The :class:`~torchvision.transforms.RandomAffine` transform
# (see also :func:`~torchvision.transforms.functional.affine`)
# performs random affine transform on an image.
affined_img
=
T
.
RandomAffine
(
degrees
=
(
30
,
70
),
translate
=
(
0.1
,
0.3
),
scale
=
(
0.5
,
0.75
))(
orig_img
)
plot
(
affined_img
,
"Affine transformed image"
)
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