Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
531b3ecd
提交
531b3ecd
authored
11月 24, 2011
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Disabled the grad on Images2Neib as it was doing the inverse and not the grad!
When tring to make the grad raise an Exception with an error that the old version returned wrong answer.
上级
ba1d49f1
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
17 行增加
和
56 行删除
+17
-56
neighbours.py
theano/sandbox/neighbours.py
+7
-2
test_neighbours.py
theano/sandbox/test_neighbours.py
+10
-54
没有找到文件。
theano/sandbox/neighbours.py
浏览文件 @
531b3ecd
...
@@ -64,8 +64,13 @@ class Images2Neibs(Op):
...
@@ -64,8 +64,13 @@ class Images2Neibs(Op):
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
x
,
neib_shape
,
neib_step
=
inp
x
,
neib_shape
,
neib_step
=
inp
gz
,
=
grads
gz
,
=
grads
if
self
.
mode
in
[
'valid'
,
'ignore_borders'
]:
if
self
.
mode
in
[
'valid'
,
'ignore_borders'
]:
return
[
neibs2images
(
gz
,
neib_shape
,
x
.
shape
,
mode
=
self
.
mode
),
None
,
None
]
raise
Exception
(
"The Images2Neibs grad is not implemented."
" It was in the past, but returned the wrong"
" answer!"
)
# This is the reverse of the op, not the grad!
return
[
neibs2images
(
gz
,
neib_shape
,
x
.
shape
,
mode
=
self
.
mode
),
None
,
None
]
else
:
else
:
raise
NotImplementedError
()
raise
NotImplementedError
()
...
...
theano/sandbox/test_neighbours.py
浏览文件 @
531b3ecd
...
@@ -361,56 +361,8 @@ def speed_neibs_wrap_centered():
...
@@ -361,56 +361,8 @@ def speed_neibs_wrap_centered():
for
i
in
range
(
1000
):
for
i
in
range
(
1000
):
f
()
f
()
# Disable the test as the grad is wronly implemented
def
test_neibs_grad
():
def
tes_neibs_grad_verify_grad
():
shape
=
(
2
,
3
,
4
,
4
)
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
),
dtype
=
'float32'
)
.
reshape
(
shape
))
cost
=
T
.
sum
(
T
.
sqr
(
images2neibs
(
images
,
(
2
,
2
))),
axis
=
[
0
,
1
])
grad
=
T
.
grad
(
cost
,
images
)
f
=
theano
.
function
([],
[
cost
,
grad
],
mode
=
mode_without_gpu
)
got
=
f
()
should_get
=
[
numpy
.
asarray
(
290320.0
,
dtype
=
numpy
.
float32
),
numpy
.
asarray
([[[[
0.
,
2.
,
4.
,
6.
],
[
8.
,
10.
,
12.
,
14.
],
[
16.
,
18.
,
20.
,
22.
],
[
24.
,
26.
,
28.
,
30.
]],
[[
32.
,
34.
,
36.
,
38.
],
[
40.
,
42.
,
44.
,
46.
],
[
48.
,
50.
,
52.
,
54.
],
[
56.
,
58.
,
60.
,
62.
]],
[[
64.
,
66.
,
68.
,
70.
],
[
72.
,
74.
,
76.
,
78.
],
[
80.
,
82.
,
84.
,
86.
],
[
88.
,
90.
,
92.
,
94.
]]],
[[[
96.
,
98.
,
100.
,
102.
],
[
104.
,
106.
,
108.
,
110.
],
[
112.
,
114.
,
116.
,
118.
],
[
120.
,
122.
,
124.
,
126.
]],
[[
128.
,
130.
,
132.
,
134.
],
[
136.
,
138.
,
140.
,
142.
],
[
144.
,
146.
,
148.
,
150.
],
[
152.
,
154.
,
156.
,
158.
]],
[[
160.
,
162.
,
164.
,
166.
],
[
168.
,
170.
,
172.
,
174.
],
[
176.
,
178.
,
180.
,
182.
],
[
184.
,
186.
,
188.
,
190.
]]]],
dtype
=
numpy
.
float32
)]
assert
numpy
.
allclose
(
got
[
0
],
should_get
[
0
])
assert
numpy
.
allclose
(
got
[
1
],
should_get
[
1
])
def
test_neibs_grad_verify_grad
():
shape
=
(
2
,
3
,
4
,
4
)
shape
=
(
2
,
3
,
4
,
4
)
images
=
T
.
dtensor4
()
images
=
T
.
dtensor4
()
images_val
=
numpy
.
arange
(
numpy
.
prod
(
shape
),
images_val
=
numpy
.
arange
(
numpy
.
prod
(
shape
),
...
@@ -458,7 +410,8 @@ def test_neibs_ignore_border():
...
@@ -458,7 +410,8 @@ def test_neibs_ignore_border():
return
T
.
sum
(
T
.
sqr
(
images2neibs
(
images
,
(
2
,
2
),
return
T
.
sum
(
T
.
sqr
(
images2neibs
(
images
,
(
2
,
2
),
mode
=
'ignore_borders'
)),
axis
=
[
0
,
1
])
mode
=
'ignore_borders'
)),
axis
=
[
0
,
1
])
unittest_tools
.
verify_grad
(
fn
,
[
images_val
],
mode
=
mode_without_gpu
)
# Disable the test as the grad is wronly implemented
#unittest_tools.verify_grad(fn, [images_val], mode=mode_without_gpu)
# not implemented for gpu
# not implemented for gpu
# if cuda.cuda_available:
# if cuda.cuda_available:
...
@@ -475,15 +428,18 @@ def test_neibs_valid_with_inconsistent_borders():
...
@@ -475,15 +428,18 @@ def test_neibs_valid_with_inconsistent_borders():
return
T
.
sum
(
T
.
sqr
(
images2neibs
(
images
,
(
2
,
2
),
mode
=
'valid'
)),
return
T
.
sum
(
T
.
sqr
(
images2neibs
(
images
,
(
2
,
2
),
mode
=
'valid'
)),
axis
=
[
0
,
1
])
axis
=
[
0
,
1
])
f
=
theano
.
function
([
images
],
T
.
sqr
(
images2neibs
(
images
,
(
2
,
2
),
mode
=
'valid'
)))
try
:
try
:
unittest_tools
.
verify_grad
(
fn
,
[
images_val
],
mode
=
mode_without_gpu
)
f
(
images_val
)
assert
False
,
"An error was expected"
assert
False
,
"An error was expected"
except
TypeError
:
except
TypeError
,
e
:
# This is expected if the assert is there
# This is expected if the assert is there
pass
pass
def
test_neibs2images_crash_on_grad
():
# Disable the test as the grad is wronly implemented
def
tes_neibs2images_crash_on_grad
():
# say we had images of size (2, 3, 20, 20)
# say we had images of size (2, 3, 20, 20)
# then we extracted 2x2 neighbors on this, we get (2 * 3 * 10 * 10, 4)
# then we extracted 2x2 neighbors on this, we get (2 * 3 * 10 * 10, 4)
neibs
=
T
.
dmatrix
()
neibs
=
T
.
dmatrix
()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论