Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7509fa75
提交
7509fa75
authored
6月 13, 2017
作者:
Pascal Lamblin
提交者:
GitHub
6月 13, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5942 from botev/master
Added mode 'half' to Images2Neibs. Tests pass.
上级
88b49770
3805415a
全部展开
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
142 行增加
和
6 行删除
+142
-6
neighbours.py
theano/gpuarray/neighbours.py
+0
-0
neighbours.py
theano/tensor/nnet/neighbours.py
+0
-0
test_neighbours.py
theano/tensor/nnet/tests/test_neighbours.py
+142
-6
没有找到文件。
theano/gpuarray/neighbours.py
浏览文件 @
7509fa75
差异被折叠。
点击展开。
theano/tensor/nnet/neighbours.py
浏览文件 @
7509fa75
差异被折叠。
点击展开。
theano/tensor/nnet/tests/test_neighbours.py
浏览文件 @
7509fa75
...
@@ -236,6 +236,57 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -236,6 +236,57 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
# TODO: why this is commented?
# TODO: why this is commented?
# assert numpy.allclose(images.get_value(borrow=True), g())
# assert numpy.allclose(images.get_value(borrow=True), g())
def
test_neibs_half_step_by_valid
(
self
):
neib_shapes
=
((
3
,
3
),
(
3
,
5
),
(
5
,
3
))
for
shp_idx
,
(
shape
,
neib_step
)
in
enumerate
([
[(
7
,
8
,
5
,
5
),
(
1
,
1
)],
[(
7
,
8
,
5
,
5
),
(
2
,
2
)],
[(
7
,
8
,
5
,
5
),
(
4
,
4
)],
[(
7
,
8
,
5
,
5
),
(
1
,
4
)],
[(
7
,
8
,
5
,
5
),
(
4
,
1
)],
[(
80
,
90
,
5
,
5
),
(
1
,
2
)],
[(
1025
,
9
,
5
,
5
),
(
2
,
1
)],
[(
1
,
1
,
5
,
1037
),
(
2
,
4
)],
[(
1
,
1
,
1045
,
5
),
(
4
,
2
)]]
):
for
neib_shape
in
neib_shapes
:
for
dtype
in
self
.
dtypes
:
x
=
theano
.
shared
(
np
.
random
.
randn
(
*
shape
)
.
astype
(
dtype
))
extra
=
(
neib_shape
[
0
]
//
2
,
neib_shape
[
1
]
//
2
)
padded_shape
=
(
x
.
shape
[
0
],
x
.
shape
[
1
],
x
.
shape
[
2
]
+
2
*
extra
[
0
],
x
.
shape
[
3
]
+
2
*
extra
[
1
])
padded_x
=
T
.
zeros
(
padded_shape
)
padded_x
=
T
.
set_subtensor
(
padded_x
[:,
:,
extra
[
0
]:
-
extra
[
0
],
extra
[
1
]:
-
extra
[
1
]],
x
)
x_using_valid
=
images2neibs
(
padded_x
,
neib_shape
,
neib_step
,
mode
=
"valid"
)
x_using_half
=
images2neibs
(
x
,
neib_shape
,
neib_step
,
mode
=
"half"
)
close
=
T
.
allclose
(
x_using_valid
,
x_using_half
)
f
=
theano
.
function
([],
close
,
mode
=
self
.
mode
)
assert
f
()
def
test_neibs_full_step_by_valid
(
self
):
for
shp_idx
,
(
shape
,
neib_step
,
neib_shapes
)
in
enumerate
([
[(
7
,
8
,
5
,
5
),
(
1
,
1
),
((
3
,
3
),
(
3
,
5
),
(
5
,
3
))],
[(
7
,
8
,
5
,
5
),
(
2
,
2
),
((
3
,
3
),
(
3
,
5
),
(
5
,
3
))],
[(
7
,
8
,
6
,
6
),
(
3
,
3
),
((
2
,
2
),
(
2
,
5
),
(
5
,
2
))],
[(
7
,
8
,
6
,
6
),
(
1
,
3
),
((
2
,
2
),
(
2
,
5
),
(
5
,
2
))],
[(
7
,
8
,
6
,
6
),
(
3
,
1
),
((
2
,
2
),
(
2
,
5
),
(
5
,
2
))],
[(
80
,
90
,
5
,
5
),
(
1
,
2
),
((
3
,
3
),
(
3
,
5
),
(
5
,
3
))],
[(
1025
,
9
,
5
,
5
),
(
2
,
1
),
((
3
,
3
),
(
3
,
5
),
(
5
,
3
))],
[(
1
,
1
,
11
,
1037
),
(
2
,
3
),
((
3
,
3
),
(
5
,
3
))],
[(
1
,
1
,
1043
,
11
),
(
3
,
2
),
((
3
,
3
),
(
3
,
5
))]]
):
for
neib_shape
in
neib_shapes
:
for
dtype
in
self
.
dtypes
:
x
=
theano
.
shared
(
np
.
random
.
randn
(
*
shape
)
.
astype
(
dtype
))
extra
=
(
neib_shape
[
0
]
-
1
,
neib_shape
[
1
]
-
1
)
padded_shape
=
(
x
.
shape
[
0
],
x
.
shape
[
1
],
x
.
shape
[
2
]
+
2
*
extra
[
0
],
x
.
shape
[
3
]
+
2
*
extra
[
1
])
padded_x
=
T
.
zeros
(
padded_shape
)
padded_x
=
T
.
set_subtensor
(
padded_x
[:,
:,
extra
[
0
]:
-
extra
[
0
],
extra
[
1
]:
-
extra
[
1
]],
x
)
x_using_valid
=
images2neibs
(
padded_x
,
neib_shape
,
neib_step
,
mode
=
"valid"
)
x_using_full
=
images2neibs
(
x
,
neib_shape
,
neib_step
,
mode
=
"full"
)
close
=
T
.
allclose
(
x_using_valid
,
x_using_full
)
f
=
theano
.
function
([],
close
,
mode
=
self
.
mode
)
assert
f
()
def
test_neibs_bad_shape_wrap_centered
(
self
):
def
test_neibs_bad_shape_wrap_centered
(
self
):
shape
=
(
2
,
3
,
10
,
10
)
shape
=
(
2
,
3
,
10
,
10
)
...
@@ -281,6 +332,28 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -281,6 +332,28 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
self
.
assertRaises
(
TypeError
,
unittest_tools
.
verify_grad
,
self
.
assertRaises
(
TypeError
,
unittest_tools
.
verify_grad
,
fn
,
[
images_val
],
mode
=
self
.
mode
)
fn
,
[
images_val
],
mode
=
self
.
mode
)
def
test_grad_half
(
self
):
# It is not implemented for now. So test that we raise an error.
shape
=
(
2
,
3
,
6
,
6
)
images_val
=
np
.
random
.
rand
(
*
shape
)
.
astype
(
'float32'
)
def
fn
(
images
):
return
images2neibs
(
images
,
(
3
,
3
),
mode
=
'half'
)
self
.
assertRaises
(
TypeError
,
unittest_tools
.
verify_grad
,
fn
,
[
images_val
],
mode
=
self
.
mode
)
def
test_grad_full
(
self
):
# It is not implemented for now. So test that we raise an error.
shape
=
(
2
,
3
,
6
,
6
)
images_val
=
np
.
random
.
rand
(
*
shape
)
.
astype
(
'float32'
)
def
fn
(
images
):
return
images2neibs
(
images
,
(
3
,
3
),
mode
=
'full'
)
self
.
assertRaises
(
TypeError
,
unittest_tools
.
verify_grad
,
fn
,
[
images_val
],
mode
=
self
.
mode
)
def
test_grad_valid
(
self
):
def
test_grad_valid
(
self
):
shape
=
(
2
,
3
,
6
,
6
)
shape
=
(
2
,
3
,
6
,
6
)
images_val
=
np
.
random
.
rand
(
*
shape
)
.
astype
(
'float32'
)
images_val
=
np
.
random
.
rand
(
*
shape
)
.
astype
(
'float32'
)
...
@@ -330,15 +403,33 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -330,15 +403,33 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
images_val
=
np
.
arange
(
np
.
prod
(
shape
),
images_val
=
np
.
arange
(
np
.
prod
(
shape
),
dtype
=
'float32'
)
.
reshape
(
shape
)
dtype
=
'float32'
)
.
reshape
(
shape
)
def
fn
(
images
):
return
T
.
sum
(
T
.
sqr
(
images2neibs
(
images
,
(
2
,
2
),
mode
=
'valid'
)),
axis
=
[
0
,
1
])
f
=
theano
.
function
([
images
],
f
=
theano
.
function
([
images
],
T
.
sqr
(
images2neibs
(
images
,
(
2
,
2
),
mode
=
'valid'
)),
T
.
sqr
(
images2neibs
(
images
,
(
2
,
2
),
mode
=
'valid'
)),
mode
=
self
.
mode
)
mode
=
self
.
mode
)
self
.
assertRaises
(
TypeError
,
f
,
images_val
)
self
.
assertRaises
(
TypeError
,
f
,
images_val
)
def
test_neibs_half_with_inconsistent_borders
(
self
):
shape
=
(
2
,
3
,
5
,
5
)
images
=
T
.
dtensor4
()
images_val
=
np
.
arange
(
np
.
prod
(
shape
),
dtype
=
'float32'
)
.
reshape
(
shape
)
f
=
theano
.
function
([
images
],
T
.
sqr
(
images2neibs
(
images
,
(
2
,
2
),
mode
=
'half'
)),
mode
=
self
.
mode
)
self
.
assertRaises
(
TypeError
,
f
,
images_val
)
def
test_neibs_full_with_inconsistent_borders
(
self
):
shape
=
(
2
,
3
,
5
,
5
)
images
=
T
.
dtensor4
()
images_val
=
np
.
arange
(
np
.
prod
(
shape
),
dtype
=
'float32'
)
.
reshape
(
shape
)
f
=
theano
.
function
([
images
],
T
.
sqr
(
images2neibs
(
images
,
(
2
,
2
),
mode
=
'full'
)),
mode
=
self
.
mode
)
self
.
assertRaises
(
TypeError
,
f
,
images_val
)
def
test_can_not_infer_nb_dim
(
self
):
def
test_can_not_infer_nb_dim
(
self
):
# Was reported in gh-5613. Test that we do not crash
# Was reported in gh-5613. Test that we do not crash
# or that we crash in a few other case found while
# or that we crash in a few other case found while
...
@@ -346,7 +437,7 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -346,7 +437,7 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
img
=
T
.
tensor4
(
'img'
)
img
=
T
.
tensor4
(
'img'
)
patches
=
T
.
nnet
.
neighbours
.
images2neibs
(
img
,
[
16
,
16
])
patches
=
T
.
nnet
.
neighbours
.
images2neibs
(
img
,
[
16
,
16
])
extractPatches
=
theano
.
function
([
img
],
patches
)
extractPatches
=
theano
.
function
([
img
],
patches
,
mode
=
self
.
mode
)
patsRecovery
=
T
.
matrix
(
'patsRecovery'
)
patsRecovery
=
T
.
matrix
(
'patsRecovery'
)
original_size
=
T
.
ivector
(
'original_size'
)
original_size
=
T
.
ivector
(
'original_size'
)
...
@@ -354,7 +445,8 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -354,7 +445,8 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
for
mode
in
[
'valid'
,
'ignore_borders'
]:
for
mode
in
[
'valid'
,
'ignore_borders'
]:
out
=
neibs2images
(
patsRecovery
,
(
16
,
16
),
out
=
neibs2images
(
patsRecovery
,
(
16
,
16
),
original_size
,
mode
=
mode
)
original_size
,
mode
=
mode
)
f
=
theano
.
function
([
patsRecovery
,
original_size
],
out
)
f
=
theano
.
function
([
patsRecovery
,
original_size
],
out
,
mode
=
self
.
mode
)
im_val
=
np
.
ones
((
1
,
3
,
320
,
320
),
dtype
=
np
.
float32
)
im_val
=
np
.
ones
((
1
,
3
,
320
,
320
),
dtype
=
np
.
float32
)
neibs
=
extractPatches
(
im_val
)
neibs
=
extractPatches
(
im_val
)
...
@@ -392,6 +484,32 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -392,6 +484,32 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
for
i
in
range
(
1000
):
for
i
in
range
(
1000
):
f
()
f
()
def
speed_neibs_half
(
self
):
shape
=
(
100
,
40
,
18
,
18
)
images
=
shared
(
np
.
arange
(
np
.
prod
(
shape
),
dtype
=
'float32'
)
.
reshape
(
shape
))
neib_shape
=
T
.
as_tensor_variable
((
3
,
3
))
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
mode
=
"half"
),
mode
=
self
.
mode
)
for
i
in
range
(
1000
):
f
()
def
speed_neibs_full
(
self
):
shape
=
(
100
,
40
,
18
,
18
)
images
=
shared
(
np
.
arange
(
np
.
prod
(
shape
),
dtype
=
'float32'
)
.
reshape
(
shape
))
neib_shape
=
T
.
as_tensor_variable
((
3
,
3
))
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
mode
=
"full"
),
mode
=
self
.
mode
)
for
i
in
range
(
1000
):
f
()
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
shape
=
(
100
,
40
,
6
,
3
)
shape
=
(
100
,
40
,
6
,
3
)
images
=
np
.
ones
(
shape
)
.
astype
(
'float32'
)
images
=
np
.
ones
(
shape
)
.
astype
(
'float32'
)
...
@@ -431,6 +549,24 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -431,6 +549,24 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
[
x
],
[
images2neibs
(
[
x
],
[
images2neibs
(
x
,
neib_shape
=
(
3
,
3
),
mode
=
'wrap_centered'
)],
x
,
neib_shape
=
(
3
,
3
),
mode
=
'wrap_centered'
)],
[
images
],
Images2Neibs
)
[
images
],
Images2Neibs
)
shape
=
(
100
,
40
,
6
,
4
)
images
=
np
.
ones
(
shape
)
.
astype
(
'float32'
)
x
=
T
.
ftensor4
()
self
.
_compile_and_check
(
[
x
],
[
images2neibs
(
x
,
neib_shape
=
(
2
,
1
),
mode
=
'half'
)],
[
images
],
Images2Neibs
)
self
.
_compile_and_check
(
[
x
],
[
images2neibs
(
x
,
neib_shape
=
(
2
,
3
),
mode
=
'half'
)],
[
images
],
Images2Neibs
)
shape
=
(
100
,
40
,
6
,
5
)
images
=
np
.
ones
(
shape
)
.
astype
(
'float32'
)
x
=
T
.
ftensor4
()
self
.
_compile_and_check
(
[
x
],
[
images2neibs
(
x
,
neib_shape
=
(
2
,
1
),
mode
=
'full'
)],
[
images
],
Images2Neibs
)
self
.
_compile_and_check
(
[
x
],
[
images2neibs
(
x
,
neib_shape
=
(
2
,
3
),
mode
=
'full'
)],
[
images
],
Images2Neibs
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论