Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
333de734
提交
333de734
authored
11月 18, 2016
作者:
Alexander Matyasko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for direct use of gpu pooling
Add methods for grad and infer shape, so gpu pooling can be used directly.
上级
1ce720d3
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
80 行增加
和
1 行删除
+80
-1
pool.py
theano/gpuarray/pool.py
+80
-1
没有找到文件。
theano/gpuarray/pool.py
浏览文件 @
333de734
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
os.path
import
os.path
import
theano
from
theano
import
Apply
from
theano
import
Apply
from
theano.tensor.basic
import
as_tensor_variable
from
theano.tensor.basic
import
as_tensor_variable
from
theano.tensor.signal.pool
import
Pool
from
.basic_ops
import
CGpuKernelBase
,
infer_context_name
,
as_gpuarray_variable
from
.basic_ops
import
(
CGpuKernelBase
,
infer_context_name
,
as_gpuarray_variable
,
gpu_contiguous
)
try
:
try
:
import
pygpu
import
pygpu
...
@@ -80,6 +83,35 @@ class GpuPool(CGpuKernelBase):
...
@@ -80,6 +83,35 @@ class GpuPool(CGpuKernelBase):
(
'MAX_POOL'
,
max_pool
),
(
'MAX_POOL'
,
max_pool
),
(
'SUM_MODE'
,
sum_mode
)]
(
'SUM_MODE'
,
sum_mode
)]
def
infer_shape
(
self
,
node
,
in_shapes
):
ws
,
stride
,
pad
=
[
node
.
inputs
[
1
],
node
.
inputs
[
2
],
node
.
inputs
[
3
]]
shp
=
Pool
.
out_shape
(
in_shapes
[
0
],
ws
,
self
.
ignore_border
,
stride
,
pad
,
self
.
ndim
)
return
[
shp
]
def
grad
(
self
,
inp
,
grads
):
img
,
ws
,
stride
,
pad
=
inp
grad
,
=
grads
grad
=
gpu_contiguous
(
grad
)
disc
=
[
theano
.
gradient
.
DisconnectedType
()()
for
i
in
inp
[
1
:]]
if
self
.
mode
==
'max'
:
out
=
self
(
inp
,
ws
,
stride
,
pad
)
g_out
=
GpuMaxPoolGrad
(
ndim
=
self
.
ndim
,
ignore_border
=
self
.
ignore_border
)(
img
,
out
,
grad
,
ws
,
stride
,
pad
)
return
[
g_out
]
+
disc
else
:
g_out
=
GpuAveragePoolGrad
(
ndim
=
self
.
ndim
,
ignore_border
=
self
.
ignore_border
,
mode
=
self
.
mode
)(
img
,
grad
,
ws
,
stride
,
pad
)
return
[
g_out
]
+
disc
def
connection_pattern
(
self
,
node
):
return
[[
1
],
[
0
],
[
0
],
[
0
]]
class
GpuMaxPoolGrad
(
CGpuKernelBase
):
class
GpuMaxPoolGrad
(
CGpuKernelBase
):
"""
"""
...
@@ -136,6 +168,22 @@ class GpuMaxPoolGrad(CGpuKernelBase):
...
@@ -136,6 +168,22 @@ class GpuMaxPoolGrad(CGpuKernelBase):
def
get_params
(
self
,
node
):
def
get_params
(
self
,
node
):
return
node
.
inputs
[
0
]
.
type
.
context
return
node
.
inputs
[
0
]
.
type
.
context
def
infer_shape
(
self
,
node
,
in_shapes
):
return
[
in_shapes
[
0
]]
def
grad
(
self
,
inp
,
grads
):
x
,
maxout
,
gz
,
ws
,
stride
,
pad
=
inp
ggx
,
=
grads
return
([
theano
.
tensor
.
zeros_like
(
x
),
theano
.
tensor
.
zeros_like
(
maxout
),
GpuDownsampleFactorMaxGradGrad
(
ndim
=
self
.
ndim
,
ignore_border
=
self
.
ignore_border
)(
x
,
maxout
,
ggx
,
ws
,
stride
,
pad
)]
+
[
theano
.
tensor
.
DisconnectedType
()()
for
i
in
inp
[
3
:]])
def
connection_pattern
(
self
,
node
):
return
[[
1
],
[
1
],
[
1
],
[
0
],
[
0
],
[
0
]]
class
GpuAveragePoolGrad
(
CGpuKernelBase
):
class
GpuAveragePoolGrad
(
CGpuKernelBase
):
"""
"""
...
@@ -200,6 +248,21 @@ class GpuAveragePoolGrad(CGpuKernelBase):
...
@@ -200,6 +248,21 @@ class GpuAveragePoolGrad(CGpuKernelBase):
return
[(
'INC_PAD'
,
inc_pad
),
return
[(
'INC_PAD'
,
inc_pad
),
(
'SUM_MODE'
,
sum_mode
)]
(
'SUM_MODE'
,
sum_mode
)]
def
infer_shape
(
self
,
node
,
in_shapes
):
return
[
in_shapes
[
0
]]
def
grad
(
self
,
inp
,
grads
):
x
,
gz
,
ws
,
stride
,
pad
=
inp
ggx
,
=
grads
return
([
theano
.
tensor
.
zeros_like
(
x
),
GpuPool
(
ignore_border
=
self
.
ignore_border
,
ndim
=
self
.
ndim
,
mode
=
self
.
mode
)(
ggx
,
ws
,
stride
,
pad
)]
+
[
theano
.
gradient
.
DisconnectedType
()()
for
i
in
inp
[
2
:]])
def
connection_pattern
(
self
,
node
):
return
[[
1
],
[
1
],
[
0
],
[
0
],
[
0
]]
class
GpuDownsampleFactorMaxGradGrad
(
CGpuKernelBase
):
class
GpuDownsampleFactorMaxGradGrad
(
CGpuKernelBase
):
"""
"""
...
@@ -255,3 +318,19 @@ class GpuDownsampleFactorMaxGradGrad(CGpuKernelBase):
...
@@ -255,3 +318,19 @@ class GpuDownsampleFactorMaxGradGrad(CGpuKernelBase):
def
get_params
(
self
,
node
):
def
get_params
(
self
,
node
):
return
node
.
inputs
[
0
]
.
type
.
context
return
node
.
inputs
[
0
]
.
type
.
context
def
infer_shape
(
self
,
node
,
in_shapes
):
return
[
in_shapes
[
1
]]
def
grad
(
self
,
inp
,
grads
):
x
,
maxout
,
ggx
,
ws
,
stride
,
pad
=
inp
gz
,
=
grads
return
([
theano
.
tensor
.
zeros_like
(
x
),
theano
.
tensor
.
zeros_like
(
maxout
),
GpuMaxPoolGrad
(
ignore_border
=
self
.
ignore_border
,
ndim
=
self
.
ndim
)(
x
,
maxout
,
gz
,
ws
,
stride
,
pad
)]
+
[
theano
.
gradient
.
DisconnectedType
()()
for
i
in
inp
[
3
:]])
def
connection_pattern
(
self
,
node
):
return
[[
1
],
[
1
],
[
1
],
[
0
],
[
0
],
[
0
]]
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论