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