看板 DataScience 關於我們 聯絡資訊
※ 引述《Haikyuu (!!)》之銘言: : convolution with stride跟pooling都是將feature map變小張的方法 : 例如convolution with stride=2的輸出大小相當於2x2的pooling的輸出大小 : 那想請問這兩者的使用上是怎麼取捨的呢? : 我認為convolution丟掉的資訊量比較少,所以DCGAN才使用convolution而非pooling : 來使Discriminator可以分辨細微差異 首先,Striving for simplicity: The all convolutional net提到 'We find that max-pooling can simply be replaced by a convolutional layer with increased stride without loss in accuracy on several image recognition benchmarks' 在多個 image classification benchmark上 使用convolution with stride=2替換2x2 pooling並沒有損失acc Ref: https://goo.gl/Q3c9i7 第二,用convolution with stride會比較快, 以下是我使用pytorch0.4 & python3.6測試的結果 使用CPU intel i5-6500 1. conv + 2*2maxpool = 0.13秒 2. conv with stride2 = 0.009秒 使用GPU gtx1080 1. conv + 2*2maxpool = 0.046秒 2. conv with stride2 = 0.00069 batch size = 64 image size = 100*100 input channel = 3 output channel = 64 kernel size = 3 ### CPU import time import torch a = torch.rand(64,3,100,100) conv = torch.nn.Conv2d(3, 64, 3) pool = torch.nn.MaxPool2d(2) start = time.time() out1 = pool(conv(a)) print(time.time()-start) conv2 = torch.nn.Conv2d(3, 64, 3, stride=2) start = time.time() out2 = conv2(a) print(time.time()-start) ### GPU import time import torch import torch.nn as nn import torch.nn.functional as F class ConvPool(nn.Module): def __init__(self): super().__init__() self.conv = torch.nn.Conv2d(3, 64, 3) self.pool = torch.nn.MaxPool2d(2) def forward(self, x): out = self.pool(F.relu(self.conv(x))) return out class ConvStride(nn.Module): def __init__(self): super().__init__() self.conv = torch.nn.Conv2d(3, 64, 3, stride=2) def forward(self, x): out = F.relu(self.conv(x)) return out a = torch.rand(64,3,100,100).to('cuda') conv_pool = ConvPool().to('cuda') start = time.time() out1 = conv_pool(a) print(time.time()-start) conv_stride = ConvStride().to('cuda') start = time.time() out2 = conv_stride(a) print(time.time()-start) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 211.72.69.157 ※ 文章網址: https://www.ptt.cc/bbs/DataScience/M.1529981935.A.218.html ※ 編輯: robert780612 (211.72.69.157), 06/26/2018 11:00:56 ※ 編輯: robert780612 (211.72.69.157), 06/26/2018 11:01:16
goldflower: 推實驗 06/26 14:21
※ 編輯: robert780612 (211.72.69.157), 06/26/2018 16:37:16
aszx4510: 感謝教學 06/26 20:40
Mchord: 這篇是只有在classification benchmark,但對detection和s 06/26 22:41
Mchord: egmentation就不會是沒有loss 06/26 22:41
robert780612: 感謝樓上補充 06/26 23:10
leoloveivy: 沒用過pytorch你是用gpu跑的嗎 06/27 02:56
leoloveivy: 這樣可能要先run一個gpu的 06/27 02:56
leoloveivy: 再計時不然可能會有context的問題 06/27 02:56
已補上gpu數據 ※ 編輯: robert780612 (211.72.69.157), 06/27/2018 07:53:41 ※ 編輯: robert780612 (211.72.69.157), 06/27/2018 07:54:38 ※ 編輯: robert780612 (211.72.69.157), 06/27/2018 07:55:22
wrt: 這樣比較不準唷 06/28 10:31
wrt: 你應該把MAC一起算進去 06/28 10:31
wrt: 畢竟你conv+stride和conv+pool運算量不一樣 06/28 10:31
wrt: 再來是用conv+stride就沒辦法享受到 06/28 10:31
wrt: FFT或winograd等等的加速了 06/28 10:31
wrt: 另外acc loss的問題都可以靠調整超參數或模型補回 06/28 10:31
wrt: 不過如果沒有使用進階的FFT加速或是winograd 06/28 10:54
wrt: 就大方使用conv+stride吧 06/28 10:54
robert780612: 不是很懂你的意思 06/28 14:58
robert780612: 因爲conv+stride運算量少,所以拿來取代conv+pool 06/28 15:00
robert780612: 為什麼要在mac相同的情況下比較? 06/28 15:05
yoyololicon: conv+stride為甚麼就不能有FFT加速?從DSP角度來看 06/28 22:49
yoyololicon: stride只是在做downsampling而已 06/28 22:49
wrt: 因為FFT就是在data分享下加速 07/01 18:07
wrt: 如果有stride,那共享的data會變少,就影響加速 07/01 18:07
sma1033: ""..................................ㄏ"" 07/02 09:08