forked from pytorch/pytorch.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransforms.html
2669 lines (2385 loc) · 212 KB
/
transforms.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta name="robots" content="noindex">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>torchvision.transforms — PyTorch 1.7.1 documentation</title>
<link rel="canonical" href="https://pytorch.org/vision/0.8/transforms.html"/>
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<!-- <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" type="text/css" />
<link rel="stylesheet" href="../_static/css/jit.css" type="text/css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" type="text/css" />
<link rel="stylesheet" href="../_static/katex-math.css" type="text/css" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<script src="../_static/js/modernizr.min.js"></script>
<!-- Preload the theme fonts -->
<link rel="preload" href="../_static/fonts/FreightSans/freight-sans-book.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/fonts/FreightSans/freight-sans-medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/fonts/IBMPlexMono/IBMPlexMono-Medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/fonts/FreightSans/freight-sans-bold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/fonts/FreightSans/freight-sans-medium-italic.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/fonts/IBMPlexMono/IBMPlexMono-SemiBold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<!-- Preload the katex fonts -->
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Math-Italic.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Main-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Main-Bold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size1-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size4-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size2-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Size3-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/fonts/KaTeX_Caligraphic-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
</head>
<div class="container-fluid header-holder tutorials-header" id="header-holder">
<div class="container">
<div class="header-container">
<a class="header-logo" href="https://pytorch.org/" aria-label="PyTorch"></a>
<div class="main-menu">
<ul>
<li>
<a href="https://pytorch.org/get-started">Get Started</a>
</li>
<li>
<a href="https://pytorch.org/ecosystem">Ecosystem</a>
</li>
<li>
<a href="https://pytorch.org/mobile">Mobile</a>
</li>
<li>
<a href="https://pytorch.org/blog/">Blog</a>
</li>
<li>
<a href="https://pytorch.org/tutorials">Tutorials</a>
</li>
<li class="active">
<div id="resourcesDropdownButton" data-toggle="resources-dropdown" class="resources-dropdown">
<a class="resource-option with-down-orange-arrow">
Docs
</a>
<div class="resources-dropdown-menu">
<a class="doc-dropdown-option nav-dropdown-item" href="https://pytorch.org/docs/1.7.1/index.html">
<span class="dropdown-title">PyTorch</span>
<p></p>
</a>
<a class="doc-dropdown-option nav-dropdown-item" href="https://pytorch.org/audio/0.7.0/index.html">
<span class="dropdown-title">torchaudio</span>
<p></p>
</a>
<a class="doc-dropdown-option nav-dropdown-item" href="https://pytorch.org/text/0.8.1/index.html">
<span class="dropdown-title">torchtext</span>
<p></p>
</a>
<a class="doc-dropdown-option nav-dropdown-item" href="https://pytorch.org/vision/0.8/">
<span class="dropdown-title">torchvision</span>
<p></p>
</a>
<a class="doc-dropdown-option nav-dropdown-item" href="https://pytorch.org/elastic/">
<span class="dropdown-title">TorchElastic</span>
<p></p>
</a>
<a class="doc-dropdown-option nav-dropdown-item" href="https://pytorch.org/serve/">
<span class="dropdown-title">TorchServe</span>
<p></p>
</a>
<a class="doc-dropdown-option nav-dropdown-item" href="https://pytorch.org/xla">
<span class="dropdown-title">PyTorch on XLA Devices</span>
<p></p>
</a>
</div>
</li>
<li>
<div id="resourcesDropdownButton" data-toggle="resources-dropdown" class="resources-dropdown">
<a class="resource-option with-down-arrow">
Resources
</a>
<div class="resources-dropdown-menu">
<a class="nav-dropdown-item" href="https://pytorch.org/features">
<span class="dropdown-title">About</span>
<p>Learn about PyTorch’s features and capabilities</p>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/#community-module">
<span class="dropdown-title">Community</span>
<p>Join the PyTorch developer community to contribute, learn, and get your questions answered.</p>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/resources">
<span class="dropdown-title">Developer Resources</span>
<p>Find resources and get questions answered</p>
</a>
<a class="nav-dropdown-item" href="https://discuss.pytorch.org/" target="_blank">
<span class="dropdown-title">Forums</span>
<p>A place to discuss PyTorch code, issues, install, research</p>
</a>
<a class="nav-dropdown-item" href="https://pytorch.org/hub">
<span class="dropdown-title">Models (Beta)</span>
<p>Discover, publish, and reuse pre-trained models</p>
</a>
</div>
</div>
</li>
<li>
<a href="https://github.com/pytorch/pytorch">Github</a>
</li>
</ul>
</div>
<a class="main-menu-open-button" href="#" data-behavior="open-mobile-menu"></a>
</div>
</div>
</div>
<body class="pytorch-body">
<div class="table-of-contents-link-wrapper">
<span>Table of Contents</span>
<a href="#" class="toggle-table-of-contents" data-behavior="toggle-table-of-contents"></a>
</div>
<nav data-toggle="wy-nav-shift" class="pytorch-left-menu" id="pytorch-left-menu">
<div class="pytorch-side-scroll">
<div class="pytorch-menu pytorch-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<div class="pytorch-left-menu-search">
<div class="version">
<a href='http://pytorch.org/docs/versions.html'>1.7.1 ▼</a>
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search Docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<p class="caption"><span class="caption-text">Notes</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../notes/amp_examples.html">Automatic Mixed Precision examples</a></li>
<li class="toctree-l1"><a class="reference internal" href="../notes/autograd.html">Autograd mechanics</a></li>
<li class="toctree-l1"><a class="reference internal" href="../notes/broadcasting.html">Broadcasting semantics</a></li>
<li class="toctree-l1"><a class="reference internal" href="../notes/cpu_threading_torchscript_inference.html">CPU threading and TorchScript inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="../notes/cuda.html">CUDA semantics</a></li>
<li class="toctree-l1"><a class="reference internal" href="../notes/ddp.html">Distributed Data Parallel</a></li>
<li class="toctree-l1"><a class="reference internal" href="../notes/extending.html">Extending PyTorch</a></li>
<li class="toctree-l1"><a class="reference internal" href="../notes/faq.html">Frequently Asked Questions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../notes/large_scale_deployments.html">Features for large-scale deployments</a></li>
<li class="toctree-l1"><a class="reference internal" href="../notes/multiprocessing.html">Multiprocessing best practices</a></li>
<li class="toctree-l1"><a class="reference internal" href="../notes/randomness.html">Reproducibility</a></li>
<li class="toctree-l1"><a class="reference internal" href="../notes/serialization.html">Serialization semantics</a></li>
<li class="toctree-l1"><a class="reference internal" href="../notes/windows.html">Windows FAQ</a></li>
</ul>
<p class="caption"><span class="caption-text">Language Bindings</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../cpp_index.html">C++</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/javadoc/">Javadoc</a></li>
</ul>
<p class="caption"><span class="caption-text">Python API</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../torch.html">torch</a></li>
<li class="toctree-l1"><a class="reference internal" href="../nn.html">torch.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../nn.functional.html">torch.nn.functional</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tensors.html">torch.Tensor</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tensor_attributes.html">Tensor Attributes</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tensor_view.html">Tensor Views</a></li>
<li class="toctree-l1"><a class="reference internal" href="../autograd.html">torch.autograd</a></li>
<li class="toctree-l1"><a class="reference internal" href="../cuda.html">torch.cuda</a></li>
<li class="toctree-l1"><a class="reference internal" href="../amp.html">torch.cuda.amp</a></li>
<li class="toctree-l1"><a class="reference internal" href="../backends.html">torch.backends</a></li>
<li class="toctree-l1"><a class="reference internal" href="../distributed.html">torch.distributed</a></li>
<li class="toctree-l1"><a class="reference internal" href="../distributions.html">torch.distributions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../fft.html">torch.fft</a></li>
<li class="toctree-l1"><a class="reference internal" href="../futures.html">torch.futures</a></li>
<li class="toctree-l1"><a class="reference internal" href="../hub.html">torch.hub</a></li>
<li class="toctree-l1"><a class="reference internal" href="../jit.html">torch.jit</a></li>
<li class="toctree-l1"><a class="reference internal" href="../linalg.html">torch.linalg</a></li>
<li class="toctree-l1"><a class="reference internal" href="../nn.init.html">torch.nn.init</a></li>
<li class="toctree-l1"><a class="reference internal" href="../onnx.html">torch.onnx</a></li>
<li class="toctree-l1"><a class="reference internal" href="../optim.html">torch.optim</a></li>
<li class="toctree-l1"><a class="reference internal" href="../complex_numbers.html">Complex Numbers</a></li>
<li class="toctree-l1"><a class="reference internal" href="../quantization.html">Quantization</a></li>
<li class="toctree-l1"><a class="reference internal" href="../rpc.html">Distributed RPC Framework</a></li>
<li class="toctree-l1"><a class="reference internal" href="../random.html">torch.random</a></li>
<li class="toctree-l1"><a class="reference internal" href="../sparse.html">torch.sparse</a></li>
<li class="toctree-l1"><a class="reference internal" href="../storage.html">torch.Storage</a></li>
<li class="toctree-l1"><a class="reference internal" href="../bottleneck.html">torch.utils.bottleneck</a></li>
<li class="toctree-l1"><a class="reference internal" href="../checkpoint.html">torch.utils.checkpoint</a></li>
<li class="toctree-l1"><a class="reference internal" href="../cpp_extension.html">torch.utils.cpp_extension</a></li>
<li class="toctree-l1"><a class="reference internal" href="../data.html">torch.utils.data</a></li>
<li class="toctree-l1"><a class="reference internal" href="../dlpack.html">torch.utils.dlpack</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mobile_optimizer.html">torch.utils.mobile_optimizer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../model_zoo.html">torch.utils.model_zoo</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tensorboard.html">torch.utils.tensorboard</a></li>
<li class="toctree-l1"><a class="reference internal" href="../type_info.html">Type Info</a></li>
<li class="toctree-l1"><a class="reference internal" href="../named_tensor.html">Named Tensors</a></li>
<li class="toctree-l1"><a class="reference internal" href="../name_inference.html">Named Tensors operator coverage</a></li>
<li class="toctree-l1"><a class="reference internal" href="../__config__.html">torch.__config__</a></li>
</ul>
<p class="caption"><span class="caption-text">Libraries</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/audio">torchaudio</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/text">torchtext</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/vision">torchvision</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/elastic/">TorchElastic</a></li>
<li class="toctree-l1"><a class="reference external" href="https://pytorch.org/serve">TorchServe</a></li>
<li class="toctree-l1"><a class="reference external" href="http://pytorch.org/xla/">PyTorch on XLA Devices</a></li>
</ul>
<p class="caption"><span class="caption-text">Community</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../community/contribution_guide.html">PyTorch Contribution Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="../community/governance.html">PyTorch Governance</a></li>
<li class="toctree-l1"><a class="reference internal" href="../community/persons_of_interest.html">PyTorch Governance | Persons of Interest</a></li>
</ul>
</div>
</div>
</nav>
<div class="pytorch-container">
<div class="pytorch-page-level-bar" id="pytorch-page-level-bar">
<div class="pytorch-breadcrumbs-wrapper">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="pytorch-breadcrumbs">
<li>
<a href="../index.html">
Docs
</a> >
</li>
<li>torchvision.transforms</li>
<li class="pytorch-breadcrumbs-aside">
<a href="../_sources/torchvision/transforms.rst.txt" rel="nofollow"><img src="../_static/images/view-page-source-icon.svg"></a>
</li>
</ul>
</div>
</div>
<div class="pytorch-shortcuts-wrapper" id="pytorch-shortcuts-wrapper">
Shortcuts
</div>
</div>
<section data-toggle="wy-nav-shift" id="pytorch-content-wrap" class="pytorch-content-wrap">
<div class="pytorch-content-left">
<div class="rst-content">
<div role="main" class="main-content" itemscope="itemscope" itemtype="http://schema.org/Article">
<article itemprop="articleBody" id="pytorch-article" class="pytorch-article">
<div class="section" id="torchvision-transforms">
<h1>torchvision.transforms<a class="headerlink" href="#torchvision-transforms" title="Permalink to this headline">¶</a></h1>
<p>Transforms are common image transformations. They can be chained together using <a class="reference internal" href="#torchvision.transforms.Compose" title="torchvision.transforms.Compose"><code class="xref py py-class docutils literal notranslate"><span class="pre">Compose</span></code></a>.
Additionally, there is the <a class="reference internal" href="#module-torchvision.transforms.functional" title="torchvision.transforms.functional"><code class="xref py py-mod docutils literal notranslate"><span class="pre">torchvision.transforms.functional</span></code></a> module.
Functional transforms give fine-grained control over the transformations.
This is useful if you have to build a more complex transformation pipeline
(e.g. in the case of segmentation tasks).</p>
<p>All transformations accept PIL Image, Tensor Image or batch of Tensor Images as input. Tensor Image is a tensor with
<code class="docutils literal notranslate"><span class="pre">(C,</span> <span class="pre">H,</span> <span class="pre">W)</span></code> shape, where <code class="docutils literal notranslate"><span class="pre">C</span></code> is a number of channels, <code class="docutils literal notranslate"><span class="pre">H</span></code> and <code class="docutils literal notranslate"><span class="pre">W</span></code> are image height and width. Batch of
Tensor Images is a tensor of <code class="docutils literal notranslate"><span class="pre">(B,</span> <span class="pre">C,</span> <span class="pre">H,</span> <span class="pre">W)</span></code> shape, where <code class="docutils literal notranslate"><span class="pre">B</span></code> 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.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p>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:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Previous versions</span>
<span class="c1"># import random</span>
<span class="c1"># random.seed(12)</span>
<span class="c1"># Now</span>
<span class="kn">import</span> <span class="nn">torch</span>
<span class="n">torch</span><span class="o">.</span><span class="n">manual_seed</span><span class="p">(</span><span class="mi">17</span><span class="p">)</span>
</pre></div>
</div>
<p>Please, keep in mind that the same seed for torch random generator and Python random generator will not
produce the same results.</p>
</div>
<div class="section" id="scriptable-transforms">
<h2>Scriptable transforms<a class="headerlink" href="#scriptable-transforms" title="Permalink to this headline">¶</a></h2>
<p>In order to script the transformations, please use <code class="docutils literal notranslate"><span class="pre">torch.nn.Sequential</span></code> instead of <a class="reference internal" href="#torchvision.transforms.Compose" title="torchvision.transforms.Compose"><code class="xref py py-class docutils literal notranslate"><span class="pre">Compose</span></code></a>.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">transforms</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">nn</span><span class="o">.</span><span class="n">Sequential</span><span class="p">(</span>
<span class="n">transforms</span><span class="o">.</span><span class="n">CenterCrop</span><span class="p">(</span><span class="mi">10</span><span class="p">),</span>
<span class="n">transforms</span><span class="o">.</span><span class="n">Normalize</span><span class="p">((</span><span class="mf">0.485</span><span class="p">,</span> <span class="mf">0.456</span><span class="p">,</span> <span class="mf">0.406</span><span class="p">),</span> <span class="p">(</span><span class="mf">0.229</span><span class="p">,</span> <span class="mf">0.224</span><span class="p">,</span> <span class="mf">0.225</span><span class="p">)),</span>
<span class="p">)</span>
<span class="n">scripted_transforms</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">jit</span><span class="o">.</span><span class="n">script</span><span class="p">(</span><span class="n">transforms</span><span class="p">)</span>
</pre></div>
</div>
<p>Make sure to use only scriptable transformations, i.e. that work with <code class="docutils literal notranslate"><span class="pre">torch.Tensor</span></code> and does not require
<cite>lambda</cite> functions or <code class="docutils literal notranslate"><span class="pre">PIL.Image</span></code>.</p>
<p>For any custom transformations to be used with <code class="docutils literal notranslate"><span class="pre">torch.jit.script</span></code>, they should be derived from <code class="docutils literal notranslate"><span class="pre">torch.nn.Module</span></code>.</p>
</div>
<div class="section" id="compositions-of-transforms">
<h2>Compositions of transforms<a class="headerlink" href="#compositions-of-transforms" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="torchvision.transforms.Compose">
<em class="property">class </em><code class="sig-prename descclassname">torchvision.transforms.</code><code class="sig-name descname">Compose</code><span class="sig-paren">(</span><em class="sig-param">transforms</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#Compose"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.Compose" title="Permalink to this definition">¶</a></dt>
<dd><p>Composes several transforms together. This transform does not support torchscript.
Please, see the note below.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>transforms</strong> (list of <code class="docutils literal notranslate"><span class="pre">Transform</span></code> objects) – list of transforms to compose.</p>
</dd>
</dl>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">transforms</span><span class="o">.</span><span class="n">Compose</span><span class="p">([</span>
<span class="gp">>>> </span> <span class="n">transforms</span><span class="o">.</span><span class="n">CenterCrop</span><span class="p">(</span><span class="mi">10</span><span class="p">),</span>
<span class="gp">>>> </span> <span class="n">transforms</span><span class="o">.</span><span class="n">ToTensor</span><span class="p">(),</span>
<span class="gp">>>> </span><span class="p">])</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>In order to script the transformations, please use <code class="docutils literal notranslate"><span class="pre">torch.nn.Sequential</span></code> as below.</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">transforms</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">nn</span><span class="o">.</span><span class="n">Sequential</span><span class="p">(</span>
<span class="gp">>>> </span> <span class="n">transforms</span><span class="o">.</span><span class="n">CenterCrop</span><span class="p">(</span><span class="mi">10</span><span class="p">),</span>
<span class="gp">>>> </span> <span class="n">transforms</span><span class="o">.</span><span class="n">Normalize</span><span class="p">((</span><span class="mf">0.485</span><span class="p">,</span> <span class="mf">0.456</span><span class="p">,</span> <span class="mf">0.406</span><span class="p">),</span> <span class="p">(</span><span class="mf">0.229</span><span class="p">,</span> <span class="mf">0.224</span><span class="p">,</span> <span class="mf">0.225</span><span class="p">)),</span>
<span class="gp">>>> </span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">scripted_transforms</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">jit</span><span class="o">.</span><span class="n">script</span><span class="p">(</span><span class="n">transforms</span><span class="p">)</span>
</pre></div>
</div>
<p>Make sure to use only scriptable transformations, i.e. that work with <code class="docutils literal notranslate"><span class="pre">torch.Tensor</span></code>, does not require
<cite>lambda</cite> functions or <code class="docutils literal notranslate"><span class="pre">PIL.Image</span></code>.</p>
</div>
</dd></dl>
</div>
<div class="section" id="transforms-on-pil-image-and-torch-tensor">
<h2>Transforms on PIL Image and torch.*Tensor<a class="headerlink" href="#transforms-on-pil-image-and-torch-tensor" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="torchvision.transforms.CenterCrop">
<em class="property">class </em><code class="sig-prename descclassname">torchvision.transforms.</code><code class="sig-name descname">CenterCrop</code><span class="sig-paren">(</span><em class="sig-param">size</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#CenterCrop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.CenterCrop" title="Permalink to this definition">¶</a></dt>
<dd><p>Crops the given image at the center.
The image can be a PIL Image or a torch Tensor, in which case it is expected
to have […, H, W] shape, where … means an arbitrary number of leading dimensions</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>size</strong> (<em>sequence</em><em> or </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><em>int</em></a>) – Desired output size of the crop. If size is an
int instead of sequence like (h, w), a square crop (size, size) is
made. If provided a tuple or list of length 1, it will be interpreted as (size[0], size[0]).</p>
</dd>
</dl>
<dl class="method">
<dt id="torchvision.transforms.CenterCrop.forward">
<code class="sig-name descname">forward</code><span class="sig-paren">(</span><em class="sig-param">img</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#CenterCrop.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.CenterCrop.forward" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>img</strong> (<em>PIL Image</em><em> or </em><a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor"><em>Tensor</em></a>) – Image to be cropped.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Cropped image.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>PIL Image or <a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor">Tensor</a></p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="torchvision.transforms.ColorJitter">
<em class="property">class </em><code class="sig-prename descclassname">torchvision.transforms.</code><code class="sig-name descname">ColorJitter</code><span class="sig-paren">(</span><em class="sig-param">brightness=0</em>, <em class="sig-param">contrast=0</em>, <em class="sig-param">saturation=0</em>, <em class="sig-param">hue=0</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#ColorJitter"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.ColorJitter" title="Permalink to this definition">¶</a></dt>
<dd><p>Randomly change the brightness, contrast and saturation of an image.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>brightness</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><em>float</em></a><em> or </em><em>tuple of python:float</em><em> (</em><em>min</em><em>, </em><em>max</em><em>)</em>) – How much to jitter brightness.
brightness_factor is chosen uniformly from [max(0, 1 - brightness), 1 + brightness]
or the given [min, max]. Should be non negative numbers.</p></li>
<li><p><strong>contrast</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><em>float</em></a><em> or </em><em>tuple of python:float</em><em> (</em><em>min</em><em>, </em><em>max</em><em>)</em>) – How much to jitter contrast.
contrast_factor is chosen uniformly from [max(0, 1 - contrast), 1 + contrast]
or the given [min, max]. Should be non negative numbers.</p></li>
<li><p><strong>saturation</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><em>float</em></a><em> or </em><em>tuple of python:float</em><em> (</em><em>min</em><em>, </em><em>max</em><em>)</em>) – How much to jitter saturation.
saturation_factor is chosen uniformly from [max(0, 1 - saturation), 1 + saturation]
or the given [min, max]. Should be non negative numbers.</p></li>
<li><p><strong>hue</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><em>float</em></a><em> or </em><em>tuple of python:float</em><em> (</em><em>min</em><em>, </em><em>max</em><em>)</em>) – How much to jitter hue.
hue_factor is chosen uniformly from [-hue, hue] or the given [min, max].
Should have 0<= hue <= 0.5 or -0.5 <= min <= max <= 0.5.</p></li>
</ul>
</dd>
</dl>
<dl class="method">
<dt id="torchvision.transforms.ColorJitter.forward">
<code class="sig-name descname">forward</code><span class="sig-paren">(</span><em class="sig-param">img</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#ColorJitter.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.ColorJitter.forward" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>img</strong> (<em>PIL Image</em><em> or </em><a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor"><em>Tensor</em></a>) – Input image.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Color jittered image.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>PIL Image or <a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor">Tensor</a></p>
</dd>
</dl>
</dd></dl>
<dl class="method">
<dt id="torchvision.transforms.ColorJitter.get_params">
<em class="property">static </em><code class="sig-name descname">get_params</code><span class="sig-paren">(</span><em class="sig-param">brightness</em>, <em class="sig-param">contrast</em>, <em class="sig-param">saturation</em>, <em class="sig-param">hue</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#ColorJitter.get_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.ColorJitter.get_params" title="Permalink to this definition">¶</a></dt>
<dd><p>Get a randomized transform to be applied on image.</p>
<p>Arguments are same as that of __init__.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>Transform which randomly adjusts brightness, contrast and
saturation in a random order.</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="torchvision.transforms.FiveCrop">
<em class="property">class </em><code class="sig-prename descclassname">torchvision.transforms.</code><code class="sig-name descname">FiveCrop</code><span class="sig-paren">(</span><em class="sig-param">size</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#FiveCrop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.FiveCrop" title="Permalink to this definition">¶</a></dt>
<dd><p>Crop the given image into four corners and the central crop.
The image can be a PIL Image or a Tensor, in which case it is expected
to have […, H, W] shape, where … means an arbitrary number of leading
dimensions</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This transform returns a tuple of images and there may be a mismatch in the number of
inputs and targets your Dataset returns. See below for an example of how to deal with
this.</p>
</div>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>size</strong> (<em>sequence</em><em> or </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><em>int</em></a>) – Desired output size of the crop. If size is an <code class="docutils literal notranslate"><span class="pre">int</span></code>
instead of sequence like (h, w), a square crop of size (size, size) is made.
If provided a tuple or list of length 1, it will be interpreted as (size[0], size[0]).</p>
</dd>
</dl>
<p class="rubric">Example</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">transform</span> <span class="o">=</span> <span class="n">Compose</span><span class="p">([</span>
<span class="gp">>>> </span> <span class="n">FiveCrop</span><span class="p">(</span><span class="n">size</span><span class="p">),</span> <span class="c1"># this is a list of PIL Images</span>
<span class="gp">>>> </span> <span class="n">Lambda</span><span class="p">(</span><span class="k">lambda</span> <span class="n">crops</span><span class="p">:</span> <span class="n">torch</span><span class="o">.</span><span class="n">stack</span><span class="p">([</span><span class="n">ToTensor</span><span class="p">()(</span><span class="n">crop</span><span class="p">)</span> <span class="k">for</span> <span class="n">crop</span> <span class="ow">in</span> <span class="n">crops</span><span class="p">]))</span> <span class="c1"># returns a 4D tensor</span>
<span class="gp">>>> </span><span class="p">])</span>
<span class="gp">>>> </span><span class="c1">#In your test loop you can do the following:</span>
<span class="gp">>>> </span><span class="nb">input</span><span class="p">,</span> <span class="n">target</span> <span class="o">=</span> <span class="n">batch</span> <span class="c1"># input is a 5d tensor, target is 2d</span>
<span class="gp">>>> </span><span class="n">bs</span><span class="p">,</span> <span class="n">ncrops</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">h</span><span class="p">,</span> <span class="n">w</span> <span class="o">=</span> <span class="nb">input</span><span class="o">.</span><span class="n">size</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">result</span> <span class="o">=</span> <span class="n">model</span><span class="p">(</span><span class="nb">input</span><span class="o">.</span><span class="n">view</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">c</span><span class="p">,</span> <span class="n">h</span><span class="p">,</span> <span class="n">w</span><span class="p">))</span> <span class="c1"># fuse batch size and ncrops</span>
<span class="gp">>>> </span><span class="n">result_avg</span> <span class="o">=</span> <span class="n">result</span><span class="o">.</span><span class="n">view</span><span class="p">(</span><span class="n">bs</span><span class="p">,</span> <span class="n">ncrops</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">mean</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="c1"># avg over crops</span>
</pre></div>
</div>
<dl class="method">
<dt id="torchvision.transforms.FiveCrop.forward">
<code class="sig-name descname">forward</code><span class="sig-paren">(</span><em class="sig-param">img</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#FiveCrop.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.FiveCrop.forward" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>img</strong> (<em>PIL Image</em><em> or </em><a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor"><em>Tensor</em></a>) – Image to be cropped.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>tuple of 5 images. Image can be PIL Image or Tensor</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="torchvision.transforms.Grayscale">
<em class="property">class </em><code class="sig-prename descclassname">torchvision.transforms.</code><code class="sig-name descname">Grayscale</code><span class="sig-paren">(</span><em class="sig-param">num_output_channels=1</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#Grayscale"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.Grayscale" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert image to grayscale.
The image can be a PIL Image or a Tensor, in which case it is expected
to have […, 3, H, W] shape, where … means an arbitrary number of leading
dimensions</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>num_output_channels</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><em>int</em></a>) – (1 or 3) number of channels desired for output image</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><dl class="simple">
<dt>Grayscale version of the input.</dt><dd><ul class="simple">
<li><p>If <code class="docutils literal notranslate"><span class="pre">num_output_channels</span> <span class="pre">==</span> <span class="pre">1</span></code> : returned image is single channel</p></li>
<li><p>If <code class="docutils literal notranslate"><span class="pre">num_output_channels</span> <span class="pre">==</span> <span class="pre">3</span></code> : returned image is 3 channel with r == g == b</p></li>
</ul>
</dd>
</dl>
</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>PIL Image</p>
</dd>
</dl>
<dl class="method">
<dt id="torchvision.transforms.Grayscale.forward">
<code class="sig-name descname">forward</code><span class="sig-paren">(</span><em class="sig-param">img</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#Grayscale.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.Grayscale.forward" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>img</strong> (<em>PIL Image</em><em> or </em><a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor"><em>Tensor</em></a>) – Image to be converted to grayscale.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Grayscaled image.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>PIL Image or <a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor">Tensor</a></p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="torchvision.transforms.Pad">
<em class="property">class </em><code class="sig-prename descclassname">torchvision.transforms.</code><code class="sig-name descname">Pad</code><span class="sig-paren">(</span><em class="sig-param">padding</em>, <em class="sig-param">fill=0</em>, <em class="sig-param">padding_mode='constant'</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#Pad"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.Pad" title="Permalink to this definition">¶</a></dt>
<dd><p>Pad the given image on all sides with the given “pad” value.
The image can be a PIL Image or a torch Tensor, in which case it is expected
to have […, H, W] shape, where … means an arbitrary number of leading dimensions</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>padding</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><em>int</em></a><em> or </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.9)"><em>tuple</em></a><em> or </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.9)"><em>list</em></a>) – Padding on each border. If a single int is provided this
is used to pad all borders. If tuple of length 2 is provided this is the padding
on left/right and top/bottom respectively. If a tuple of length 4 is provided
this is the padding for the left, top, right and bottom borders respectively.
In torchscript mode padding as single int is not supported, use a tuple or
list of length 1: <code class="docutils literal notranslate"><span class="pre">[padding,</span> <span class="pre">]</span></code>.</p></li>
<li><p><strong>fill</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><em>int</em></a><em> or </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.9)"><em>tuple</em></a>) – Pixel fill value for constant fill. Default is 0. If a tuple of
length 3, it is used to fill R, G, B channels respectively.
This value is only used when the padding_mode is constant</p></li>
<li><p><strong>padding_mode</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.9)"><em>str</em></a>) – <p>Type of padding. Should be: constant, edge, reflect or symmetric.
Default is constant. Mode symmetric is not yet supported for Tensor inputs.</p>
<ul>
<li><p>constant: pads with a constant value, this value is specified with fill</p></li>
<li><p>edge: pads with the last value at the edge of the image</p></li>
<li><p>reflect: pads with reflection of image without repeating the last value on the edge</p>
<blockquote>
<div><p>For example, padding [1, 2, 3, 4] with 2 elements on both sides in reflect mode
will result in [3, 2, 1, 2, 3, 4, 3, 2]</p>
</div></blockquote>
</li>
<li><p>symmetric: pads with reflection of image repeating the last value on the edge</p>
<blockquote>
<div><p>For example, padding [1, 2, 3, 4] with 2 elements on both sides in symmetric mode
will result in [2, 1, 1, 2, 3, 4, 4, 3]</p>
</div></blockquote>
</li>
</ul>
</p></li>
</ul>
</dd>
</dl>
<dl class="method">
<dt id="torchvision.transforms.Pad.forward">
<code class="sig-name descname">forward</code><span class="sig-paren">(</span><em class="sig-param">img</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#Pad.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.Pad.forward" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>img</strong> (<em>PIL Image</em><em> or </em><a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor"><em>Tensor</em></a>) – Image to be padded.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Padded image.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>PIL Image or <a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor">Tensor</a></p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="torchvision.transforms.RandomAffine">
<em class="property">class </em><code class="sig-prename descclassname">torchvision.transforms.</code><code class="sig-name descname">RandomAffine</code><span class="sig-paren">(</span><em class="sig-param">degrees</em>, <em class="sig-param">translate=None</em>, <em class="sig-param">scale=None</em>, <em class="sig-param">shear=None</em>, <em class="sig-param">resample=0</em>, <em class="sig-param">fillcolor=0</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#RandomAffine"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.RandomAffine" title="Permalink to this definition">¶</a></dt>
<dd><p>Random affine transformation of the image keeping center invariant.
The image can be a PIL Image or a Tensor, in which case it is expected
to have […, H, W] shape, where … means an arbitrary number of leading dimensions.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>degrees</strong> (<em>sequence</em><em> or </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><em>float</em></a><em> or </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><em>int</em></a>) – Range of degrees to select from.
If degrees is a number instead of sequence like (min, max), the range of degrees
will be (-degrees, +degrees). Set to 0 to deactivate rotations.</p></li>
<li><p><strong>translate</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.9)"><em>tuple</em></a><em>, </em><em>optional</em>) – tuple of maximum absolute fraction for horizontal
and vertical translations. For example translate=(a, b), then horizontal shift
is randomly sampled in the range -img_width * a < dx < img_width * a and vertical shift is
randomly sampled in the range -img_height * b < dy < img_height * b. Will not translate by default.</p></li>
<li><p><strong>scale</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.9)"><em>tuple</em></a><em>, </em><em>optional</em>) – scaling factor interval, e.g (a, b), then scale is
randomly sampled from the range a <= scale <= b. Will keep original scale by default.</p></li>
<li><p><strong>shear</strong> (<em>sequence</em><em> or </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><em>float</em></a><em> or </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><em>int</em></a><em>, </em><em>optional</em>) – Range of degrees to select from.
If shear is a number, a shear parallel to the x axis in the range (-shear, +shear)
will be applied. Else if shear is a tuple or list of 2 values a shear parallel to the x axis in the
range (shear[0], shear[1]) will be applied. Else if shear is a tuple or list of 4 values,
a x-axis shear in (shear[0], shear[1]) and y-axis shear in (shear[2], shear[3]) will be applied.
Will not apply shear by default.</p></li>
<li><p><strong>resample</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><em>int</em></a><em>, </em><em>optional</em>) – An optional resampling filter. See <a class="reference external" href="https://pillow.readthedocs.io/en/latest/handbook/concepts.html#filters">filters</a> for more information.
If omitted, or if the image has mode “1” or “P”, it is set to <code class="docutils literal notranslate"><span class="pre">PIL.Image.NEAREST</span></code>.
If input is Tensor, only <code class="docutils literal notranslate"><span class="pre">PIL.Image.NEAREST</span></code> and <code class="docutils literal notranslate"><span class="pre">PIL.Image.BILINEAR</span></code> are supported.</p></li>
<li><p><strong>fillcolor</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.9)"><em>tuple</em></a><em> or </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><em>int</em></a>) – Optional fill color (Tuple for RGB Image and int for grayscale) for the area
outside the transform in the output image (Pillow>=5.0.0). This option is not supported for Tensor
input. Fill value for the area outside the transform in the output image is always 0.</p></li>
</ul>
</dd>
</dl>
<dl class="method">
<dt id="torchvision.transforms.RandomAffine.forward">
<code class="sig-name descname">forward</code><span class="sig-paren">(</span><em class="sig-param">img</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#RandomAffine.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.RandomAffine.forward" title="Permalink to this definition">¶</a></dt>
<dd><blockquote>
<div><p>img (PIL Image or Tensor): Image to be transformed.</p>
</div></blockquote>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>Affine transformed image.</p>
</dd>
<dt class="field-even">Return type</dt>
<dd class="field-even"><p>PIL Image or <a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor">Tensor</a></p>
</dd>
</dl>
</dd></dl>
<dl class="method">
<dt id="torchvision.transforms.RandomAffine.get_params">
<em class="property">static </em><code class="sig-name descname">get_params</code><span class="sig-paren">(</span><em class="sig-param">degrees: List[float], translate: Optional[List[float]], scale_ranges: Optional[List[float]], shears: Optional[List[float]], img_size: List[int]</em><span class="sig-paren">)</span> → Tuple[float, Tuple[int, int], float, Tuple[float, float]]<a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#RandomAffine.get_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.RandomAffine.get_params" title="Permalink to this definition">¶</a></dt>
<dd><p>Get parameters for affine transformation</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>params to be passed to the affine transformation</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="torchvision.transforms.RandomApply">
<em class="property">class </em><code class="sig-prename descclassname">torchvision.transforms.</code><code class="sig-name descname">RandomApply</code><span class="sig-paren">(</span><em class="sig-param">transforms</em>, <em class="sig-param">p=0.5</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#RandomApply"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.RandomApply" title="Permalink to this definition">¶</a></dt>
<dd><p>Apply randomly a list of transformations with a given probability.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>In order to script the transformation, please use <code class="docutils literal notranslate"><span class="pre">torch.nn.ModuleList</span></code> as input instead of list/tuple of
transforms as shown below:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">transforms</span> <span class="o">=</span> <span class="n">transforms</span><span class="o">.</span><span class="n">RandomApply</span><span class="p">(</span><span class="n">torch</span><span class="o">.</span><span class="n">nn</span><span class="o">.</span><span class="n">ModuleList</span><span class="p">([</span>
<span class="gp">>>> </span> <span class="n">transforms</span><span class="o">.</span><span class="n">ColorJitter</span><span class="p">(),</span>
<span class="gp">>>> </span><span class="p">]),</span> <span class="n">p</span><span class="o">=</span><span class="mf">0.3</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">scripted_transforms</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">jit</span><span class="o">.</span><span class="n">script</span><span class="p">(</span><span class="n">transforms</span><span class="p">)</span>
</pre></div>
</div>
<p>Make sure to use only scriptable transformations, i.e. that work with <code class="docutils literal notranslate"><span class="pre">torch.Tensor</span></code>, does not require
<cite>lambda</cite> functions or <code class="docutils literal notranslate"><span class="pre">PIL.Image</span></code>.</p>
</div>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>transforms</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#list" title="(in Python v3.9)"><em>list</em></a><em> or </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.9)"><em>tuple</em></a><em> or </em><a class="reference internal" href="../generated/torch.nn.Module.html#torch.nn.Module" title="torch.nn.Module"><em>torch.nn.Module</em></a>) – list of transformations</p></li>
<li><p><strong>p</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><em>float</em></a>) – probability</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="class">
<dt id="torchvision.transforms.RandomCrop">
<em class="property">class </em><code class="sig-prename descclassname">torchvision.transforms.</code><code class="sig-name descname">RandomCrop</code><span class="sig-paren">(</span><em class="sig-param">size</em>, <em class="sig-param">padding=None</em>, <em class="sig-param">pad_if_needed=False</em>, <em class="sig-param">fill=0</em>, <em class="sig-param">padding_mode='constant'</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#RandomCrop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.RandomCrop" title="Permalink to this definition">¶</a></dt>
<dd><p>Crop the given image at a random location.
The image can be a PIL Image or a Tensor, in which case it is expected
to have […, H, W] shape, where … means an arbitrary number of leading
dimensions</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>size</strong> (<em>sequence</em><em> or </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><em>int</em></a>) – Desired output size of the crop. If size is an
int instead of sequence like (h, w), a square crop (size, size) is
made. If provided a tuple or list of length 1, it will be interpreted as (size[0], size[0]).</p></li>
<li><p><strong>padding</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><em>int</em></a><em> or </em><em>sequence</em><em>, </em><em>optional</em>) – Optional padding on each border
of the image. Default is None. If a single int is provided this
is used to pad all borders. If tuple of length 2 is provided this is the padding
on left/right and top/bottom respectively. If a tuple of length 4 is provided
this is the padding for the left, top, right and bottom borders respectively.
In torchscript mode padding as single int is not supported, use a tuple or
list of length 1: <code class="docutils literal notranslate"><span class="pre">[padding,</span> <span class="pre">]</span></code>.</p></li>
<li><p><strong>pad_if_needed</strong> (<em>boolean</em>) – It will pad the image if smaller than the
desired size to avoid raising an exception. Since cropping is done
after padding, the padding seems to be done at a random offset.</p></li>
<li><p><strong>fill</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><em>int</em></a><em> or </em><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.9)"><em>tuple</em></a>) – Pixel fill value for constant fill. Default is 0. If a tuple of
length 3, it is used to fill R, G, B channels respectively.
This value is only used when the padding_mode is constant</p></li>
<li><p><strong>padding_mode</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(in Python v3.9)"><em>str</em></a>) – <p>Type of padding. Should be: constant, edge, reflect or symmetric. Default is constant.
Mode symmetric is not yet supported for Tensor inputs.</p>
<blockquote>
<div><ul>
<li><p>constant: pads with a constant value, this value is specified with fill</p></li>
<li><p>edge: pads with the last value on the edge of the image</p></li>
<li><p>reflect: pads with reflection of image (without repeating the last value on the edge)</p>
<blockquote>
<div><p>padding [1, 2, 3, 4] with 2 elements on both sides in reflect mode
will result in [3, 2, 1, 2, 3, 4, 3, 2]</p>
</div></blockquote>
</li>
<li><p>symmetric: pads with reflection of image (repeating the last value on the edge)</p>
<blockquote>
<div><p>padding [1, 2, 3, 4] with 2 elements on both sides in symmetric mode
will result in [2, 1, 1, 2, 3, 4, 4, 3]</p>
</div></blockquote>
</li>
</ul>
</div></blockquote>
</p></li>
</ul>
</dd>
</dl>
<dl class="method">
<dt id="torchvision.transforms.RandomCrop.forward">
<code class="sig-name descname">forward</code><span class="sig-paren">(</span><em class="sig-param">img</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#RandomCrop.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.RandomCrop.forward" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>img</strong> (<em>PIL Image</em><em> or </em><a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor"><em>Tensor</em></a>) – Image to be cropped.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Cropped image.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>PIL Image or <a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor">Tensor</a></p>
</dd>
</dl>
</dd></dl>
<dl class="method">
<dt id="torchvision.transforms.RandomCrop.get_params">
<em class="property">static </em><code class="sig-name descname">get_params</code><span class="sig-paren">(</span><em class="sig-param">img: torch.Tensor, output_size: Tuple[int, int]</em><span class="sig-paren">)</span> → Tuple[int, int, int, int]<a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#RandomCrop.get_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.RandomCrop.get_params" title="Permalink to this definition">¶</a></dt>
<dd><p>Get parameters for <code class="docutils literal notranslate"><span class="pre">crop</span></code> for a random crop.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>img</strong> (<em>PIL Image</em><em> or </em><a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor"><em>Tensor</em></a>) – Image to be cropped.</p></li>
<li><p><strong>output_size</strong> (<a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.9)"><em>tuple</em></a>) – Expected output size of the crop.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>params (i, j, h, w) to be passed to <code class="docutils literal notranslate"><span class="pre">crop</span></code> for random crop.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#tuple" title="(in Python v3.9)">tuple</a></p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="torchvision.transforms.RandomGrayscale">
<em class="property">class </em><code class="sig-prename descclassname">torchvision.transforms.</code><code class="sig-name descname">RandomGrayscale</code><span class="sig-paren">(</span><em class="sig-param">p=0.1</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#RandomGrayscale"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.RandomGrayscale" title="Permalink to this definition">¶</a></dt>
<dd><p>Randomly convert image to grayscale with a probability of p (default 0.1).
The image can be a PIL Image or a Tensor, in which case it is expected
to have […, 3, H, W] shape, where … means an arbitrary number of leading
dimensions</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>p</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><em>float</em></a>) – probability that image should be converted to grayscale.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Grayscale version of the input image with probability p and unchanged
with probability (1-p).
- If input image is 1 channel: grayscale version is 1 channel
- If input image is 3 channel: grayscale version is 3 channel with r == g == b</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>PIL Image or <a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor">Tensor</a></p>
</dd>
</dl>
<dl class="method">
<dt id="torchvision.transforms.RandomGrayscale.forward">
<code class="sig-name descname">forward</code><span class="sig-paren">(</span><em class="sig-param">img</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#RandomGrayscale.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.RandomGrayscale.forward" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>img</strong> (<em>PIL Image</em><em> or </em><a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor"><em>Tensor</em></a>) – Image to be converted to grayscale.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Randomly grayscaled image.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>PIL Image or <a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor">Tensor</a></p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="torchvision.transforms.RandomHorizontalFlip">
<em class="property">class </em><code class="sig-prename descclassname">torchvision.transforms.</code><code class="sig-name descname">RandomHorizontalFlip</code><span class="sig-paren">(</span><em class="sig-param">p=0.5</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#RandomHorizontalFlip"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.RandomHorizontalFlip" title="Permalink to this definition">¶</a></dt>
<dd><p>Horizontally flip the given image randomly with a given probability.
The image can be a PIL Image or a torch Tensor, in which case it is expected
to have […, H, W] shape, where … means an arbitrary number of leading
dimensions</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>p</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><em>float</em></a>) – probability of the image being flipped. Default value is 0.5</p>
</dd>
</dl>
<dl class="method">
<dt id="torchvision.transforms.RandomHorizontalFlip.forward">
<code class="sig-name descname">forward</code><span class="sig-paren">(</span><em class="sig-param">img</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#RandomHorizontalFlip.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.RandomHorizontalFlip.forward" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>img</strong> (<em>PIL Image</em><em> or </em><a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor"><em>Tensor</em></a>) – Image to be flipped.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Randomly flipped image.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>PIL Image or <a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor">Tensor</a></p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="torchvision.transforms.RandomPerspective">
<em class="property">class </em><code class="sig-prename descclassname">torchvision.transforms.</code><code class="sig-name descname">RandomPerspective</code><span class="sig-paren">(</span><em class="sig-param">distortion_scale=0.5</em>, <em class="sig-param">p=0.5</em>, <em class="sig-param">interpolation=2</em>, <em class="sig-param">fill=0</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#RandomPerspective"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.RandomPerspective" title="Permalink to this definition">¶</a></dt>
<dd><p>Performs a random perspective transformation of the given image with a given probability.
The image can be a PIL Image or a Tensor, in which case it is expected
to have […, H, W] shape, where … means an arbitrary number of leading dimensions.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>distortion_scale</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><em>float</em></a>) – argument to control the degree of distortion and ranges from 0 to 1.
Default is 0.5.</p></li>
<li><p><strong>p</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><em>float</em></a>) – probability of the image being transformed. Default is 0.5.</p></li>
<li><p><strong>interpolation</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><em>int</em></a>) – Interpolation type. If input is Tensor, only <code class="docutils literal notranslate"><span class="pre">PIL.Image.NEAREST</span></code> and
<code class="docutils literal notranslate"><span class="pre">PIL.Image.BILINEAR</span></code> are supported. Default, <code class="docutils literal notranslate"><span class="pre">PIL.Image.BILINEAR</span></code> for PIL images and Tensors.</p></li>
<li><p><strong>fill</strong> (<em>n-tuple</em><em> or </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><em>int</em></a><em> or </em><a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><em>float</em></a>) – Pixel fill value for area outside the rotated
image. If int or float, the value is used for all bands respectively. Default is 0.
This option is only available for <code class="docutils literal notranslate"><span class="pre">pillow>=5.0.0</span></code>. This option is not supported for Tensor
input. Fill value for the area outside the transform in the output image is always 0.</p></li>
</ul>
</dd>
</dl>
<dl class="method">
<dt id="torchvision.transforms.RandomPerspective.forward">
<code class="sig-name descname">forward</code><span class="sig-paren">(</span><em class="sig-param">img</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#RandomPerspective.forward"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.RandomPerspective.forward" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>img</strong> (<em>PIL Image</em><em> or </em><a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor"><em>Tensor</em></a>) – Image to be Perspectively transformed.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Randomly transformed image.</p>
</dd>
<dt class="field-odd">Return type</dt>
<dd class="field-odd"><p>PIL Image or <a class="reference internal" href="../tensors.html#torch.Tensor" title="torch.Tensor">Tensor</a></p>
</dd>
</dl>
</dd></dl>
<dl class="method">
<dt id="torchvision.transforms.RandomPerspective.get_params">
<em class="property">static </em><code class="sig-name descname">get_params</code><span class="sig-paren">(</span><em class="sig-param">width: int</em>, <em class="sig-param">height: int</em>, <em class="sig-param">distortion_scale: float</em><span class="sig-paren">)</span> → Tuple[List[List[int]], List[List[int]]]<a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#RandomPerspective.get_params"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.RandomPerspective.get_params" title="Permalink to this definition">¶</a></dt>
<dd><p>Get parameters for <code class="docutils literal notranslate"><span class="pre">perspective</span></code> for a random perspective transform.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>width</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><em>int</em></a>) – width of the image.</p></li>
<li><p><strong>height</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><em>int</em></a>) – height of the image.</p></li>
<li><p><strong>distortion_scale</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(in Python v3.9)"><em>float</em></a>) – argument to control the degree of distortion and ranges from 0 to 1.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>List containing [top-left, top-right, bottom-right, bottom-left] of the original image,
List containing [top-left, top-right, bottom-right, bottom-left] of the transformed image.</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="torchvision.transforms.RandomResizedCrop">
<em class="property">class </em><code class="sig-prename descclassname">torchvision.transforms.</code><code class="sig-name descname">RandomResizedCrop</code><span class="sig-paren">(</span><em class="sig-param">size</em>, <em class="sig-param">scale=(0.08</em>, <em class="sig-param">1.0)</em>, <em class="sig-param">ratio=(0.75</em>, <em class="sig-param">1.3333333333333333)</em>, <em class="sig-param">interpolation=2</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/torchvision/transforms/transforms.html#RandomResizedCrop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#torchvision.transforms.RandomResizedCrop" title="Permalink to this definition">¶</a></dt>
<dd><p>Crop the given image to random size and aspect ratio.
The image can be a PIL Image or a Tensor, in which case it is expected
to have […, H, W] shape, where … means an arbitrary number of leading dimensions</p>
<p>A crop of random size (default: of 0.08 to 1.0) of the original size and a random
aspect ratio (default: of 3/4 to 4/3) of the original aspect ratio is made. This crop
is finally resized to given size.
This is popularly used to train the Inception networks.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>size</strong> (<a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(in Python v3.9)"><em>int</em></a><em> or </em><em>sequence</em>) – expected output size of each edge. If size is an
int instead of sequence like (h, w), a square output size <code class="docutils literal notranslate"><span class="pre">(size,</span> <span class="pre">size)</span></code> is
made. If provided a tuple or list of length 1, it will be interpreted as (size[0], size[0]).</p></li>
<li><p><strong>scale</strong> (<em>tuple of python:float</em>) – range of size of the origin size cropped</p></li>
<li><p><strong>ratio</strong> (<em>tuple of python:float</em>) – range of aspect ratio of the origin aspect ratio cropped.</p></li>