作者robert780612 (.....)
看板DataScience
标题Re: [问题] convolution with stride VS. pooling
时间Tue Jun 26 10:58:51 2018
※ 引述《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://webptt.com/cn.aspx?n=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
1F:推 goldflower: 推实验 06/26 14:21
※ 编辑: robert780612 (211.72.69.157), 06/26/2018 16:37:16
2F:推 aszx4510: 感谢教学 06/26 20:40
3F:推 Mchord: 这篇是只有在classification benchmark,但对detection和s 06/26 22:41
4F:→ Mchord: egmentation就不会是没有loss 06/26 22:41
5F:→ robert780612: 感谢楼上补充 06/26 23:10
6F:推 leoloveivy: 没用过pytorch你是用gpu跑的吗 06/27 02:56
7F:→ leoloveivy: 这样可能要先run一个gpu的 06/27 02:56
8F:→ 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
9F:→ wrt: 这样比较不准唷 06/28 10:31
10F:→ wrt: 你应该把MAC一起算进去 06/28 10:31
11F:→ wrt: 毕竟你conv+stride和conv+pool运算量不一样 06/28 10:31
12F:→ wrt: 再来是用conv+stride就没办法享受到 06/28 10:31
13F:→ wrt: FFT或winograd等等的加速了 06/28 10:31
14F:→ wrt: 另外acc loss的问题都可以靠调整超参数或模型补回 06/28 10:31
15F:→ wrt: 不过如果没有使用进阶的FFT加速或是winograd 06/28 10:54
16F:→ wrt: 就大方使用conv+stride吧 06/28 10:54
17F:→ robert780612: 不是很懂你的意思 06/28 14:58
18F:→ robert780612: 因爲conv+stride运算量少,所以拿来取代conv+pool 06/28 15:00
19F:→ robert780612: 为什麽要在mac相同的情况下比较? 06/28 15:05
20F:→ yoyololicon: conv+stride为甚麽就不能有FFT加速?从DSP角度来看 06/28 22:49
21F:→ yoyololicon: stride只是在做downsampling而已 06/28 22:49
22F:→ wrt: 因为FFT就是在data分享下加速 07/01 18:07
23F:→ wrt: 如果有stride,那共享的data会变少,就影响加速 07/01 18:07
24F:推 sma1033: ""..................................ㄏ"" 07/02 09:08