Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
86613b02
提交
86613b02
authored
8月 21, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reenabled the grad of Images2Neibs. The problem was in the tests, not op.grad()
The problem was that we tested sqr(images2neibs(x)) with too big values. This caused problem when we compute the numerical gradient.
上级
9783a17d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
76 行增加
和
68 行删除
+76
-68
neighbours.py
theano/sandbox/neighbours.py
+11
-2
test_neighbours.py
theano/sandbox/test_neighbours.py
+65
-66
没有找到文件。
theano/sandbox/neighbours.py
浏览文件 @
86613b02
...
@@ -84,8 +84,17 @@ class Images2Neibs(Op):
...
@@ -84,8 +84,17 @@ 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
return
[
grad_not_implemented
(
self
,
i
,
ip
)
\
for
i
,
ip
in
enumerate
(
inp
)
]
if
self
.
mode
in
[
'valid'
,
'ignore_borders'
]:
if
(
neib_shape
is
neib_step
or
neib_shape
==
neib_step
or
# Theano Constant == do not compare the data
# the equals function do that.
(
hasattr
(
neib_shape
,
"equals"
)
and
neib_shape
.
equals
(
neib_step
))):
return
[
neibs2images
(
gz
,
neib_shape
,
x
.
shape
,
mode
=
self
.
mode
),
None
,
None
]
return
[
grad_not_implemented
(
self
,
0
,
x
),
None
,
None
]
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
5
,)
return
(
5
,)
...
...
theano/sandbox/test_neighbours.py
浏览文件 @
86613b02
...
@@ -323,61 +323,72 @@ def speed_neibs_wrap_centered():
...
@@ -323,61 +323,72 @@ def speed_neibs_wrap_centered():
for
i
in
range
(
1000
):
for
i
in
range
(
1000
):
f
()
f
()
# Disable the test as the grad is wrongly implemented
def
tes_neibs_grad_verify_grad
():
shape
=
(
2
,
3
,
4
,
4
)
images
=
T
.
dtensor4
()
images_val
=
numpy
.
arange
(
numpy
.
prod
(
shape
),
dtype
=
'float32'
)
.
reshape
(
shape
)
def
fn
(
images
):
return
T
.
sum
(
T
.
sqr
(
images2neibs
(
images
,
(
2
,
2
))),
axis
=
[
0
,
1
])
unittest_tools
.
verify_grad
(
fn
,
[
images_val
],
mode
=
mode_without_gpu
)
if
cuda
.
cuda_available
:
unittest_tools
.
verify_grad
(
fn
,
[
images_val
],
mode
=
mode_with_gpu
)
def
test_neibs_grad_verify_grad_warp_centered
():
# It is not implemented for now. So test that we raise an error.
shape
=
(
2
,
3
,
6
,
6
)
images
=
T
.
dtensor4
()
images_val
=
numpy
.
arange
(
numpy
.
prod
(
shape
),
dtype
=
'float32'
)
.
reshape
(
shape
)
def
fn
(
images
):
return
T
.
sum
(
T
.
sqr
(
images2neibs
(
images
,
(
3
,
3
),
mode
=
'wrap_centered'
)),
axis
=
[
0
,
1
])
try
:
unittest_tools
.
verify_grad
(
fn
,
[
images_val
],
mode
=
mode_without_gpu
)
raise
Exception
(
"Expected an error"
)
except
NotImplementedError
:
pass
if
cuda
.
cuda_available
:
try
:
unittest_tools
.
verify_grad
(
fn
,
[
images_val
],
mode
=
mode_with_gpu
)
raise
Exception
(
"Expected an error"
)
except
NotImplementedError
:
pass
def
test_neibs_ignore_border
():
shape
=
(
2
,
3
,
5
,
5
)
images
=
T
.
dtensor4
()
images_val
=
numpy
.
arange
(
numpy
.
prod
(
shape
),
dtype
=
'float32'
)
.
reshape
(
shape
)
def
fn
(
images
):
class
T_Images2Neibs
(
unittest_tools
.
InferShapeTester
):
return
T
.
sum
(
T
.
sqr
(
images2neibs
(
images
,
(
2
,
2
),
def
test_grad_valid
(
self
):
mode
=
'ignore_borders'
)),
axis
=
[
0
,
1
])
shape
=
(
2
,
3
,
4
,
4
)
images_val
=
numpy
.
random
.
rand
(
*
shape
)
.
astype
(
'float32'
)
# Disable the test as the grad is wrongly implemented
#unittest_tools.verify_grad(fn, [images_val], mode=mode_without_gpu)
def
fn
(
images
):
return
images2neibs
(
images
,
(
2
,
2
))
# not implemented for gpu
# if cuda.cuda_available:
unittest_tools
.
verify_grad
(
fn
,
[
images_val
],
mode
=
mode_without_gpu
,
# unittest_tools.verify_grad(fn, [images_val], mode=mode_with_gpu)
eps
=
0.1
)
if
cuda
.
cuda_available
:
unittest_tools
.
verify_grad
(
fn
,
[
images_val
],
mode
=
mode_with_gpu
,
eps
=
0.1
)
# The grad is not defined when the neib_shape and neib_step
# are not the same.
def
fn
(
images
):
return
images2neibs
(
images
,
(
2
,
2
),
(
1
,
1
))
self
.
assertRaises
(
NotImplementedError
,
unittest_tools
.
verify_grad
,
fn
,
[
images_val
],
mode
=
mode_without_gpu
)
def
test_grad_warp_centered
(
self
):
# It is not implemented for now. So test that we raise an error.
shape
=
(
2
,
3
,
6
,
6
)
images_val
=
numpy
.
random
.
rand
(
*
shape
)
.
astype
(
'float32'
)
def
fn
(
images
):
return
images2neibs
(
images
,
(
3
,
3
),
mode
=
'wrap_centered'
)
self
.
assertRaises
(
NotImplementedError
,
unittest_tools
.
verify_grad
,
fn
,
[
images_val
],
mode
=
mode_without_gpu
)
if
cuda
.
cuda_available
:
self
.
assertRaises
(
NotImplementedError
,
unittest_tools
.
verify_grad
,
fn
,
[
images_val
],
mode
=
mode_with_gpu
)
def
test_grad_ignore_border
(
self
):
shape
=
(
2
,
3
,
5
,
5
)
images
=
T
.
dtensor4
()
images_val
=
numpy
.
random
.
rand
(
*
shape
)
.
astype
(
'float32'
)
def
fn
(
images
):
return
images2neibs
(
images
,
(
2
,
2
),
mode
=
'ignore_borders'
)
unittest_tools
.
verify_grad
(
fn
,
[
images_val
],
mode
=
mode_without_gpu
,
eps
=
0.1
)
# GPU code not implemented in that case, but is should still
# not crash.
if
cuda
.
cuda_available
:
unittest_tools
.
verify_grad
(
fn
,
[
images_val
],
mode
=
mode_with_gpu
,
eps
=
0.1
)
def
test_neibs2images_crash_on_grad
(
self
):
# say we had images of size (2, 3, 20, 20)
# then we extracted 2x2 neighbors on this, we get (2 * 3 * 10 * 10, 4)
neibs
=
T
.
dmatrix
()
neibs_val
=
numpy
.
random
.
rand
(
600
,
4
)
to_images
=
T
.
sum
(
neibs2images
(
neibs
,
(
2
,
2
),
(
2
,
3
,
20
,
20
)))
g
=
T
.
grad
(
to_images
,
neibs
)
fn
=
theano
.
function
([
neibs
],
to_images
,
mode
=
mode_without_gpu
)
#print "Compiled"
fn
(
neibs_val
)
def
test_neibs_valid_with_inconsistent_borders
():
def
test_neibs_valid_with_inconsistent_borders
():
...
@@ -401,18 +412,6 @@ def test_neibs_valid_with_inconsistent_borders():
...
@@ -401,18 +412,6 @@ def test_neibs_valid_with_inconsistent_borders():
pass
pass
# Disable the test as the grad is wrongly implemented
def
tes_neibs2images_crash_on_grad
():
# say we had images of size (2, 3, 20, 20)
# then we extracted 2x2 neighbors on this, we get (2 * 3 * 10 * 10, 4)
neibs
=
T
.
dmatrix
()
neibs_val
=
numpy
.
random
.
rand
(
600
,
4
)
to_images
=
T
.
sum
(
neibs2images
(
neibs
,
(
2
,
2
),
(
2
,
3
,
20
,
20
)))
g
=
T
.
grad
(
to_images
,
neibs
)
fn
=
theano
.
function
([
neibs
],
to_images
,
mode
=
mode_without_gpu
)
#print "Compiled"
fn
(
neibs_val
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
#test_neibs_gpu()
#test_neibs_gpu()
#test_neibs()
#test_neibs()
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论