Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d4d3ae5b
提交
d4d3ae5b
authored
8月 04, 2015
作者:
--global
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Flake8 on test_dnn.py
上级
397394d6
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
22 行增加
和
19 行删除
+22
-19
test_dnn.py
theano/sandbox/cuda/tests/test_dnn.py
+22
-19
没有找到文件。
theano/sandbox/cuda/tests/test_dnn.py
浏览文件 @
d4d3ae5b
...
@@ -477,7 +477,7 @@ def test_log_softmax():
...
@@ -477,7 +477,7 @@ def test_log_softmax():
(
66000
,
2
,
3
,
4
),
(
66000
,
2
,
3
,
4
),
(
2
,
66000
,
3
,
4
),
(
2
,
66000
,
3
,
4
),
(
2
,
3
,
66000
,
4
),
(
2
,
3
,
66000
,
4
),
(
2
,
3
,
4
,
66000
)
,
]
(
2
,
3
,
4
,
66000
)]
for
inp_shape
in
input_shapes
:
for
inp_shape
in
input_shapes
:
input_val
=
numpy
.
random
.
normal
(
0
,
1
,
inp_shape
)
.
astype
(
"float32"
)
input_val
=
numpy
.
random
.
normal
(
0
,
1
,
inp_shape
)
.
astype
(
"float32"
)
...
@@ -1060,7 +1060,7 @@ def test_dnn_conv_grad():
...
@@ -1060,7 +1060,7 @@ def test_dnn_conv_grad():
def
get_conv3d_test_cases
():
def
get_conv3d_test_cases
():
# Every element of test_shapes follows the format
# Every element of test_shapes follows the format
# [input_shape, filter_shape, subsample]
# [input_shape, filter_shape, subsample]
test_shapes
=
[
# Test with standard size inputs and kernels
test_shapes
=
[
# Test with standard size inputs and kernels
[(
128
,
3
,
5
,
5
,
5
),
(
64
,
3
,
1
,
2
,
4
),
(
1
,
1
,
1
)],
[(
128
,
3
,
5
,
5
,
5
),
(
64
,
3
,
1
,
2
,
4
),
(
1
,
1
,
1
)],
[(
8
,
4
,
20
,
12
,
15
),
(
5
,
4
,
6
,
12
,
4
),
(
2
,
2
,
2
)],
[(
8
,
4
,
20
,
12
,
15
),
(
5
,
4
,
6
,
12
,
4
),
(
2
,
2
,
2
)],
[(
8
,
1
,
20
,
12
,
15
),
(
5
,
1
,
6
,
12
,
4
),
(
3
,
3
,
3
)],
[(
8
,
1
,
20
,
12
,
15
),
(
5
,
1
,
6
,
12
,
4
),
(
3
,
3
,
3
)],
...
@@ -1083,8 +1083,7 @@ def get_conv3d_test_cases():
...
@@ -1083,8 +1083,7 @@ def get_conv3d_test_cases():
test_shapes_full
=
[[(
6
,
2
,
2
,
2
,
2
),
(
4
,
2
,
3
,
1
,
1
),
(
1
,
1
,
1
)],
test_shapes_full
=
[[(
6
,
2
,
2
,
2
,
2
),
(
4
,
2
,
3
,
1
,
1
),
(
1
,
1
,
1
)],
[(
6
,
2
,
2
,
2
,
2
),
(
4
,
2
,
1
,
3
,
1
),
(
1
,
1
,
1
)],
[(
6
,
2
,
2
,
2
,
2
),
(
4
,
2
,
1
,
3
,
1
),
(
1
,
1
,
1
)],
[(
6
,
2
,
2
,
2
,
2
),
(
4
,
2
,
1
,
1
,
3
),
(
1
,
1
,
1
)],
[(
6
,
2
,
2
,
2
,
2
),
(
4
,
2
,
1
,
1
,
3
),
(
1
,
1
,
1
)],
[(
6
,
2
,
2
,
2
,
2
),
(
4
,
2
,
5
,
5
,
5
),
(
1
,
1
,
1
)],
[(
6
,
2
,
2
,
2
,
2
),
(
4
,
2
,
5
,
5
,
5
),
(
1
,
1
,
1
)]]
]
border_modes
=
[
'valid'
,
'full'
,
(
1
,
2
,
3
),
(
3
,
2
,
1
),
1
,
2
]
border_modes
=
[
'valid'
,
'full'
,
(
1
,
2
,
3
),
(
3
,
2
,
1
),
1
,
2
]
conv_modes
=
[
'conv'
,
'cross'
]
conv_modes
=
[
'conv'
,
'cross'
]
...
@@ -1130,7 +1129,7 @@ def test_conv3d_fwd():
...
@@ -1130,7 +1129,7 @@ def test_conv3d_fwd():
# If conv_mode is 'conv' the reference implementation should use
# If conv_mode is 'conv' the reference implementation should use
# filters filpped according to the width, height and time axis
# filters filpped according to the width, height and time axis
if
conv_mode
==
'conv'
:
if
conv_mode
==
'conv'
:
flipped_filters
=
filters
[:,
:,::
-
1
,::
-
1
,
::
-
1
]
flipped_filters
=
filters
[:,
:,
::
-
1
,
::
-
1
,
::
-
1
]
else
:
else
:
flipped_filters
=
filters
flipped_filters
=
filters
...
@@ -1140,7 +1139,7 @@ def test_conv3d_fwd():
...
@@ -1140,7 +1139,7 @@ def test_conv3d_fwd():
padded_inputs
=
inputs
padded_inputs
=
inputs
else
:
else
:
if
border_mode
==
'full'
:
if
border_mode
==
'full'
:
pad_per_dim
=
[
filters_shape
[
i
]
-
1
for
i
in
range
(
2
,
5
)]
pad_per_dim
=
[
filters_shape
[
i
]
-
1
for
i
in
range
(
2
,
5
)]
else
:
else
:
if
isinstance
(
border_mode
,
int
):
if
isinstance
(
border_mode
,
int
):
pad_per_dim
=
[
border_mode
]
*
3
pad_per_dim
=
[
border_mode
]
*
3
...
@@ -1154,9 +1153,10 @@ def test_conv3d_fwd():
...
@@ -1154,9 +1153,10 @@ def test_conv3d_fwd():
padded_inputs
=
shared
(
padded_inputs_val
)
padded_inputs
=
shared
(
padded_inputs_val
)
# Compile a theano function for the reference implementation
# Compile a theano function for the reference implementation
conv_ref
=
theano
.
tensor
.
nnet
.
conv3D
(
V
=
padded_inputs
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
),
conv_ref
=
theano
.
tensor
.
nnet
.
conv3D
(
W
=
flipped_filters
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
),
V
=
padded_inputs
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
),
b
=
bias
,
d
=
subsample
)
W
=
flipped_filters
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
),
b
=
bias
,
d
=
subsample
)
f_ref
=
theano
.
function
([],
conv_ref
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
f_ref
=
theano
.
function
([],
conv_ref
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
# Compare the results of the two implementations
# Compare the results of the two implementations
...
@@ -1197,7 +1197,7 @@ def test_conv3d_bwd():
...
@@ -1197,7 +1197,7 @@ def test_conv3d_bwd():
# If conv_mode is 'conv' the reference implementation should use
# If conv_mode is 'conv' the reference implementation should use
# filters filpped according to the width, height and time axis
# filters filpped according to the width, height and time axis
if
conv_mode
==
'conv'
:
if
conv_mode
==
'conv'
:
flipped_filters
=
filters
[:,
:,::
-
1
,::
-
1
,
::
-
1
]
flipped_filters
=
filters
[:,
:,
::
-
1
,
::
-
1
,
::
-
1
]
else
:
else
:
flipped_filters
=
filters
flipped_filters
=
filters
...
@@ -1207,7 +1207,7 @@ def test_conv3d_bwd():
...
@@ -1207,7 +1207,7 @@ def test_conv3d_bwd():
padded_inputs
=
inputs
padded_inputs
=
inputs
else
:
else
:
if
border_mode
==
'full'
:
if
border_mode
==
'full'
:
pad_per_dim
=
[
filters_shape
[
i
]
-
1
for
i
in
range
(
2
,
5
)]
pad_per_dim
=
[
filters_shape
[
i
]
-
1
for
i
in
range
(
2
,
5
)]
else
:
else
:
if
isinstance
(
border_mode
,
int
):
if
isinstance
(
border_mode
,
int
):
pad_per_dim
=
[
border_mode
]
*
3
pad_per_dim
=
[
border_mode
]
*
3
...
@@ -1221,21 +1221,24 @@ def test_conv3d_bwd():
...
@@ -1221,21 +1221,24 @@ def test_conv3d_bwd():
padded_inputs
=
shared
(
padded_inputs_val
)
padded_inputs
=
shared
(
padded_inputs_val
)
# Compile a theano function for the reference implementation
# Compile a theano function for the reference implementation
conv_ref
=
theano
.
tensor
.
nnet
.
conv3D
(
V
=
padded_inputs
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
),
conv_ref
=
theano
.
tensor
.
nnet
.
conv3D
(
W
=
flipped_filters
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
),
V
=
padded_inputs
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
),
b
=
bias
,
d
=
subsample
)
W
=
flipped_filters
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
),
b
=
bias
,
d
=
subsample
)
(
grad_padded_i_ref
,
(
grad_padded_i_ref
,
grad_w_ref
)
=
theano
.
tensor
.
grad
(
conv_ref
.
sum
(),
[
padded_inputs
,
filters
])
grad_w_ref
)
=
theano
.
tensor
.
grad
(
conv_ref
.
sum
(),
[
padded_inputs
,
filters
])
# Recover grad_i_ref from grad_padded_i_ref
# Recover grad_i_ref from grad_padded_i_ref
if
border_mode
==
'valid'
:
if
border_mode
==
'valid'
:
grad_i_ref
=
grad_padded_i_ref
grad_i_ref
=
grad_padded_i_ref
else
:
else
:
shp
=
grad_padded_i_ref
.
shape
shp
=
grad_padded_i_ref
.
shape
grad_i_ref
=
grad_padded_i_ref
[:,
:,
grad_i_ref
=
grad_padded_i_ref
[
pad_per_dim
[
0
]:
shp
[
2
]
-
pad_per_dim
[
0
],
:,
:,
pad_per_dim
[
1
]:
shp
[
3
]
-
pad_per_dim
[
1
],
pad_per_dim
[
0
]:
shp
[
2
]
-
pad_per_dim
[
0
],
pad_per_dim
[
2
]:
shp
[
4
]
-
pad_per_dim
[
2
]]
pad_per_dim
[
1
]:
shp
[
3
]
-
pad_per_dim
[
1
],
pad_per_dim
[
2
]:
shp
[
4
]
-
pad_per_dim
[
2
]]
f_ref
=
theano
.
function
([],
[
grad_i_ref
,
grad_w_ref
])
f_ref
=
theano
.
function
([],
[
grad_i_ref
,
grad_w_ref
])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论