Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6bf15e52
提交
6bf15e52
authored
1月 21, 2016
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make sure grads of abstract conv ops have the right type
上级
dd41f3e9
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
122 行增加
和
0 行删除
+122
-0
test_abstractconv.py
theano/sandbox/cuda/tests/test_abstractconv.py
+53
-0
test_abstractconv.py
theano/sandbox/gpuarray/tests/test_abstractconv.py
+57
-0
abstract_conv.py
theano/tensor/nnet/abstract_conv.py
+12
-0
没有找到文件。
theano/sandbox/cuda/tests/test_abstractconv.py
浏览文件 @
6bf15e52
...
@@ -3,6 +3,7 @@ import numpy
...
@@ -3,6 +3,7 @@ import numpy
import
itertools
import
itertools
import
theano
import
theano
from
theano
import
tensor
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
import
theano.tensor.nnet.abstract_conv
as
conv
import
theano.tensor.nnet.abstract_conv
as
conv
from
theano.sandbox.cuda
import
float32_shared_constructor
as
gpu_shared
from
theano.sandbox.cuda
import
float32_shared_constructor
as
gpu_shared
...
@@ -265,3 +266,55 @@ class TestConv2d(unittest.TestCase):
...
@@ -265,3 +266,55 @@ class TestConv2d(unittest.TestCase):
provide_shape
=
provide_shape
,
border_mode
=
b
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
filter_flip
=
flip
,
filter_flip
=
flip
,
target_op
=
GpuCorrMM_gradInputs
)
target_op
=
GpuCorrMM_gradInputs
)
def
test_grad_types
(
self
):
# This function simply tests the behaviour of the AbstractConv
# Ops, not their optimizations
cpu_input
=
tensor
.
ftensor4
()
cpu_filters
=
tensor
.
ftensor4
()
cpu_topgrad
=
tensor
.
ftensor4
()
gpu_input
=
cuda
.
ftensor4
()
gpu_filters
=
cuda
.
ftensor4
()
gpu_topgrad
=
cuda
.
ftensor4
()
out_shape
=
tensor
.
lvector
()
# Check the gradient of the forward conv2d
for
input
,
filters
in
itertools
.
product
(
(
cpu_input
,
gpu_input
),
(
cpu_filters
,
gpu_filters
)):
output
=
conv
.
conv2d
(
input
,
filters
)
grad_input
,
grad_filters
=
theano
.
grad
(
output
.
sum
(),
wrt
=
(
input
,
filters
))
assert
grad_input
.
type
==
input
.
type
,
(
grad_input
,
grad_input
.
type
,
input
,
input
.
type
)
assert
grad_filters
.
type
==
filters
.
type
,
(
grad_filters
,
grad_filters
.
type
,
filters
,
filters
.
type
)
# Check the gradient of gradweight
for
input
,
topgrad
in
itertools
.
product
(
(
cpu_input
,
gpu_input
),
(
cpu_topgrad
,
gpu_topgrad
)):
grad_filters
=
conv
.
AbstractConv2d_gradWeights
()(
input
,
topgrad
,
out_shape
)
grad_input
,
grad_topgrad
=
theano
.
grad
(
grad_filters
.
sum
(),
wrt
=
(
input
,
topgrad
))
assert
grad_input
.
type
==
input
.
type
,
(
grad_input
,
grad_input
.
type
,
input
,
input
.
type
)
assert
grad_topgrad
.
type
==
topgrad
.
type
,
(
grad_topgrad
,
grad_topgrad
.
type
,
topgrad
,
topgrad
.
type
)
# Check the gradient of gradinputs
for
filters
,
topgrad
in
itertools
.
product
(
(
cpu_filters
,
gpu_filters
),
(
cpu_topgrad
,
gpu_topgrad
)):
grad_input
=
conv
.
AbstractConv2d_gradInputs
()(
filters
,
topgrad
,
out_shape
)
grad_filters
,
grad_topgrad
=
theano
.
grad
(
grad_input
.
sum
(),
wrt
=
(
filters
,
topgrad
))
assert
grad_filters
.
type
==
filters
.
type
,
(
grad_filters
,
grad_filters
.
type
,
filters
,
filters
.
type
)
assert
grad_topgrad
.
type
==
topgrad
.
type
,
(
grad_topgrad
,
grad_topgrad
.
type
,
topgrad
,
topgrad
.
type
)
theano/sandbox/gpuarray/tests/test_abstractconv.py
浏览文件 @
6bf15e52
...
@@ -5,10 +5,12 @@ import itertools
...
@@ -5,10 +5,12 @@ import itertools
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
import
theano
import
theano
from
theano
import
tensor
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
import
theano.tensor.nnet.abstract_conv
as
conv
import
theano.tensor.nnet.abstract_conv
as
conv
from
theano.compile
import
shared
as
cpu_shared
from
theano.compile
import
shared
as
cpu_shared
from
..type
import
gpuarray_shared_constructor
as
gpu_shared
from
..type
import
gpuarray_shared_constructor
as
gpu_shared
from
..type
import
GpuArrayType
from
..dnn
import
(
from
..dnn
import
(
dnn_available
,
dnn_conv
,
dnn_gradweight
,
dnn_gradinput
,
dnn_available
,
dnn_conv
,
dnn_gradweight
,
dnn_gradinput
,
GpuDnnConv
,
GpuDnnConvGradW
,
GpuDnnConvGradI
)
GpuDnnConv
,
GpuDnnConvGradW
,
GpuDnnConvGradI
)
...
@@ -20,6 +22,9 @@ from theano.tensor.nnet import ConvGrad3D, ConvTransp3D
...
@@ -20,6 +22,9 @@ from theano.tensor.nnet import ConvGrad3D, ConvTransp3D
from
.config
import
mode_with_gpu
,
mode_without_gpu
,
test_ctx_name
from
.config
import
mode_with_gpu
,
mode_without_gpu
,
test_ctx_name
gpu_ftensor4
=
GpuArrayType
(
dtype
=
'float32'
,
broadcastable
=
(
False
,)
*
4
)
class
TestConv2d
(
unittest
.
TestCase
):
class
TestConv2d
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -348,3 +353,55 @@ class TestConv2d(unittest.TestCase):
...
@@ -348,3 +353,55 @@ class TestConv2d(unittest.TestCase):
provide_shape
=
provide_shape
,
provide_shape
=
provide_shape
,
border_mode
=
b
,
border_mode
=
b
,
filter_flip
=
flip
)
filter_flip
=
flip
)
def
test_grad_types
(
self
):
# This function simply tests the behaviour of the AbstractConv
# Ops, not their optimizations
cpu_input
=
tensor
.
ftensor4
()
cpu_filters
=
tensor
.
ftensor4
()
cpu_topgrad
=
tensor
.
ftensor4
()
gpu_input
=
gpu_ftensor4
()
gpu_filters
=
gpu_ftensor4
()
gpu_topgrad
=
gpu_ftensor4
()
out_shape
=
tensor
.
lvector
()
# Check the gradient of the forward conv2d
for
input
,
filters
in
itertools
.
product
(
(
cpu_input
,
gpu_input
),
(
cpu_filters
,
gpu_filters
)):
output
=
conv
.
conv2d
(
input
,
filters
)
grad_input
,
grad_filters
=
theano
.
grad
(
output
.
sum
(),
wrt
=
(
input
,
filters
))
assert
grad_input
.
type
==
input
.
type
,
(
grad_input
,
grad_input
.
type
,
input
,
input
.
type
)
assert
grad_filters
.
type
==
filters
.
type
,
(
grad_filters
,
grad_filters
.
type
,
filters
,
filters
.
type
)
# Check the gradient of gradweight
for
input
,
topgrad
in
itertools
.
product
(
(
cpu_input
,
gpu_input
),
(
cpu_topgrad
,
gpu_topgrad
)):
grad_filters
=
conv
.
AbstractConv2d_gradWeights
()(
input
,
topgrad
,
out_shape
)
grad_input
,
grad_topgrad
=
theano
.
grad
(
grad_filters
.
sum
(),
wrt
=
(
input
,
topgrad
))
assert
grad_input
.
type
==
input
.
type
,
(
grad_input
,
grad_input
.
type
,
input
,
input
.
type
)
assert
grad_topgrad
.
type
==
topgrad
.
type
,
(
grad_topgrad
,
grad_topgrad
.
type
,
topgrad
,
topgrad
.
type
)
# Check the gradient of gradinputs
for
filters
,
topgrad
in
itertools
.
product
(
(
cpu_filters
,
gpu_filters
),
(
cpu_topgrad
,
gpu_topgrad
)):
grad_input
=
conv
.
AbstractConv2d_gradInputs
()(
filters
,
topgrad
,
out_shape
)
grad_filters
,
grad_topgrad
=
theano
.
grad
(
grad_input
.
sum
(),
wrt
=
(
filters
,
topgrad
))
assert
grad_filters
.
type
==
filters
.
type
,
(
grad_filters
,
grad_filters
.
type
,
filters
,
filters
.
type
)
assert
grad_topgrad
.
type
==
topgrad
.
type
,
(
grad_topgrad
,
grad_topgrad
.
type
,
topgrad
,
topgrad
.
type
)
theano/tensor/nnet/abstract_conv.py
浏览文件 @
6bf15e52
...
@@ -337,8 +337,12 @@ class AbstractConv2d(BaseAbstractConv2d):
...
@@ -337,8 +337,12 @@ class AbstractConv2d(BaseAbstractConv2d):
# Make sure that the broadcastable pattern of the inputs is used
# Make sure that the broadcastable pattern of the inputs is used
# for the gradients, even if the grad opts are not able to infer
# for the gradients, even if the grad opts are not able to infer
# that the dimensions are broadcastable.
# that the dimensions are broadcastable.
# Also make sure that the gradient lives on the same device than
# the corresponding input.
d_bottom
=
patternbroadcast
(
d_bottom
,
bottom
.
broadcastable
)
d_bottom
=
patternbroadcast
(
d_bottom
,
bottom
.
broadcastable
)
d_bottom
=
bottom
.
type
.
filter_variable
(
d_bottom
)
d_weights
=
patternbroadcast
(
d_weights
,
weights
.
broadcastable
)
d_weights
=
patternbroadcast
(
d_weights
,
weights
.
broadcastable
)
d_weights
=
weights
.
type
.
filter_variable
(
d_weights
)
return
d_bottom
,
d_weights
return
d_bottom
,
d_weights
def
infer_shape
(
self
,
node
,
input_shapes
):
def
infer_shape
(
self
,
node
,
input_shapes
):
...
@@ -414,8 +418,12 @@ class AbstractConv2d_gradWeights(BaseAbstractConv2d):
...
@@ -414,8 +418,12 @@ class AbstractConv2d_gradWeights(BaseAbstractConv2d):
# Make sure that the broadcastable pattern of the inputs is used
# Make sure that the broadcastable pattern of the inputs is used
# for the gradients, even if the grad opts are not able to infer
# for the gradients, even if the grad opts are not able to infer
# that the dimensions are broadcastable.
# that the dimensions are broadcastable.
# Also make sure that the gradient lives on the same device than
# the corresponding input.
d_bottom
=
patternbroadcast
(
d_bottom
,
bottom
.
broadcastable
)
d_bottom
=
patternbroadcast
(
d_bottom
,
bottom
.
broadcastable
)
d_bottom
=
bottom
.
type
.
filter_variable
(
d_bottom
)
d_top
=
patternbroadcast
(
d_top
,
top
.
broadcastable
)
d_top
=
patternbroadcast
(
d_top
,
top
.
broadcastable
)
d_top
=
top
.
type
.
filter_variable
(
d_top
)
d_height_width
=
(
theano
.
gradient
.
DisconnectedType
()(),)
d_height_width
=
(
theano
.
gradient
.
DisconnectedType
()(),)
return
(
d_bottom
,
d_top
)
+
d_height_width
return
(
d_bottom
,
d_top
)
+
d_height_width
...
@@ -491,8 +499,12 @@ class AbstractConv2d_gradInputs(BaseAbstractConv2d):
...
@@ -491,8 +499,12 @@ class AbstractConv2d_gradInputs(BaseAbstractConv2d):
# Make sure that the broadcastable pattern of the inputs is used
# Make sure that the broadcastable pattern of the inputs is used
# for the gradients, even if the grad opts are not able to infer
# for the gradients, even if the grad opts are not able to infer
# that the dimensions are broadcastable.
# that the dimensions are broadcastable.
# Also make sure that the gradient lives on the same device than
# the corresponding input.
d_weights
=
patternbroadcast
(
d_weights
,
weights
.
broadcastable
)
d_weights
=
patternbroadcast
(
d_weights
,
weights
.
broadcastable
)
d_weights
=
weights
.
type
.
filter_variable
(
d_weights
)
d_top
=
patternbroadcast
(
d_top
,
top
.
broadcastable
)
d_top
=
patternbroadcast
(
d_top
,
top
.
broadcastable
)
d_top
=
top
.
type
.
filter_variable
(
d_top
)
d_height_width
=
(
theano
.
gradient
.
DisconnectedType
()(),)
d_height_width
=
(
theano
.
gradient
.
DisconnectedType
()(),)
return
(
d_weights
,
d_top
)
+
d_height_width
return
(
d_weights
,
d_top
)
+
d_height_width
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论