Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
87057fa6
提交
87057fa6
authored
4月 12, 2017
作者:
amrithasuresh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated numpy as np
上级
7d7c4baf
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
23 行增加
和
23 行删除
+23
-23
test_corr.py
theano/tensor/nnet/tests/test_corr.py
+23
-23
没有找到文件。
theano/tensor/nnet/tests/test_corr.py
浏览文件 @
87057fa6
...
...
@@ -3,7 +3,7 @@ from __future__ import absolute_import, print_function, division
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.attrib
import
attr
from
nose.tools
import
assert_equals
import
numpy
import
numpy
as
np
from
six
import
integer_types
import
theano
...
...
@@ -66,15 +66,15 @@ class TestCorr2D(utt.InferShapeTester):
theano_corr
=
theano
.
function
([
input
,
filters
],
output
,
mode
=
self
.
mode
)
# initialize input and compute result
image_data
=
n
umpy
.
random
.
random
(
N_image_shape
)
.
astype
(
self
.
dtype
)
filter_data
=
n
umpy
.
random
.
random
(
N_filter_shape
)
.
astype
(
self
.
dtype
)
image_data
=
n
p
.
random
.
random
(
N_image_shape
)
.
astype
(
self
.
dtype
)
filter_data
=
n
p
.
random
.
random
(
N_filter_shape
)
.
astype
(
self
.
dtype
)
if
non_contiguous
:
image_data
=
n
umpy
.
transpose
(
image_data
,
axes
=
(
0
,
1
,
3
,
2
))
image_data
=
n
p
.
transpose
(
image_data
,
axes
=
(
0
,
1
,
3
,
2
))
image_data
=
image_data
.
copy
()
image_data
=
n
umpy
.
transpose
(
image_data
,
axes
=
(
0
,
1
,
3
,
2
))
filter_data
=
n
umpy
.
transpose
(
filter_data
,
axes
=
(
0
,
1
,
3
,
2
))
image_data
=
n
p
.
transpose
(
image_data
,
axes
=
(
0
,
1
,
3
,
2
))
filter_data
=
n
p
.
transpose
(
filter_data
,
axes
=
(
0
,
1
,
3
,
2
))
filter_data
=
filter_data
.
copy
()
filter_data
=
n
umpy
.
transpose
(
filter_data
,
axes
=
(
0
,
1
,
3
,
2
))
filter_data
=
n
p
.
transpose
(
filter_data
,
axes
=
(
0
,
1
,
3
,
2
))
assert
not
image_data
.
flags
[
'CONTIGUOUS'
]
assert
not
filter_data
.
flags
[
'CONTIGUOUS'
]
...
...
@@ -82,36 +82,36 @@ class TestCorr2D(utt.InferShapeTester):
# REFERENCE IMPLEMENTATION
# Testing correlation, not convolution. Reverse filters.
filter_data_corr
=
n
umpy
.
array
(
filter_data
[:,
:,
::
-
1
,
::
-
1
],
filter_data_corr
=
n
p
.
array
(
filter_data
[:,
:,
::
-
1
,
::
-
1
],
copy
=
True
,
order
=
'C'
)
orig_image_data
=
image_data
img_shape2d
=
n
umpy
.
array
(
N_image_shape
[
-
2
:])
fil_shape2d
=
n
umpy
.
array
(
N_filter_shape
[
-
2
:])
dil_shape2d
=
n
umpy
.
array
(
filter_dilation
)
img_shape2d
=
n
p
.
array
(
N_image_shape
[
-
2
:])
fil_shape2d
=
n
p
.
array
(
N_filter_shape
[
-
2
:])
dil_shape2d
=
n
p
.
array
(
filter_dilation
)
dil_fil_shape2d
=
(
fil_shape2d
-
1
)
*
dil_shape2d
+
1
subsample2d
=
n
umpy
.
array
(
subsample
)
subsample2d
=
n
p
.
array
(
subsample
)
if
border_mode
==
'full'
:
padHW
=
(
dil_fil_shape2d
-
1
)
elif
border_mode
==
'valid'
:
padHW
=
n
umpy
.
array
([
0
,
0
])
padHW
=
n
p
.
array
([
0
,
0
])
elif
border_mode
==
'half'
:
padHW
=
n
umpy
.
floor
(
dil_fil_shape2d
/
2
)
.
astype
(
'int32'
)
padHW
=
n
p
.
floor
(
dil_fil_shape2d
/
2
)
.
astype
(
'int32'
)
elif
isinstance
(
border_mode
,
tuple
):
padHW
=
n
umpy
.
array
(
border_mode
)
padHW
=
n
p
.
array
(
border_mode
)
elif
isinstance
(
border_mode
,
integer_types
):
padHW
=
n
umpy
.
array
([
border_mode
,
border_mode
])
padHW
=
n
p
.
array
([
border_mode
,
border_mode
])
else
:
raise
NotImplementedError
(
'Unsupported border_mode {}'
.
format
(
border_mode
))
out_shape2d
=
n
umpy
.
floor
((
img_shape2d
+
2
*
(
padHW
)
-
dil_fil_shape2d
)
/
subsample2d
)
+
1
out_shape2d
=
n
p
.
floor
((
img_shape2d
+
2
*
(
padHW
)
-
dil_fil_shape2d
)
/
subsample2d
)
+
1
# avoid numpy deprecation
out_shape2d
=
out_shape2d
.
astype
(
'int32'
)
out_shape
=
(
N_image_shape
[
0
],
N_filter_shape
[
0
])
+
tuple
(
out_shape2d
)
ref_output
=
n
umpy
.
zeros
(
out_shape
)
ref_output
=
n
p
.
zeros
(
out_shape
)
# loop over output feature maps
ref_output
.
fill
(
0
)
image_data2
=
n
umpy
.
zeros
((
N_image_shape
[
0
],
N_image_shape
[
1
],
image_data2
=
n
p
.
zeros
((
N_image_shape
[
0
],
N_image_shape
[
1
],
N_image_shape
[
2
]
+
2
*
padHW
[
0
],
N_image_shape
[
3
]
+
2
*
padHW
[
1
]))
image_data2
[:,
:,
padHW
[
0
]:
padHW
[
0
]
+
N_image_shape
[
2
],
...
...
@@ -265,7 +265,7 @@ class TestCorr2D(utt.InferShapeTester):
Checks dtype upcast for CorrMM methods.
"""
def
rand
(
shape
,
dtype
=
'float64'
):
r
=
n
umpy
.
asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
dtype
)
r
=
n
p
.
asarray
(
np
.
random
.
rand
(
*
shape
),
dtype
=
dtype
)
return
r
*
2
-
1
if
not
theano
.
config
.
cxx
:
raise
SkipTest
(
"Need cxx to test conv2d"
)
...
...
@@ -296,7 +296,7 @@ class TestCorr2D(utt.InferShapeTester):
raise
SkipTest
(
"Need cxx for this test"
)
def
rand
(
*
shape
):
r
=
n
umpy
.
asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
'float64'
)
r
=
n
p
.
asarray
(
np
.
random
.
rand
(
*
shape
),
dtype
=
'float64'
)
return
r
*
2
-
1
corrMM
=
corr
.
CorrMM
...
...
@@ -329,7 +329,7 @@ class TestCorr2D(utt.InferShapeTester):
raise
SkipTest
(
"Need cxx for this test"
)
def
rand
(
*
shape
):
r
=
n
umpy
.
asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
'float64'
)
r
=
n
p
.
asarray
(
np
.
random
.
rand
(
*
shape
),
dtype
=
'float64'
)
return
r
*
2
-
1
corrMM
=
corr
.
CorrMM
gradW
=
corr
.
CorrMM_gradWeights
...
...
@@ -369,7 +369,7 @@ class TestCorr2D(utt.InferShapeTester):
raise
SkipTest
(
"Need cxx for this test"
)
def
rand
(
*
shape
):
r
=
n
umpy
.
asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
'float64'
)
r
=
n
p
.
asarray
(
np
.
random
.
rand
(
*
shape
),
dtype
=
'float64'
)
return
r
*
2
-
1
corrMM
=
corr
.
CorrMM
gradI
=
corr
.
CorrMM_gradInputs
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论