Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9da3e43d
提交
9da3e43d
authored
2月 23, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pep8
上级
5b150c63
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
32 行增加
和
26 行删除
+32
-26
test_conv.py
theano/tensor/signal/tests/test_conv.py
+32
-26
没有找到文件。
theano/tensor/signal/tests/test_conv.py
浏览文件 @
9da3e43d
import
sys
,
time
,
unittest
import
unittest
import
numpy
import
theano
import
theano.tensor
as
T
from
theano
import
function
,
Mode
from
theano.tests
import
unittest_tools
as
utt
from
theano.tensor.signal
import
conv
from
theano.tensor.basic
import
_allclose
class
TestSignalConv2D
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
@@ -19,13 +20,15 @@ class TestSignalConv2D(unittest.TestCase):
image_dim
=
len
(
image_shape
)
filter_dim
=
len
(
filter_shape
)
input
=
T
.
TensorType
(
'float64'
,
[
False
]
*
image_dim
)()
filters
=
T
.
TensorType
(
'float64'
,
[
False
]
*
filter_dim
)()
input
=
T
.
TensorType
(
'float64'
,
[
False
]
*
image_dim
)()
filters
=
T
.
TensorType
(
'float64'
,
[
False
]
*
filter_dim
)()
bsize
=
image_shape
[
0
]
if
image_dim
!=
3
:
bsize
=
1
if
image_dim
!=
3
:
bsize
=
1
nkern
=
filter_shape
[
0
]
if
filter_dim
!=
3
:
nkern
=
1
if
filter_dim
!=
3
:
nkern
=
1
############# THEANO IMPLEMENTATION ############
# we create a symbolic function so that verify_grad can work
...
...
@@ -35,7 +38,7 @@ class TestSignalConv2D(unittest.TestCase):
theano_conv
=
theano
.
function
([
input
,
filters
],
output
)
# initialize input and compute result
image_data
=
numpy
.
random
.
random
(
image_shape
)
image_data
=
numpy
.
random
.
random
(
image_shape
)
filter_data
=
numpy
.
random
.
random
(
filter_shape
)
theano_output
=
theano_conv
(
image_data
,
filter_data
)
...
...
@@ -45,10 +48,11 @@ class TestSignalConv2D(unittest.TestCase):
ref_output
=
numpy
.
zeros
(
tuple
(
out_shape2d
))
# reshape as 3D input tensors to make life easier
image_data3d
=
image_data
.
reshape
((
bsize
,)
+
image_shape
[
-
2
:])
filter_data3d
=
filter_data
.
reshape
((
nkern
,)
+
filter_shape
[
-
2
:])
image_data3d
=
image_data
.
reshape
((
bsize
,)
+
image_shape
[
-
2
:])
filter_data3d
=
filter_data
.
reshape
((
nkern
,)
+
filter_shape
[
-
2
:])
# reshape theano output as 4D to make life easier
theano_output4d
=
theano_output
.
reshape
((
bsize
,
nkern
,)
+
theano_output
.
shape
[
-
2
:])
theano_output4d
=
theano_output
.
reshape
((
bsize
,
nkern
,)
+
theano_output
.
shape
[
-
2
:])
# loop over mini-batches (if required)
for
b
in
range
(
bsize
):
...
...
@@ -56,17 +60,19 @@ class TestSignalConv2D(unittest.TestCase):
# loop over filters (if required)
for
k
in
range
(
nkern
):
image2d
=
image_data3d
[
b
,
:,
:]
filter2d
=
filter_data3d
[
k
,
:,
:]
image2d
=
image_data3d
[
b
,
:,
:]
filter2d
=
filter_data3d
[
k
,
:,
:]
output2d
=
numpy
.
zeros
(
ref_output
.
shape
)
for
row
in
range
(
ref_output
.
shape
[
0
]):
for
col
in
range
(
ref_output
.
shape
[
1
]):
output2d
[
row
,
col
]
+=
(
image2d
[
row
:
row
+
filter2d
.
shape
[
0
],
col
:
col
+
filter2d
.
shape
[
1
]]
*
filter2d
[::
-
1
,::
-
1
]
)
.
sum
()
output2d
[
row
,
col
]
+=
(
image2d
[
row
:
row
+
filter2d
.
shape
[
0
],
col
:
col
+
filter2d
.
shape
[
1
]]
*
filter2d
[::
-
1
,
::
-
1
]
)
.
sum
()
self
.
assertTrue
(
_allclose
(
theano_output4d
[
b
,
k
,:,:],
output2d
))
self
.
assertTrue
(
_allclose
(
theano_output4d
[
b
,
k
,
:,
:],
output2d
))
############# TEST GRADIENT ############
if
verify_grad
:
...
...
@@ -74,14 +80,15 @@ class TestSignalConv2D(unittest.TestCase):
def
test_basic
(
self
):
"""
Basic functionality of nnet.conv.ConvOp is already tested by its own test suite. We
just have to test whether or not signal.conv.conv2d can support inputs and filters of
type matrix or tensor3.
Basic functionality of nnet.conv.ConvOp is already tested by
its own test suite. We just have to test whether or not
signal.conv.conv2d can support inputs and filters of type
matrix or tensor3.
"""
self
.
validate
((
1
,
4
,
5
),
(
2
,
2
,
3
),
verify_grad
=
True
)
self
.
validate
((
7
,
5
),
(
5
,
2
,
3
),
verify_grad
=
False
)
self
.
validate
((
3
,
7
,
5
),
(
2
,
3
),
verify_grad
=
False
)
self
.
validate
((
7
,
5
),
(
2
,
3
),
verify_grad
=
False
)
self
.
validate
((
1
,
4
,
5
),
(
2
,
2
,
3
),
verify_grad
=
True
)
self
.
validate
((
7
,
5
),
(
5
,
2
,
3
),
verify_grad
=
False
)
self
.
validate
((
3
,
7
,
5
),
(
2
,
3
),
verify_grad
=
False
)
self
.
validate
((
7
,
5
),
(
2
,
3
),
verify_grad
=
False
)
def
test_fail
(
self
):
"""
...
...
@@ -98,5 +105,4 @@ class TestSignalConv2D(unittest.TestCase):
"""
m1
=
theano
.
tensor
.
matrix
()
m2
=
theano
.
tensor
.
matrix
()
rval
=
conv
.
conv2d
(
m1
,
m2
)
conv
.
conv2d
(
m1
,
m2
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论