Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2fe68421
提交
2fe68421
authored
4月 27, 2011
作者:
Philippe Hamel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added comments and test for ignore_border mode in neighbours.py
上级
29c92ffc
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
39 行增加
和
1 行删除
+39
-1
neighbours.py
theano/sandbox/neighbours.py
+9
-1
test_neighbours.py
theano/sandbox/test_neighbours.py
+30
-0
没有找到文件。
theano/sandbox/neighbours.py
浏览文件 @
2fe68421
...
@@ -12,6 +12,14 @@ if cuda_available:
...
@@ -12,6 +12,14 @@ if cuda_available:
class
Images2Neibs
(
Op
):
class
Images2Neibs
(
Op
):
def
__init__
(
self
,
mode
=
'valid'
):
def
__init__
(
self
,
mode
=
'valid'
):
"""
Modes:
valid : Reshapes the input as a a 2D tensor where each row is a pooling example.
Requires an input that is a multiple of the pooling factor (in each direction)
ignore_borders : Same as valid, but will ignore the borders if the shape(s) of the input
is not a multiple of the pooling factor(s)
wrap_centered : ?? TODO comment
"""
if
mode
not
in
[
'valid'
,
'wrap_centered'
,
'ignore_borders'
]:
if
mode
not
in
[
'valid'
,
'wrap_centered'
,
'ignore_borders'
]:
raise
NotImplementedError
(
"Only the mode valid, ignore_borders and wrap_centered have been implemented for the op Images2Neibs"
)
raise
NotImplementedError
(
"Only the mode valid, ignore_borders and wrap_centered have been implemented for the op Images2Neibs"
)
self
.
mode
=
mode
self
.
mode
=
mode
...
@@ -55,7 +63,7 @@ class Images2Neibs(Op):
...
@@ -55,7 +63,7 @@ class Images2Neibs(Op):
raise
NotImplementedError
()
raise
NotImplementedError
()
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
4
,)
return
(
5
,)
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
ten4
,
neib_shape
,
neib_step
=
inp
ten4
,
neib_shape
,
neib_step
=
inp
...
...
theano/sandbox/test_neighbours.py
浏览文件 @
2fe68421
...
@@ -411,6 +411,36 @@ def test_neibs_grad_verify_grad_warp_centered():
...
@@ -411,6 +411,36 @@ def test_neibs_grad_verify_grad_warp_centered():
except
NotImplementedError
:
except
NotImplementedError
:
pass
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
):
return
T
.
sum
(
T
.
sqr
(
images2neibs
(
images
,
(
2
,
2
),
mode
=
'ignore_borders'
)),
axis
=
[
0
,
1
])
unittest_tools
.
verify_grad
(
fn
,
[
images_val
],
mode
=
mode_without_gpu
)
# not implemented for gpu
# if cuda.cuda_available:
# unittest_tools.verify_grad(fn, [images_val], mode=mode_with_gpu)
def
test_neibs_valid_with_inconsistent_borders
():
shape
=
(
2
,
3
,
5
,
5
)
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
),
mode
=
'valid'
)),
axis
=
[
0
,
1
])
try
:
unittest_tools
.
verify_grad
(
fn
,
[
images_val
],
mode
=
mode_without_gpu
)
assert
False
,
"An error was expected"
except
TypeError
:
# This is expected if the assert is there
pass
def
test_neibs2images_crash_on_grad
():
def
test_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)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论