前言
這次就不廢話了,我想趕在10點(diǎn)前回去洗頭(現(xiàn)在9.17,還差一篇文章)
一、nn.Upsample 上采樣
該函數(shù)有四個(gè)參數(shù):
參數(shù)的介紹如下:
稍微翻譯一下:
參數(shù):
1)size(int或Tuple[int]或Tuple[int,int]或Tupple[int,int,int],可選):輸出空間大小
2)scale_factor(float或Tuple[floot]或Tuple[floot,float]或Tuple[floot、float、float],可選):空間大小的乘數(shù)。如果是元組,則必須匹配輸入大小。
3)mode(str,可選):上采樣算法:“最近”,“線性”、“雙線性”、“雙三次”和“三線性”。默認(rèn)值 ‘nearst’
4)align_ccorners(bool,可選):如果“True”,則輸入的角像素和輸出張量對(duì)齊,從而保持這些像素。僅當(dāng):attr:mode為“線性”、“線性”或“三線性”。默認(rèn)值:False
深度學(xué)習(xí)里用的比較多的是二倍向上采樣,比如經(jīng)常出現(xiàn)在U-net網(wǎng)絡(luò)結(jié)構(gòu)里,例子如下:
import torch
import torch.nn as nn
A =torch.rand(1,3,24,24)
up=nn.Upsample(scale_factor=2, mode='bilinear', align_corners=True)
B =up(A)
print(B.shape)
如果少寫(xiě)了一個(gè)維度,就會(huì)報(bào)錯(cuò):
import torch
import torch.nn as nn
A =torch.rand(3,24,24)
up=nn.Upsample(scale_factor=2, mode='bilinear', align_corners=True)
B =up(A)
print(B.shape)
二、nn.ConvTranspose2d 轉(zhuǎn)置卷積
我們首先看看它的參數(shù),依然如此得多
其實(shí),轉(zhuǎn)置卷積和普通的卷積操作,參數(shù)配置都是很相似的??磶讉€(gè)例子把
1)311型轉(zhuǎn)置卷積:
import torch
import torch.nn as nn
A =torch.rand(1,64,24,24)
up=nn.ConvTranspose2d(64,32,3,1,1)
B =up(A)
print(B.shape)
和普通卷積的311一樣,寬高不變
2)310型轉(zhuǎn)置卷積:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-401616.html
import torch
import torch.nn as nn
A =torch.rand(1,64,24,24)
up=nn.ConvTranspose2d(64,32,3,1,0)
B =up(A)
print(B.shape)
和普通卷積類似,這里是+2(普通卷積是寬高-2)文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-401616.html
到了這里,關(guān)于【深度學(xué)習(xí)】特征圖的上采樣(nn.Upsample)和轉(zhuǎn)置卷積(nn.ConvTranspose2d) | pytorch的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!