Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cf81ce7f
提交
cf81ce7f
authored
4月 12, 2017
作者:
amrithasuresh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Updated numpy as np
上级
e79c4e4c
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
34 行增加
和
35 行删除
+34
-35
test_abstract_conv.py
theano/tensor/nnet/tests/test_abstract_conv.py
+34
-35
没有找到文件。
theano/tensor/nnet/tests/test_abstract_conv.py
浏览文件 @
cf81ce7f
from
__future__
import
absolute_import
,
print_function
,
division
import
unittest
import
numpy
import
numpy
as
np
from
nose.plugins.skip
import
SkipTest
from
nose.tools
import
assert_raises
,
assert_true
...
...
@@ -238,8 +237,8 @@ class TestAssertShape(unittest.TestCase):
expected_shape
=
[
None
,
s1
,
s2
,
None
]
f
=
theano
.
function
([
x
,
s1
,
s2
],
assert_shape
(
x
,
expected_shape
))
v
=
n
umpy
.
zeros
((
3
,
5
,
7
,
11
),
dtype
=
'float32'
)
self
.
assertEqual
(
0
,
n
umpy
.
sum
(
f
(
v
,
5
,
7
)))
v
=
n
p
.
zeros
((
3
,
5
,
7
,
11
),
dtype
=
'float32'
)
self
.
assertEqual
(
0
,
n
p
.
sum
(
f
(
v
,
5
,
7
)))
assert_raises
(
AssertionError
,
f
,
v
,
5
,
0
)
assert_raises
(
AssertionError
,
f
,
v
,
5
,
9
)
...
...
@@ -257,12 +256,12 @@ class TestAssertShape(unittest.TestCase):
f
=
theano
.
function
([
input
,
filters
],
out
)
# mismatched input_shape
assert_raises
(
AssertionError
,
f
,
n
umpy
.
zeros
((
3
,
5
,
9
,
11
),
dtype
=
'float32'
),
n
umpy
.
zeros
((
7
,
5
,
3
,
3
),
dtype
=
'float32'
))
n
p
.
zeros
((
3
,
5
,
9
,
11
),
dtype
=
'float32'
),
n
p
.
zeros
((
7
,
5
,
3
,
3
),
dtype
=
'float32'
))
# mismatched filter_shape
assert_raises
(
AssertionError
,
f
,
n
umpy
.
zeros
((
3
,
5
,
7
,
11
),
dtype
=
'float32'
),
n
umpy
.
zeros
((
7
,
5
,
2
,
2
),
dtype
=
'float32'
))
n
p
.
zeros
((
3
,
5
,
7
,
11
),
dtype
=
'float32'
),
n
p
.
zeros
((
7
,
5
,
2
,
2
),
dtype
=
'float32'
))
@change_flags
([(
"conv.assert_shape"
,
True
)])
def
test_shape_check_conv3d
(
self
):
...
...
@@ -275,12 +274,12 @@ class TestAssertShape(unittest.TestCase):
f
=
theano
.
function
([
input
,
filters
],
out
)
# mismatched input_shape
assert_raises
(
AssertionError
,
f
,
n
umpy
.
zeros
((
3
,
5
,
9
,
11
,
13
),
dtype
=
'float32'
),
n
umpy
.
zeros
((
7
,
5
,
3
,
3
,
3
),
dtype
=
'float32'
))
n
p
.
zeros
((
3
,
5
,
9
,
11
,
13
),
dtype
=
'float32'
),
n
p
.
zeros
((
7
,
5
,
3
,
3
,
3
),
dtype
=
'float32'
))
# mismatched filter_shape
assert_raises
(
AssertionError
,
f
,
n
umpy
.
zeros
((
3
,
5
,
7
,
11
,
13
),
dtype
=
'float32'
),
n
umpy
.
zeros
((
7
,
5
,
2
,
2
,
2
),
dtype
=
'float32'
))
n
p
.
zeros
((
3
,
5
,
7
,
11
,
13
),
dtype
=
'float32'
),
n
p
.
zeros
((
7
,
5
,
2
,
2
,
2
),
dtype
=
'float32'
))
@change_flags
([(
"conv.assert_shape"
,
True
)])
def
test_shape_check_conv2d_grad_wrt_inputs
(
self
):
...
...
@@ -293,8 +292,8 @@ class TestAssertShape(unittest.TestCase):
f
=
theano
.
function
([
output_grad
,
filters
],
out
)
# mismatched filter_shape
assert_raises
(
AssertionError
,
f
,
n
umpy
.
zeros
((
3
,
6
,
5
,
9
),
dtype
=
'float32'
),
n
umpy
.
zeros
((
7
,
6
,
3
,
3
),
dtype
=
'float32'
))
n
p
.
zeros
((
3
,
6
,
5
,
9
),
dtype
=
'float32'
),
n
p
.
zeros
((
7
,
6
,
3
,
3
),
dtype
=
'float32'
))
@change_flags
([(
"conv.assert_shape"
,
True
)])
def
test_shape_check_conv3d_grad_wrt_inputs
(
self
):
...
...
@@ -307,8 +306,8 @@ class TestAssertShape(unittest.TestCase):
f
=
theano
.
function
([
output_grad
,
filters
],
out
)
# mismatched filter_shape
assert_raises
(
AssertionError
,
f
,
n
umpy
.
zeros
((
3
,
6
,
5
,
9
,
11
),
dtype
=
'float32'
),
n
umpy
.
zeros
((
7
,
6
,
3
,
3
,
3
),
dtype
=
'float32'
))
n
p
.
zeros
((
3
,
6
,
5
,
9
,
11
),
dtype
=
'float32'
),
n
p
.
zeros
((
7
,
6
,
3
,
3
,
3
),
dtype
=
'float32'
))
@change_flags
([(
"conv.assert_shape"
,
True
)])
def
test_shape_check_conv2d_grad_wrt_weights
(
self
):
...
...
@@ -321,8 +320,8 @@ class TestAssertShape(unittest.TestCase):
f
=
theano
.
function
([
input
,
output_grad
],
out
)
# mismatched filter_shape
assert_raises
(
AssertionError
,
f
,
n
umpy
.
zeros
((
3
,
6
,
7
,
11
),
dtype
=
'float32'
),
n
umpy
.
zeros
((
3
,
7
,
5
,
9
),
dtype
=
'float32'
))
n
p
.
zeros
((
3
,
6
,
7
,
11
),
dtype
=
'float32'
),
n
p
.
zeros
((
3
,
7
,
5
,
9
),
dtype
=
'float32'
))
@change_flags
([(
"conv.assert_shape"
,
True
)])
def
test_shape_check_conv3d_grad_wrt_weights
(
self
):
...
...
@@ -335,8 +334,8 @@ class TestAssertShape(unittest.TestCase):
f
=
theano
.
function
([
input
,
output_grad
],
out
)
# mismatched filter_shape
assert_raises
(
AssertionError
,
f
,
n
umpy
.
zeros
((
3
,
6
,
7
,
11
,
13
),
dtype
=
'float32'
),
n
umpy
.
zeros
((
3
,
7
,
5
,
9
,
11
),
dtype
=
'float32'
))
n
p
.
zeros
((
3
,
6
,
7
,
11
,
13
),
dtype
=
'float32'
),
n
p
.
zeros
((
3
,
7
,
5
,
9
,
11
),
dtype
=
'float32'
))
class
BaseTestConv
(
object
):
...
...
@@ -371,8 +370,8 @@ class BaseTestConv(object):
if
filter_dilation
is
None
:
filter_dilation
=
(
1
,)
*
(
len
(
inputs_shape
)
-
2
)
inputs_val
=
n
umpy
.
random
.
random
(
inputs_shape
)
.
astype
(
'float32'
)
filters_val
=
n
umpy
.
random
.
random
(
filters_shape
)
.
astype
(
'float32'
)
inputs_val
=
n
p
.
random
.
random
(
inputs_shape
)
.
astype
(
'float32'
)
filters_val
=
n
p
.
random
.
random
(
filters_shape
)
.
astype
(
'float32'
)
# scale down values to prevent rounding errors
inputs_val
/=
10
...
...
@@ -414,8 +413,8 @@ class BaseTestConv(object):
if
check_trace
:
assert_true
(
check_stack_trace
(
f
,
ops_to_check
=
target_op
))
res_ref
=
n
umpy
.
array
(
f_ref
())
res
=
n
umpy
.
array
(
f
())
res_ref
=
n
p
.
array
(
f_ref
())
res
=
n
p
.
array
(
f
())
utt
.
assert_allclose
(
res_ref
,
res
)
if
verify_grad
and
inputs_val
.
size
>
0
and
filters_val
.
size
>
0
and
res
.
size
>
0
:
utt
.
verify_grad
(
conv_op
(
border_mode
=
border_mode
,
...
...
@@ -436,8 +435,8 @@ class BaseTestConv(object):
if
filter_dilation
is
None
:
filter_dilation
=
(
1
,)
*
(
len
(
inputs_shape
)
-
2
)
inputs_val
=
n
umpy
.
random
.
random
(
inputs_shape
)
.
astype
(
'float32'
)
output_val
=
n
umpy
.
random
.
random
(
output_shape
)
.
astype
(
'float32'
)
inputs_val
=
n
p
.
random
.
random
(
inputs_shape
)
.
astype
(
'float32'
)
output_val
=
n
p
.
random
.
random
(
output_shape
)
.
astype
(
'float32'
)
inputs
=
self
.
shared
(
inputs_val
)
output
=
self
.
shared
(
output_val
)
...
...
@@ -473,8 +472,8 @@ class BaseTestConv(object):
if
check_trace
:
assert_true
(
check_stack_trace
(
f
,
ops_to_check
=
target_op
))
res_ref
=
n
umpy
.
array
(
f_ref
())
res
=
n
umpy
.
array
(
f
())
res_ref
=
n
p
.
array
(
f_ref
())
res
=
n
p
.
array
(
f
())
utt
.
assert_allclose
(
res_ref
,
res
)
def
abstract_conv_gradweight
(
inputs_val
,
output_val
):
...
...
@@ -499,8 +498,8 @@ class BaseTestConv(object):
if
filter_dilation
is
None
:
filter_dilation
=
(
1
,)
*
(
len
(
inputs_shape
)
-
2
)
output_val
=
n
umpy
.
random
.
random
(
output_shape
)
.
astype
(
'float32'
)
filters_val
=
n
umpy
.
random
.
random
(
filters_shape
)
.
astype
(
'float32'
)
output_val
=
n
p
.
random
.
random
(
output_shape
)
.
astype
(
'float32'
)
filters_val
=
n
p
.
random
.
random
(
filters_shape
)
.
astype
(
'float32'
)
output
=
self
.
shared
(
output_val
)
filters
=
self
.
shared
(
filters_val
)
...
...
@@ -537,10 +536,10 @@ class BaseTestConv(object):
if
check_trace
:
assert_true
(
check_stack_trace
(
f
,
ops_to_check
=
target_op
))
res
=
n
umpy
.
array
(
f
())
res
=
n
p
.
array
(
f
())
if
ref
is
not
None
:
res_ref
=
n
umpy
.
array
(
f_ref
())
res_ref
=
n
p
.
array
(
f_ref
())
utt
.
assert_allclose
(
res_ref
,
res
)
def
abstract_conv_gradinputs
(
filters_val
,
output_val
):
...
...
@@ -1272,7 +1271,7 @@ class TestConvTypes(unittest.TestCase):
self
.
filters
=
tensor
.
ftensor4
()
self
.
topgrad
=
tensor
.
ftensor4
()
self
.
constant_tensor
=
n
umpy
.
zeros
((
3
,
5
,
7
,
11
),
dtype
=
'float32'
)
self
.
constant_tensor
=
n
p
.
zeros
((
3
,
5
,
7
,
11
),
dtype
=
'float32'
)
def
test_grad_types
(
self
):
# This function simply tests the behaviour of the AbstractConv
...
...
@@ -1582,7 +1581,7 @@ class TestConv2dTranspose(unittest.TestCase):
output_shape
=
(
2
,
1
,
10
,
10
),
input_dilation
=
(
2
,
2
)),
mode
=
mode
)()
expected_output
=
n
umpy
.
array
(
expected_output
=
n
p
.
array
(
[[[[
2
,
2
,
4
,
4
,
4
,
4
,
4
,
4
,
2
,
2
],
[
2
,
2
,
4
,
4
,
4
,
4
,
4
,
4
,
2
,
2
],
[
4
,
4
,
8
,
8
,
8
,
8
,
8
,
8
,
4
,
4
],
...
...
@@ -1593,7 +1592,7 @@ class TestConv2dTranspose(unittest.TestCase):
[
4
,
4
,
8
,
8
,
8
,
8
,
8
,
8
,
4
,
4
],
[
2
,
2
,
4
,
4
,
4
,
4
,
4
,
4
,
2
,
2
],
[
2
,
2
,
4
,
4
,
4
,
4
,
4
,
4
,
2
,
2
]]]]
*
2
)
n
umpy
.
testing
.
assert_equal
(
output
,
expected_output
)
n
p
.
testing
.
assert_equal
(
output
,
expected_output
)
class
TestConv2dGrads
(
unittest
.
TestCase
):
...
...
@@ -1604,7 +1603,7 @@ class TestConv2dGrads(unittest.TestCase):
theano
.
config
.
mode
==
"FAST_COMPILE"
):
raise
SkipTest
(
"Need blas to test conv2d"
)
self
.
random_stream
=
n
umpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
self
.
random_stream
=
n
p
.
random
.
RandomState
(
utt
.
fetch_seed
())
self
.
inputs_shapes
=
[(
8
,
1
,
12
,
12
),
(
1
,
1
,
5
,
5
),
(
1
,
1
,
5
,
6
),
(
1
,
1
,
6
,
6
)]
self
.
filters_shapes
=
[(
5
,
1
,
2
,
2
),
(
1
,
1
,
3
,
3
)]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论