pytorch中的上采样以及各种反操作,求逆操作详解
importtorch.nn.functionalasF
importtorch.nnasnn
F.upsample(input,size=None,scale_factor=None,mode='nearest',align_corners=None)
r"""Upsamplestheinputtoeitherthegiven:attr:`size`orthegiven :attr:`scale_factor` Thealgorithmusedforupsamplingisdeterminedby:attr:`mode`. Currentlytemporal,spatialandvolumetricupsamplingaresupported,i.e. expectedinputsare3-D,4-Dor5-Dinshape. Theinputdimensionsareinterpretedintheform: `mini-batchxchannelsx[optionaldepth]x[optionalheight]xwidth`. Themodesavailableforupsamplingare:`nearest`,`linear`(3D-only), `bilinear`(4D-only),`trilinear`(5D-only) Args: input(Tensor):theinputtensor size(intorTuple[int]orTuple[int,int]orTuple[int,int,int]): outputspatialsize. scale_factor(int):multiplierforspatialsize.Hastobeaninteger. mode(string):algorithmusedforupsampling: 'nearest'|'linear'|'bilinear'|'trilinear'.Default:'nearest' align_corners(bool,optional):ifTrue,thecornerpixelsoftheinput andoutputtensorsarealigned,andthuspreservingthevaluesat thosepixels.Thisonlyhaseffectwhen:attr:`mode`is`linear`, `bilinear`,or`trilinear`.Default:False ..warning:: With``align_corners=True``,thelinearlyinterpolatingmodes (`linear`,`bilinear`,and`trilinear`)don'tproportionallyalignthe outputandinputpixels,andthustheoutputvaluescandependonthe inputsize.Thiswasthedefaultbehaviorforthesemodesuptoversion 0.3.1.Sincethen,thedefaultbehavioris``align_corners=False``. See:class:`~torch.nn.Upsample`forconcreteexamplesonhowthis affectstheoutputs. """
nn.ConvTranspose2d(in_channels,out_channels,kernel_size,stride=1,padding=0,output_padding=0,groups=1,bias=True,dilation=1)
""" Parameters: in_channels(int)–Numberofchannelsintheinputimage out_channels(int)–Numberofchannelsproducedbytheconvolution kernel_size(intortuple)–Sizeoftheconvolvingkernel stride(intortuple,optional)–Strideoftheconvolution.Default:1 padding(intortuple,optional)–kernel_size-1-paddingzero-paddingwillbeaddedtobothsidesofeachdimensionintheinput.Default:0 output_padding(intortuple,optional)–Additionalsizeaddedtoonesideofeachdimensionintheoutputshape.Default:0 groups(int,optional)–Numberofblockedconnectionsfrominputchannelstooutputchannels.Default:1 bias(bool,optional)–IfTrue,addsalearnablebiastotheoutput.Default:True dilation(intortuple,optional)–Spacingbetweenkernelelements.Default:1 """
计算方式:
定义:nn.MaxUnpool2d(kernel_size,stride=None,padding=0)
调用:
defforward(self,input,indices,output_size=None): returnF.max_unpool2d(input,indices,self.kernel_size,self.stride, self.padding,output_size)
r"""Computesapartialinverseof:class:`MaxPool2d`. :class:`MaxPool2d`isnotfullyinvertible,sincethenon-maximalvaluesarelost. :class:`MaxUnpool2d`takesinasinputtheoutputof:class:`MaxPool2d` includingtheindicesofthemaximalvaluesandcomputesapartialinverse inwhichallnon-maximalvaluesaresettozero. ..note::`MaxPool2d`canmapseveralinputsizestothesameoutputsizes. Hence,theinversionprocesscangetambiguous. Toaccommodatethis,youcanprovidetheneededoutputsize asanadditionalargument`output_size`intheforwardcall. SeetheInputsandExamplebelow. Args: kernel_size(intortuple):Sizeofthemaxpoolingwindow. stride(intortuple):Strideofthemaxpoolingwindow. Itissetto``kernel_size``bydefault. padding(intortuple):Paddingthatwasaddedtotheinput Inputs: -`input`:theinputTensortoinvert -`indices`:theindicesgivenoutby`MaxPool2d` -`output_size`(optional):a`torch.Size`thatspecifiesthetargetedoutputsize Shape: -Input::math:`(N,C,H_{in},W_{in})` -Output::math:`(N,C,H_{out},W_{out})`where 计算公式:见下面 Example:见下面 """
F.max_unpool2d(input,indices,kernel_size,stride=None,padding=0,output_size=None)
见上面的用法一致!
defmax_unpool2d(input,indices,kernel_size,stride=None,padding=0, output_size=None): r"""Computesapartialinverseof:class:`MaxPool2d`. See:class:`~torch.nn.MaxUnpool2d`fordetails. """ pass
以上这篇pytorch中的上采样以及各种反操作,求逆操作详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。