Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
24ace594
提交
24ace594
authored
12月 15, 2015
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3774 from lamblin/abstractconv_fixes
Fix broadcastable pattern of gradient in abstract conv
上级
458e1594
0f5f1890
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
42 行增加
和
1 行删除
+42
-1
abstract_conv.py
theano/tensor/nnet/abstract_conv.py
+19
-1
test_conv.py
theano/tensor/nnet/tests/test_conv.py
+23
-0
没有找到文件。
theano/tensor/nnet/abstract_conv.py
浏览文件 @
24ace594
...
@@ -5,7 +5,7 @@ Define abstract conv2d interface
...
@@ -5,7 +5,7 @@ Define abstract conv2d interface
import
logging
import
logging
import
theano
import
theano
from
theano.tensor
import
as_tensor_variable
from
theano.tensor
import
as_tensor_variable
,
patternbroadcast
from
theano.gof
import
Apply
,
Op
from
theano.gof
import
Apply
,
Op
...
@@ -314,6 +314,12 @@ class AbstractConv2d(BaseAbstractConv2d):
...
@@ -314,6 +314,12 @@ class AbstractConv2d(BaseAbstractConv2d):
self
.
filter_flip
)(
self
.
filter_flip
)(
bottom
,
top
,
weights
.
shape
[
-
2
:])
bottom
,
top
,
weights
.
shape
[
-
2
:])
# Make sure that the broadcastable pattern of the inputs is used
# for the gradients, even if the grad opts are not able to infer
# that the dimensions are broadcastable.
d_bottom
=
patternbroadcast
(
d_bottom
,
bottom
.
broadcastable
)
d_weights
=
patternbroadcast
(
d_weights
,
weights
.
broadcastable
)
return
d_bottom
,
d_weights
return
d_bottom
,
d_weights
...
@@ -369,6 +375,12 @@ class AbstractConv2d_gradWeights(BaseAbstractConv2d):
...
@@ -369,6 +375,12 @@ class AbstractConv2d_gradWeights(BaseAbstractConv2d):
self
.
border_mode
,
self
.
border_mode
,
self
.
subsample
,
self
.
subsample
,
self
.
filter_flip
)(
bottom
,
weights
)
self
.
filter_flip
)(
bottom
,
weights
)
# Make sure that the broadcastable pattern of the inputs is used
# for the gradients, even if the grad opts are not able to infer
# that the dimensions are broadcastable.
d_bottom
=
patternbroadcast
(
d_bottom
,
bottom
.
broadcastable
)
d_top
=
patternbroadcast
(
d_top
,
top
.
broadcastable
)
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
...
@@ -425,6 +437,12 @@ class AbstractConv2d_gradInputs(BaseAbstractConv2d):
...
@@ -425,6 +437,12 @@ class AbstractConv2d_gradInputs(BaseAbstractConv2d):
d_top
=
AbstractConv2d
(
self
.
imshp
,
self
.
kshp
,
d_top
=
AbstractConv2d
(
self
.
imshp
,
self
.
kshp
,
self
.
border_mode
,
self
.
subsample
)(
self
.
border_mode
,
self
.
subsample
)(
bottom
,
weights
)
bottom
,
weights
)
# Make sure that the broadcastable pattern of the inputs is used
# for the gradients, even if the grad opts are not able to infer
# that the dimensions are broadcastable.
d_weights
=
patternbroadcast
(
d_weights
,
weights
.
broadcastable
)
d_top
=
patternbroadcast
(
d_top
,
top
.
broadcastable
)
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
...
...
theano/tensor/nnet/tests/test_conv.py
浏览文件 @
24ace594
...
@@ -521,6 +521,29 @@ class TestConv2D(utt.InferShapeTester):
...
@@ -521,6 +521,29 @@ class TestConv2D(utt.InferShapeTester):
border_mode
=
'full'
)],
[
adtens_val
,
bdtens_val
],
conv
.
ConvOp
)
border_mode
=
'full'
)],
[
adtens_val
,
bdtens_val
],
conv
.
ConvOp
)
# Test that broadcasting of gradients works correctly when using the
# nnet.conv2d() interface. This was reported in #3763, and uses the example
# code from that ticket.
def
test_broadcast_grad
():
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
x1
=
T
.
tensor4
(
'x'
)
x1_data
=
rng
.
randn
(
1
,
1
,
300
,
300
)
sigma
=
T
.
scalar
(
'sigma'
)
sigma_data
=
20
window_radius
=
3
filter_1d
=
T
.
arange
(
-
window_radius
,
window_radius
+
1
)
filter_1d
=
filter_1d
.
astype
(
theano
.
config
.
floatX
)
filter_1d
=
T
.
exp
(
-
0.5
*
filter_1d
**
2
/
sigma
**
2
)
filter_1d
=
filter_1d
/
filter_1d
.
sum
()
filter_W
=
filter_1d
.
dimshuffle
([
'x'
,
'x'
,
0
,
'x'
])
y
=
theano
.
tensor
.
nnet
.
conv2d
(
x1
,
filter_W
,
border_mode
=
'full'
,
filter_shape
=
[
1
,
1
,
None
,
None
])
theano
.
grad
(
y
.
sum
(),
sigma
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
t
=
TestConv2D
(
'setUp'
)
t
=
TestConv2D
(
'setUp'
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论