Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f477c6a1
提交
f477c6a1
authored
7月 12, 2012
作者:
goodfeli
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #756 from lamblin/fix_conv_subsampling
Fix conv subsampling
上级
db2bd471
eaef458c
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
29 行增加
和
3 行删除
+29
-3
Conv3D.py
theano/tensor/nnet/Conv3D.py
+6
-1
conv.py
theano/tensor/nnet/conv.py
+20
-0
test_conv.py
theano/tensor/nnet/tests/test_conv.py
+3
-2
没有找到文件。
theano/tensor/nnet/Conv3D.py
浏览文件 @
f477c6a1
...
@@ -80,10 +80,15 @@ class Conv3D(theano.Op):
...
@@ -80,10 +80,15 @@ class Conv3D(theano.Op):
#quit(-1)
#quit(-1)
#dCdH = printing.Print("dCdH = ",["shape"])
#dCdH = printing.Print("dCdH = ",["shape"])
dCdV
=
ConvTransp3D
.
convTransp3D
(
W
,
T
.
zeros_like
(
V
[
0
,
0
,
0
,
0
,:]),
d
,
dCdH
,
V
.
shape
[
1
:
4
]
)
# Make sure the broadcasting pattern of the gradient is the the same
# as the initial variable
dCdV
=
ConvTransp3D
.
convTransp3D
(
W
,
T
.
zeros_like
(
V
[
0
,
0
,
0
,
0
,:]),
d
,
dCdH
,
V
.
shape
[
1
:
4
])
dCdV
=
T
.
patternbroadcast
(
dCdV
,
V
.
broadcastable
)
WShape
=
W
.
shape
WShape
=
W
.
shape
dCdW
=
ConvGrad3D
.
convGrad3D
(
V
,
d
,
WShape
,
dCdH
)
dCdW
=
ConvGrad3D
.
convGrad3D
(
V
,
d
,
WShape
,
dCdH
)
dCdW
=
T
.
patternbroadcast
(
dCdW
,
W
.
broadcastable
)
dCdb
=
T
.
sum
(
dCdH
,
axis
=
(
0
,
1
,
2
,
3
))
dCdb
=
T
.
sum
(
dCdH
,
axis
=
(
0
,
1
,
2
,
3
))
dCdb
=
T
.
patternbroadcast
(
dCdb
,
b
.
broadcastable
)
dCdd
=
None
#not differentiable, since d is not continuous
dCdd
=
None
#not differentiable, since d is not continuous
if
'name'
in
dir
(
dCdH
)
and
dCdH
.
name
is
not
None
:
if
'name'
in
dir
(
dCdH
)
and
dCdH
.
name
is
not
None
:
...
...
theano/tensor/nnet/conv.py
浏览文件 @
f477c6a1
...
@@ -716,6 +716,26 @@ class ConvOp(Op):
...
@@ -716,6 +716,26 @@ class ConvOp(Op):
if
self
.
imshp
!=
self
.
imshp_logical
or
self
.
kshp
!=
self
.
kshp_logical
:
if
self
.
imshp
!=
self
.
imshp_logical
or
self
.
kshp
!=
self
.
kshp_logical
:
raise
NotImplementedError
(
'todo'
)
raise
NotImplementedError
(
'todo'
)
if
self
.
out_mode
==
'valid'
and
(
self
.
dx
,
self
.
dy
)
!=
(
1
,
1
):
# Use the gradient as defined in conv3D, because the implementation
# by Conv is slow (about 3x slower than conv3D, and probably 10x
# slower than it could be), and incorrect when dx or dy > 2.
# build a "node", that should be equivalent to the one given by
# self.make_node, but using conv3D instead of self.
tmp_node
=
theano
.
tensor
.
nnet
.
conv3D
(
V
=
inputs
.
dimshuffle
(
0
,
2
,
3
,
'x'
,
1
),
W
=
kerns
[:,
:,
::
-
1
,
::
-
1
]
.
dimshuffle
(
0
,
2
,
3
,
'x'
,
1
),
b
=
theano
.
tensor
.
alloc
(
numpy
.
asarray
(
0
,
dtype
=
kerns
.
dtype
),
kerns
.
shape
[
0
]),
d
=
(
self
.
dx
,
self
.
dy
,
1
))
node
=
theano
.
tensor
.
addbroadcast
(
tmp_node
,
3
)
.
dimshuffle
(
0
,
4
,
1
,
2
)
# mimic what happens inside theano.grad: get the input gradient
# of the final cost wrt all variables involved.
tmp_gmap
=
theano
.
gradient
.
grad_sources_inputs
([(
node
,
gz
)],
[
inputs
,
kerns
])
return
[
tmp_gmap
[
inputs
],
tmp_gmap
[
kerns
]]
if
self
.
dx
not
in
(
1
,
2
)
or
self
.
dy
not
in
(
1
,
2
):
if
self
.
dx
not
in
(
1
,
2
)
or
self
.
dy
not
in
(
1
,
2
):
raise
NotImplementedError
(
"ERROR: We disable ConvOp.grad now when dx or "
\
raise
NotImplementedError
(
"ERROR: We disable ConvOp.grad now when dx or "
\
"dy are different from 1 and 2, as there is a bug in it."
)
"dy are different from 1 and 2, as there is a bug in it."
)
...
...
theano/tensor/nnet/tests/test_conv.py
浏览文件 @
f477c6a1
...
@@ -236,10 +236,11 @@ class TestConv2D(unittest.TestCase):
...
@@ -236,10 +236,11 @@ class TestConv2D(unittest.TestCase):
self
.
validate
((
3
,
2
,
7
,
5
),
(
5
,
2
,
2
,
3
),
'valid'
,
subsample
=
(
2
,
2
))
self
.
validate
((
3
,
2
,
7
,
5
),
(
5
,
2
,
2
,
3
),
'valid'
,
subsample
=
(
2
,
2
))
self
.
validate
((
3
,
2
,
7
,
5
),
(
5
,
2
,
2
,
3
),
'full'
,
subsample
=
(
2
,
2
))
self
.
validate
((
3
,
2
,
7
,
5
),
(
5
,
2
,
2
,
3
),
'full'
,
subsample
=
(
2
,
2
))
self
.
validate
((
3
,
2
,
7
,
5
),
(
5
,
2
,
2
,
3
),
'valid'
,
subsample
=
(
2
,
1
))
self
.
validate
((
3
,
2
,
7
,
5
),
(
5
,
2
,
2
,
3
),
'valid'
,
subsample
=
(
2
,
1
))
self
.
validate
((
1
,
1
,
6
,
6
),
(
1
,
1
,
3
,
3
),
'valid'
,
subsample
=
(
3
,
3
))
# Fails as of 2012-0
4-12
# Fails as of 2012-0
7-11
self
.
assertRaises
(
NotImplementedError
,
self
.
validate
,
(
1
,
1
,
6
,
6
),
self
.
assertRaises
(
NotImplementedError
,
self
.
validate
,
(
1
,
1
,
6
,
6
),
(
1
,
1
,
3
,
3
),
'
valid
'
,
subsample
=
(
3
,
3
))
(
1
,
1
,
3
,
3
),
'
full
'
,
subsample
=
(
3
,
3
))
def
test_shape_Constant_tensor
(
self
):
def
test_shape_Constant_tensor
(
self
):
"""
"""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论