Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
853cf7e6
提交
853cf7e6
authored
9月 24, 2016
作者:
Frédéric Bastien
提交者:
GitHub
9月 24, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4850 from gvtulder/f-conv3d2d-half
Half 3D convolution for conv3d2d
上级
aecbbb99
a87d8540
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
63 行增加
和
76 行删除
+63
-76
conv3d2d.py
theano/tensor/nnet/conv3d2d.py
+39
-65
test_conv3d2d.py
theano/tensor/nnet/tests/test_conv3d2d.py
+24
-11
没有找到文件。
theano/tensor/nnet/conv3d2d.py
浏览文件 @
853cf7e6
...
@@ -190,7 +190,7 @@ def conv3d(signals, filters,
...
@@ -190,7 +190,7 @@ def conv3d(signals, filters,
filters_shape
filters_shape
None or a tuple/list with the shape of filters.
None or a tuple/list with the shape of filters.
border_mode
border_mode
The only one tested is 'valid
'.
One of 'valid', 'full' or 'half
'.
Notes
Notes
-----
-----
...
@@ -221,18 +221,11 @@ def conv3d(signals, filters,
...
@@ -221,18 +221,11 @@ def conv3d(signals, filters,
else
:
else
:
_filters_shape_5d
=
filters_shape
_filters_shape_5d
=
filters_shape
_signals_shape_4d
=
(
Ns
,
Ts
,
C
,
Hs
,
Ws
=
_signals_shape_5d
_signals_shape_5d
[
0
]
*
_signals_shape_5d
[
1
],
Nf
,
Tf
,
C
,
Hf
,
Wf
=
_filters_shape_5d
_signals_shape_5d
[
2
],
_signals_shape_5d
[
3
],
_signals_shape_4d
=
(
Ns
*
Ts
,
C
,
Hs
,
Ws
)
_signals_shape_5d
[
4
],
_filters_shape_4d
=
(
Nf
*
Tf
,
C
,
Hf
,
Wf
)
)
_filters_shape_4d
=
(
_filters_shape_5d
[
0
]
*
_filters_shape_5d
[
1
],
_filters_shape_5d
[
2
],
_filters_shape_5d
[
3
],
_filters_shape_5d
[
4
],
)
if
border_mode
[
1
]
!=
border_mode
[
2
]:
if
border_mode
[
1
]
!=
border_mode
[
2
]:
raise
NotImplementedError
(
'height and width bordermodes must match'
)
raise
NotImplementedError
(
'height and width bordermodes must match'
)
...
@@ -250,73 +243,54 @@ def conv3d(signals, filters,
...
@@ -250,73 +243,54 @@ def conv3d(signals, filters,
filter_shape
=
conv2d_filter_shape
,
filter_shape
=
conv2d_filter_shape
,
border_mode
=
border_mode
[
1
])
# ignoring border_mode[2]
border_mode
=
border_mode
[
1
])
# ignoring border_mode[2]
# reshape the output to restore its original size
# compute the intended output size
# shape = Ns, Ts, Nf, Tf, W-Wf+1, H-Hf+1
if
border_mode
[
1
]
==
'valid'
:
if
border_mode
[
1
]
==
'valid'
:
out_tmp
=
out_4d
.
reshape
((
Hout
=
Hs
-
Hf
+
1
_signals_shape_5d
[
0
],
# Ns
Wout
=
Ws
-
Wf
+
1
_signals_shape_5d
[
1
],
# Ts
_filters_shape_5d
[
0
],
# Nf
_filters_shape_5d
[
1
],
# Tf
_signals_shape_5d
[
3
]
-
_filters_shape_5d
[
3
]
+
1
,
_signals_shape_5d
[
4
]
-
_filters_shape_5d
[
4
]
+
1
,
))
elif
border_mode
[
1
]
==
'full'
:
elif
border_mode
[
1
]
==
'full'
:
out_tmp
=
out_4d
.
reshape
((
Hout
=
Hs
+
Hf
-
1
_signals_shape_5d
[
0
],
# Ns
Wout
=
Ws
+
Wf
-
1
_signals_shape_5d
[
1
],
# Ts
elif
border_mode
[
1
]
==
'half'
:
_filters_shape_5d
[
0
],
# Nf
Hout
=
Hs
-
(
Hf
%
2
)
+
1
_filters_shape_5d
[
1
],
# Tf
Wout
=
Ws
-
(
Wf
%
2
)
+
1
_signals_shape_5d
[
3
]
+
_filters_shape_5d
[
3
]
-
1
,
_signals_shape_5d
[
4
]
+
_filters_shape_5d
[
4
]
-
1
,
))
elif
border_mode
[
1
]
==
'same'
:
elif
border_mode
[
1
]
==
'same'
:
raise
NotImplementedError
()
raise
NotImplementedError
()
else
:
else
:
raise
ValueError
(
'invalid border mode'
,
border_mode
[
1
])
raise
ValueError
(
'invalid border mode'
,
border_mode
[
1
])
# reshape the temporary output to restore its original size
out_tmp
=
out_4d
.
reshape
((
Ns
,
Ts
,
Nf
,
Tf
,
Hout
,
Wout
))
# now sum out along the Tf to get the output
# now sum out along the Tf to get the output
# but we have to sum on a diagonal through the Tf and Ts submatrix.
# but we have to sum on a diagonal through the Tf and Ts submatrix.
if
border_mode
[
0
]
==
'valid'
:
if
Tf
==
1
:
if
_filters_shape_5d
[
1
]
!=
1
:
# for Tf==1, no sum along Tf, the Ts-axis of the output is unchanged!
out_5d
=
out_tmp
.
reshape
((
Ns
,
Ts
,
Nf
,
Hout
,
Wout
))
else
:
# for some types of convolution, pad out_tmp with zeros
if
border_mode
[
0
]
==
'valid'
:
Tpad
=
0
elif
border_mode
[
0
]
==
'full'
:
Tpad
=
Tf
-
1
elif
border_mode
[
0
]
==
'half'
:
Tpad
=
Tf
//
2
elif
border_mode
[
0
]
==
'same'
:
raise
NotImplementedError
()
else
:
raise
ValueError
(
'invalid border mode'
,
border_mode
[
0
])
if
Tpad
==
0
:
out_5d
=
diagonal_subtensor
(
out_tmp
,
1
,
3
)
.
sum
(
axis
=
3
)
out_5d
=
diagonal_subtensor
(
out_tmp
,
1
,
3
)
.
sum
(
axis
=
3
)
else
:
# for Tf==1, no sum along Tf, the Ts-axis of the output is unchanged!
else
:
out_5d
=
out_tmp
.
reshape
((
# pad out_tmp with zeros before summing over the diagonal
_signals_shape_5d
[
0
],
_signals_shape_5d
[
1
],
_filters_shape_5d
[
0
],
_signals_shape_5d
[
3
]
-
_filters_shape_5d
[
3
]
+
1
,
_signals_shape_5d
[
4
]
-
_filters_shape_5d
[
4
]
+
1
,
))
elif
border_mode
[
0
]
==
'full'
:
if
_filters_shape_5d
[
1
]
!=
1
:
# pad out_tmp with zeros to have full convolution
out_tmp_padded
=
tensor
.
zeros
(
dtype
=
out_tmp
.
dtype
,
shape
=
(
out_tmp_padded
=
tensor
.
zeros
(
dtype
=
out_tmp
.
dtype
,
shape
=
(
_signals_shape_5d
[
0
],
# Ns
Ns
,
Ts
+
2
*
Tpad
,
Nf
,
Tf
,
Hout
,
Wout
_signals_shape_5d
[
1
]
+
2
*
(
_filters_shape_5d
[
1
]
-
1
),
# Ts
_filters_shape_5d
[
0
],
# Nf
_filters_shape_5d
[
1
],
# Tf
_signals_shape_5d
[
3
]
+
_filters_shape_5d
[
3
]
-
1
,
_signals_shape_5d
[
4
]
+
_filters_shape_5d
[
4
]
-
1
,
))
))
out_tmp_padded
=
tensor
.
set_subtensor
(
out_tmp_padded
=
tensor
.
set_subtensor
(
out_tmp_padded
[:,
out_tmp_padded
[:,
Tpad
:(
Ts
+
Tpad
),
:,
:,
:,
:],
(
_filters_shape_5d
[
1
]
-
1
):(
_signals_shape_5d
[
1
]
+
_filters_shape_5d
[
1
]
-
1
),
:,
:,
:,
:],
out_tmp
)
out_tmp
)
out_5d
=
diagonal_subtensor
(
out_tmp_padded
,
1
,
3
)
.
sum
(
axis
=
3
)
out_5d
=
diagonal_subtensor
(
out_tmp_padded
,
1
,
3
)
.
sum
(
axis
=
3
)
else
:
# for tf==1, no sum along tf, the ts-axis of the output is unchanged!
out_5d
=
out_tmp
.
reshape
((
_signals_shape_5d
[
0
],
_signals_shape_5d
[
1
],
_filters_shape_5d
[
0
],
_signals_shape_5d
[
3
]
+
_filters_shape_5d
[
3
]
-
1
,
_signals_shape_5d
[
4
]
+
_filters_shape_5d
[
4
]
-
1
,
))
elif
border_mode
[
0
]
==
'same'
:
raise
NotImplementedError
(
'sequence border mode'
,
border_mode
[
0
])
else
:
raise
ValueError
(
'invalid border mode'
,
border_mode
[
1
])
return
out_5d
return
out_5d
...
...
theano/tensor/nnet/tests/test_conv3d2d.py
浏览文件 @
853cf7e6
...
@@ -55,19 +55,32 @@ def test_get_diagonal_subtensor_view(wrap=lambda a: a):
...
@@ -55,19 +55,32 @@ def test_get_diagonal_subtensor_view(wrap=lambda a: a):
def
pyconv3d
(
signals
,
filters
,
border_mode
=
'valid'
):
def
pyconv3d
(
signals
,
filters
,
border_mode
=
'valid'
):
if
border_mode
==
'full'
:
# zero-pad signals for full convolution
Ns
,
Ts
,
C
,
Hs
,
Ws
=
signals
.
shape
Nf
,
Tf
,
C
,
Hf
,
Wf
=
filters
.
shape
signals_padded
=
numpy
.
zeros
((
Ns
,
Ts
+
2
*
(
Tf
-
1
),
C
,
Hs
+
2
*
(
Hf
-
1
),
Ws
+
2
*
(
Wf
-
1
)),
'float32'
)
signals_padded
[:,
(
Tf
-
1
):(
Ts
+
Tf
-
1
),
:,
(
Hf
-
1
):(
Hs
+
Hf
-
1
),
(
Wf
-
1
):(
Ws
+
Wf
-
1
)]
=
signals
signals
=
signals_padded
Ns
,
Ts
,
C
,
Hs
,
Ws
=
signals
.
shape
Ns
,
Ts
,
C
,
Hs
,
Ws
=
signals
.
shape
Nf
,
Tf
,
C
,
Hf
,
Wf
=
filters
.
shape
Nf
,
Tf
,
C
,
Hf
,
Wf
=
filters
.
shape
# if border_mode is not 'valid', the signals need zero-padding
if
border_mode
==
'full'
:
Tpad
=
Tf
-
1
Hpad
=
Hf
-
1
Wpad
=
Wf
-
1
elif
border_mode
==
'half'
:
Tpad
=
Tf
//
2
Hpad
=
Hf
//
2
Wpad
=
Wf
//
2
else
:
Tpad
=
0
Hpad
=
0
Wpad
=
0
if
Tpad
>
0
or
Hpad
>
0
or
Wpad
>
0
:
# zero-pad signals
signals_padded
=
numpy
.
zeros
((
Ns
,
Ts
+
2
*
Tpad
,
C
,
Hs
+
2
*
Hpad
,
Ws
+
2
*
Wpad
),
'float32'
)
signals_padded
[:,
Tpad
:(
Ts
+
Tpad
),
:,
Hpad
:(
Hs
+
Hpad
),
Wpad
:(
Ws
+
Wpad
)]
=
signals
Ns
,
Ts
,
C
,
Hs
,
Ws
=
signals_padded
.
shape
signals
=
signals_padded
Tf2
=
Tf
//
2
Tf2
=
Tf
//
2
Hf2
=
Hf
//
2
Hf2
=
Hf
//
2
Wf2
=
Wf
//
2
Wf2
=
Wf
//
2
...
@@ -91,7 +104,7 @@ def check_diagonal_subtensor_view_traces(fn):
...
@@ -91,7 +104,7 @@ def check_diagonal_subtensor_view_traces(fn):
fn
,
ops_to_check
=
(
DiagonalSubtensor
,
IncDiagonalSubtensor
))
fn
,
ops_to_check
=
(
DiagonalSubtensor
,
IncDiagonalSubtensor
))
@parameterized.expand
((
'valid'
,
'full'
),
utt
.
custom_name_func
)
@parameterized.expand
((
'valid'
,
'full'
,
'half'
),
utt
.
custom_name_func
)
def
test_conv3d
(
border_mode
):
def
test_conv3d
(
border_mode
):
check_conv3d
(
border_mode
=
border_mode
,
check_conv3d
(
border_mode
=
border_mode
,
mode
=
mode_without_gpu
,
mode
=
mode_without_gpu
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论