Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a78299b3
提交
a78299b3
authored
5月 31, 2009
作者:
desjagui@atchoum.iro.umontreal.ca
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Turns out we needed support for gradient of ConvOp in "full" mode ! (hint: reconstruction)
上级
4867ab0b
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
21 行增加
和
24 行删除
+21
-24
conv.py
theano/sandbox/conv.py
+20
-21
test_conv.py
theano/sandbox/test_conv.py
+1
-3
没有找到文件。
theano/sandbox/conv.py
浏览文件 @
a78299b3
...
...
@@ -106,34 +106,33 @@ class ConvOp(Op):
* will crash if filter the same size as input image
"""
# TODO: "full" mode should be supported. When in full mode, the hidden
# layer is larger than the input image. It therefore cannot be used as
# the kernel in the vis * hid convolution.
# Two possible solutions:
# - modify convolution code to support kernels of arbitrary shape
# - convolve the hidden w/ the visible layer as the kernel, then
# DimShuffle. Also verify that this works :)
if
self
.
out_mode
!=
'valid'
:
raise
NotImplementedError
(
'Only "valid" mode is currently supported in the gradient'
)
####### Determine gradient on kernels ########
mode
=
self
.
out_mode
if
inputs
.
ndim
==
3
:
inputs
=
tensor
.
shape_padleft
(
inputs
,
1
)
img
=
tensor
.
DimShuffle
(
inputs
.
broadcastable
,
(
1
,
0
,
2
,
3
))(
inputs
)
imshp
=
N
.
hstack
((
self
.
bsize
,
self
.
imshp
[
1
:]))
bsize
=
self
.
imshp
[
0
]
newin
=
tensor
.
DimShuffle
(
inputs
.
broadcastable
,
(
1
,
0
,
2
,
3
))(
inputs
)
newgz
=
tensor
.
DimShuffle
(
gz
.
broadcastable
,
(
1
,
0
,
2
,
3
))(
gz
)
if
self
.
out_mode
==
'valid'
:
(
img
,
filters
)
=
(
newin
,
newgz
)
(
bsize
,
nkern
)
=
(
self
.
imshp
[
0
],
self
.
nkern
)
imshp
=
N
.
hstack
((
self
.
bsize
,
self
.
imshp
[
1
:]))
kshp
=
self
.
outshp
[::
-
1
]
elif
self
.
out_mode
==
'full'
:
(
img
,
filters
)
=
(
newgz
,
newin
)
(
bsize
,
nkern
)
=
(
self
.
nkern
,
self
.
imshp
[
0
])
imshp
=
N
.
hstack
((
self
.
bsize
,
self
.
outshp
))
kshp
=
self
.
imshp
[
1
:][::
-
1
]
else
:
raise
NotImplementedError
(
'Only [full,valid] modes are currently supported.'
)
nkern
=
self
.
nkern
filters
=
tensor
.
DimShuffle
(
gz
.
broadcastable
,
(
1
,
0
,
2
,
3
))(
gz
)
filters
=
filters
[:,:,::
-
1
,::
-
1
]
kshp
=
self
.
outshp
[::
-
1
]
dw
=
ConvOp
(
imshp
,
kshp
,
nkern
,
bsize
,
1
,
1
,
output_mode
=
mode
)(
img
,
filters
)
dw
=
tensor
.
DimShuffle
(
dw
.
broadcastable
,
(
1
,
0
,
2
,
3
))(
dw
)
dw
=
dw
[:,:,::
-
1
,::
-
1
]
dw
=
ConvOp
(
imshp
,
kshp
,
nkern
,
bsize
,
1
,
1
,
output_mode
=
'valid'
)(
img
,
filters
)
if
self
.
out_mode
==
'valid'
:
# before DimShuffle, dw is of shape visdim x nkern x kshp[0] x kshp[1]
dw
=
tensor
.
DimShuffle
(
dw
.
broadcastable
,
(
1
,
0
,
2
,
3
))(
dw
)
dw
=
dw
[:,:,::
-
1
,::
-
1
]
####### Determine gradient on inputs ########
mode
=
'valid'
if
self
.
out_mode
==
'full'
else
'full'
...
...
theano/sandbox/test_conv.py
浏览文件 @
a78299b3
...
...
@@ -309,19 +309,17 @@ class TestConvOp(unittest.TestCase):
kerns
=
T
.
dmatrix
(
'kerns'
)
for
mode
in
'valid'
,
'full'
:
for
imshp
in
(
5
,
5
),(
2
,
5
,
5
),(
2
,
10
,
10
):
# (12,10), (3,12,11):
for
imshp
in
(
5
,
5
),(
2
,
5
,
5
),(
2
,
10
,
10
):
# (12,10), (3,12,11):
visdim
=
1
if
len
(
imshp
)
!=
3
else
imshp
[
0
]
print
'visdim = '
,
visdim
for
kshp
in
(
3
,
3
),:
# (6,7):
imgvals
=
N
.
random
.
random
(
N
.
hstack
((
bsize
,
imshp
)))
print
'imgvals.shape = '
,
imgvals
.
shape
imgvals
=
imgvals
.
reshape
(
bsize
,
-
1
)
if
visdim
==
1
:
kernvals
=
N
.
random
.
rand
(
nkern
,
kshp
[
0
],
kshp
[
1
])
else
:
kernvals
=
N
.
random
.
rand
(
nkern
,
visdim
,
kshp
[
0
],
kshp
[
1
])
print
'kernvals.shape = '
,
kernvals
.
shape
kernvals
=
kernvals
.
reshape
(
nkern
,
-
1
)
def
testf
(
imgs
,
kerns
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论