Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6e7a904e
提交
6e7a904e
authored
8月 17, 2015
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3139 from sebastien-j/average_pooling
Average pooling
上级
079181cf
8298b5b1
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
68 行增加
和
14 行删除
+68
-14
dnn.py
theano/sandbox/cuda/dnn.py
+28
-3
opt.py
theano/sandbox/cuda/opt.py
+4
-3
test_dnn.py
theano/sandbox/cuda/tests/test_dnn.py
+7
-3
dnn.py
theano/sandbox/gpuarray/dnn.py
+22
-2
test_dnn.py
theano/sandbox/gpuarray/tests/test_dnn.py
+7
-3
downsample.py
theano/tensor/signal/downsample.py
+0
-0
test_downsample.py
theano/tensor/signal/tests/test_downsample.py
+0
-0
没有找到文件。
theano/sandbox/cuda/dnn.py
浏览文件 @
6e7a904e
...
@@ -13,7 +13,7 @@ from theano.compile.ops import shape_i
...
@@ -13,7 +13,7 @@ from theano.compile.ops import shape_i
from
theano.configparser
import
AddConfigVar
,
EnumStr
from
theano.configparser
import
AddConfigVar
,
EnumStr
from
theano.tensor.nnet
import
SoftmaxGrad
from
theano.tensor.nnet
import
SoftmaxGrad
from
theano.tensor.signal.downsample
import
(
from
theano.tensor.signal.downsample
import
(
DownsampleFactorMax
,
DownsampleFactorMax
Grad
)
DownsampleFactorMax
,
MaxPoolGrad
,
AveragePool
Grad
)
from
theano.sandbox.cuda
import
GpuOp
from
theano.sandbox.cuda
import
GpuOp
from
theano.sandbox.cuda.basic_ops
import
(
as_cuda_ndarray_variable
,
from
theano.sandbox.cuda.basic_ops
import
(
as_cuda_ndarray_variable
,
host_from_gpu
,
host_from_gpu
,
...
@@ -2204,11 +2204,11 @@ if True:
...
@@ -2204,11 +2204,11 @@ if True:
desc
)]
desc
)]
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@local_optimizer
([
DownsampleFactorMax
Grad
])
@local_optimizer
([
MaxPool
Grad
])
def
local_pool_dnn_grad_stride
(
node
):
def
local_pool_dnn_grad_stride
(
node
):
if
not
dnn_available
():
if
not
dnn_available
():
return
return
if
isinstance
(
node
.
op
,
DownsampleFactorMax
Grad
):
if
isinstance
(
node
.
op
,
MaxPool
Grad
):
if
not
node
.
op
.
ignore_border
:
if
not
node
.
op
.
ignore_border
:
return
return
inp
,
out
,
inp_grad
=
node
.
inputs
inp
,
out
,
inp_grad
=
node
.
inputs
...
@@ -2228,6 +2228,31 @@ if True:
...
@@ -2228,6 +2228,31 @@ if True:
desc
)
desc
)
return
[
host_from_gpu
(
ret
)]
return
[
host_from_gpu
(
ret
)]
@register_opt
(
'cudnn'
)
@local_optimizer
([
AveragePoolGrad
])
def
local_avgpool_dnn_grad_stride
(
node
):
if
not
dnn_available
():
return
if
isinstance
(
node
.
op
,
AveragePoolGrad
):
if
not
node
.
op
.
ignore_border
:
return
inp
,
inp_grad
=
node
.
inputs
ds
=
node
.
op
.
ds
st
=
node
.
op
.
st
pad
=
node
.
op
.
padding
mode
=
node
.
op
.
mode
if
((
inp
.
owner
and
isinstance
(
inp
.
owner
.
op
,
HostFromGpu
))
or
(
inp_grad
.
owner
and
isinstance
(
inp_grad
.
owner
.
op
,
HostFromGpu
))):
desc
=
GpuDnnPoolDesc
(
ws
=
ds
,
stride
=
st
,
mode
=
mode
,
pad
=
pad
)()
ret
=
GpuDnnPoolGrad
()(
gpu_contiguous
(
inp
),
gpu_contiguous
(
numpy
.
empty
((
1
,
1
,
1
,
1
),
dtype
=
numpy
.
float32
)),
gpu_contiguous
(
inp_grad
),
desc
)
return
[
host_from_gpu
(
ret
)]
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@local_optimizer
([
GpuSoftmax
])
@local_optimizer
([
GpuSoftmax
])
def
local_softmax_dnn
(
node
):
def
local_softmax_dnn
(
node
):
...
...
theano/sandbox/cuda/opt.py
浏览文件 @
6e7a904e
...
@@ -120,7 +120,8 @@ cpu_ops_moved_to_gpu = [
...
@@ -120,7 +120,8 @@ cpu_ops_moved_to_gpu = [
tensor
.
blas
.
Dot22
,
tensor
.
blas
.
Dot22Scalar
,
tensor
.
blas
.
Gemm
,
tensor
.
blas
.
Dot22
,
tensor
.
blas
.
Dot22Scalar
,
tensor
.
blas
.
Gemm
,
tensor
.
blas
.
Gemv
,
tensor
.
blas
.
Ger
,
tensor
.
nnet
.
conv
.
ConvOp
,
tensor
.
blas
.
Gemv
,
tensor
.
blas
.
Ger
,
tensor
.
nnet
.
conv
.
ConvOp
,
tensor
.
signal
.
downsample
.
DownsampleFactorMax
,
tensor
.
signal
.
downsample
.
DownsampleFactorMax
,
tensor
.
signal
.
downsample
.
DownsampleFactorMaxGrad
,
tensor
.
signal
.
downsample
.
MaxPoolGrad
,
tensor
.
signal
.
downsample
.
AveragePoolGrad
,
theano
.
tensor
.
nnet
.
neighbours
.
Images2Neibs
,
theano
.
tensor
.
nnet
.
neighbours
.
Images2Neibs
,
tensor
.
nnet
.
CrossentropySoftmaxArgmax1HotWithBias
,
tensor
.
nnet
.
CrossentropySoftmaxArgmax1HotWithBias
,
tensor
.
nnet
.
CrossentropySoftmax1HotWithBiasDx
,
tensor
.
nnet
.
CrossentropySoftmax1HotWithBiasDx
,
...
@@ -1765,9 +1766,9 @@ def local_gpu_downsample_factor_max(node):
...
@@ -1765,9 +1766,9 @@ def local_gpu_downsample_factor_max(node):
@register_opt
()
@register_opt
()
@local_optimizer
([
downsample
.
DownsampleFactorMax
Grad
])
@local_optimizer
([
downsample
.
MaxPool
Grad
])
def
local_gpu_downsample_factor_max_grad
(
node
):
def
local_gpu_downsample_factor_max_grad
(
node
):
if
(
isinstance
(
node
.
op
,
downsample
.
DownsampleFactorMax
Grad
)
and
if
(
isinstance
(
node
.
op
,
downsample
.
MaxPool
Grad
)
and
node
.
op
.
ds
==
node
.
op
.
st
):
node
.
op
.
ds
==
node
.
op
.
st
):
assert
node
.
op
.
__props__
==
(
'ds'
,
'ignore_border'
,
'st'
,
'padding'
,
assert
node
.
op
.
__props__
==
(
'ds'
,
'ignore_border'
,
'st'
,
'padding'
,
'mode'
)
'mode'
)
...
...
theano/sandbox/cuda/tests/test_dnn.py
浏览文件 @
6e7a904e
...
@@ -10,7 +10,7 @@ import theano.tensor as T
...
@@ -10,7 +10,7 @@ import theano.tensor as T
import
theano.tests.unittest_tools
as
utt
import
theano.tests.unittest_tools
as
utt
from
theano.sandbox.neighbours
import
images2neibs
from
theano.sandbox.neighbours
import
images2neibs
from
theano.tensor.signal.downsample
import
max_pool_2d
from
theano.tensor.signal.downsample
import
max_pool_2d
from
theano.tensor.signal.downsample
import
DownsampleFactorMax
Grad
from
theano.tensor.signal.downsample
import
MaxPoolGrad
,
AveragePool
Grad
import
theano.sandbox.cuda.dnn
as
dnn
import
theano.sandbox.cuda.dnn
as
dnn
from
theano.sandbox.cuda.basic_ops
import
GpuAllocEmpty
,
gpu_alloc_empty
from
theano.sandbox.cuda.basic_ops
import
GpuAllocEmpty
,
gpu_alloc_empty
from
theano.sandbox.cuda
import
float32_shared_constructor
as
shared
from
theano.sandbox.cuda
import
float32_shared_constructor
as
shared
...
@@ -316,8 +316,12 @@ def test_pooling():
...
@@ -316,8 +316,12 @@ def test_pooling():
ignore_border
=
True
,
mode
=
mode
)
ignore_border
=
True
,
mode
=
mode
)
fc
=
theano
.
function
([
x
],
theano
.
grad
(
out
.
sum
(),
x
),
fc
=
theano
.
function
([
x
],
theano
.
grad
(
out
.
sum
(),
x
),
mode
=
mode_without_gpu
)
mode
=
mode_without_gpu
)
assert
any
([
isinstance
(
node
.
op
,
DownsampleFactorMaxGrad
)
if
mode
==
'max'
:
for
node
in
fc
.
maker
.
fgraph
.
toposort
()])
assert
any
([
isinstance
(
node
.
op
,
MaxPoolGrad
)
for
node
in
fc
.
maker
.
fgraph
.
toposort
()])
else
:
assert
any
([
isinstance
(
node
.
op
,
AveragePoolGrad
)
for
node
in
fc
.
maker
.
fgraph
.
toposort
()])
c_out
=
fc
(
data
)
c_out
=
fc
(
data
)
assert
numpy
.
allclose
(
c_out
,
g_out
)
assert
numpy
.
allclose
(
c_out
,
g_out
)
...
...
theano/sandbox/gpuarray/dnn.py
浏览文件 @
6e7a904e
...
@@ -13,7 +13,7 @@ from theano.compile.ops import shape_i
...
@@ -13,7 +13,7 @@ from theano.compile.ops import shape_i
from
theano.configparser
import
AddConfigVar
,
EnumStr
,
StrParam
from
theano.configparser
import
AddConfigVar
,
EnumStr
,
StrParam
from
theano.tensor.nnet
import
SoftmaxGrad
from
theano.tensor.nnet
import
SoftmaxGrad
from
theano.tensor.signal.downsample
import
(
from
theano.tensor.signal.downsample
import
(
DownsampleFactorMax
,
DownsampleFactorMax
Grad
)
DownsampleFactorMax
,
MaxPoolGrad
,
AveragePool
Grad
)
from
.
import
pygpu
,
init_dev
from
.
import
pygpu
,
init_dev
from
.basic_ops
import
(
as_gpuarray_variable
,
from
.basic_ops
import
(
as_gpuarray_variable
,
...
@@ -1659,7 +1659,7 @@ def local_pool_dnn_alternative(node):
...
@@ -1659,7 +1659,7 @@ def local_pool_dnn_alternative(node):
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@op_lifter
([
DownsampleFactorMax
Grad
])
@op_lifter
([
MaxPool
Grad
])
def
local_pool_dnn_grad_stride
(
node
):
def
local_pool_dnn_grad_stride
(
node
):
if
not
dnn_available
():
if
not
dnn_available
():
return
return
...
@@ -1678,6 +1678,26 @@ def local_pool_dnn_grad_stride(node):
...
@@ -1678,6 +1678,26 @@ def local_pool_dnn_grad_stride(node):
desc
)
desc
)
@register_opt
(
'cudnn'
)
@op_lifter
([
AveragePoolGrad
])
def
local_avg_pool_dnn_grad_stride
(
node
):
if
not
dnn_available
():
return
if
not
node
.
op
.
ignore_border
:
return
inp
,
inp_grad
=
node
.
inputs
ds
=
node
.
op
.
ds
st
=
node
.
op
.
st
pad
=
node
.
op
.
padding
mode
=
node
.
op
.
mode
desc
=
GpuDnnPoolDesc
(
ws
=
ds
,
stride
=
st
,
mode
=
mode
,
pad
=
pad
)()
return
GpuDnnPoolGrad
()(
gpu_contiguous
(
inp
),
gpu_contiguous
(
numpy
.
empty
((
1
,
1
,
1
,
1
),
dtype
=
numpy
.
float32
)),
gpu_contiguous
(
inp_grad
),
desc
)
@register_opt
(
'cudnn'
)
@register_opt
(
'cudnn'
)
@local_optimizer
([
GpuSoftmax
])
@local_optimizer
([
GpuSoftmax
])
def
local_softmax_dnn
(
node
):
def
local_softmax_dnn
(
node
):
...
...
theano/sandbox/gpuarray/tests/test_dnn.py
浏览文件 @
6e7a904e
...
@@ -10,7 +10,7 @@ import theano.tensor as T
...
@@ -10,7 +10,7 @@ import theano.tensor as T
import
theano.tests.unittest_tools
as
utt
import
theano.tests.unittest_tools
as
utt
from
theano.sandbox.neighbours
import
images2neibs
from
theano.sandbox.neighbours
import
images2neibs
from
theano.tensor.signal.downsample
import
max_pool_2d
from
theano.tensor.signal.downsample
import
max_pool_2d
from
theano.tensor.signal.downsample
import
DownsampleFactorMax
Grad
from
theano.tensor.signal.downsample
import
MaxPoolGrad
,
AveragePool
Grad
from
..
import
dnn
from
..
import
dnn
from
..basic_ops
import
GpuAllocEmpty
from
..basic_ops
import
GpuAllocEmpty
...
@@ -264,8 +264,12 @@ def test_pooling():
...
@@ -264,8 +264,12 @@ def test_pooling():
ignore_border
=
True
,
mode
=
mode
)
ignore_border
=
True
,
mode
=
mode
)
fc
=
theano
.
function
([
x
],
theano
.
grad
(
out
.
sum
(),
x
),
fc
=
theano
.
function
([
x
],
theano
.
grad
(
out
.
sum
(),
x
),
mode
=
mode_without_gpu
)
mode
=
mode_without_gpu
)
assert
any
([
isinstance
(
node
.
op
,
DownsampleFactorMaxGrad
)
if
mode
==
'max'
:
for
node
in
fc
.
maker
.
fgraph
.
toposort
()])
assert
any
([
isinstance
(
node
.
op
,
MaxPoolGrad
)
for
node
in
fc
.
maker
.
fgraph
.
toposort
()])
else
:
assert
any
([
isinstance
(
node
.
op
,
AveragePoolGrad
)
for
node
in
fc
.
maker
.
fgraph
.
toposort
()])
c_out
=
fc
(
data
)
c_out
=
fc
(
data
)
assert
numpy
.
allclose
(
c_out
,
g_out
)
assert
numpy
.
allclose
(
c_out
,
g_out
)
...
...
theano/tensor/signal/downsample.py
浏览文件 @
6e7a904e
差异被折叠。
点击展开。
theano/tensor/signal/tests/test_downsample.py
浏览文件 @
6e7a904e
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论