Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
95743e3c
提交
95743e3c
authored
8月 12, 2014
作者:
Nicolas Ballas
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add 3dfftconv automatic padding when the input last dimension is odd
上级
73a25553
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
17 行增加
和
13 行删除
+17
-13
fftconv.py
theano/sandbox/cuda/fftconv.py
+14
-10
opt.py
theano/sandbox/cuda/opt.py
+3
-3
没有找到文件。
theano/sandbox/cuda/fftconv.py
浏览文件 @
95743e3c
...
@@ -5,6 +5,7 @@ import theano
...
@@ -5,6 +5,7 @@ import theano
import
theano.tensor
as
T
import
theano.tensor
as
T
from
theano.sandbox.cuda
import
cuda_available
,
GpuOp
from
theano.sandbox.cuda
import
cuda_available
,
GpuOp
from
theano.ifelse
import
ifelse
if
cuda_available
:
if
cuda_available
:
from
theano.sandbox.cuda
import
(
basic_ops
,
CudaNdarrayType
,
from
theano.sandbox.cuda
import
(
basic_ops
,
CudaNdarrayType
,
...
@@ -529,10 +530,8 @@ def conv3d_fft(input, filters, image_shape=None, filter_shape=None,
...
@@ -529,10 +530,8 @@ def conv3d_fft(input, filters, image_shape=None, filter_shape=None,
If you must use input which has an odd width, you can either pad
If you must use input which has an odd width, you can either pad
it or use the `pad_last_dim` argument which will do it for you and
it or use the `pad_last_dim` argument which will do it for you and
take care to strip the padding before returning. Don't use this
take care to strip the padding before returning. pad_last_dim checks
argument if you are not sure the input is odd since the padding is
that the last dimension is odd before the actual paddding
unconditional and will make even input odd, thus leading to
problems.
On valid mode the filters must be smaller than the input.
On valid mode the filters must be smaller than the input.
...
@@ -558,19 +557,20 @@ def conv3d_fft(input, filters, image_shape=None, filter_shape=None,
...
@@ -558,19 +557,20 @@ def conv3d_fft(input, filters, image_shape=None, filter_shape=None,
# output channels, input channels, filter dim 0, filter dim 1
# output channels, input channels, filter dim 0, filter dim 1
oc
,
ic_
,
f0
,
f1
,
f2
=
filter_shape
oc
,
ic_
,
f0
,
f1
,
f2
=
filter_shape
# Check that the last dimension is odd
is_odd
=
T
.
eq
(
T
.
mod
(
input
.
shape
[
4
],
2
),
1
)
# pad filters/image to output shape
# pad filters/image to output shape
if
border_mode
==
'valid'
:
if
border_mode
==
'valid'
:
o0
=
i0
o0
=
i0
o1
=
i1
o1
=
i1
o2
=
i2
input_padded
=
input
if
pad_last_dim
:
if
pad_last_dim
:
o2
=
i
2
+
1
o2
=
i
felse
(
is_odd
,
o2
+
1
,
o2
)
input_padded
=
T
.
zeros
((
b
,
ic
,
o0
,
o1
,
o2
),
dtype
=
'float32'
)
input_padded
=
T
.
zeros
((
b
,
ic
,
o0
,
o1
,
o2
),
dtype
=
'float32'
)
input_padded
=
T
.
set_subtensor
(
input_padded
[:,
:,
:
i0
,
:
i1
,
:
i2
],
input_padded
=
T
.
set_subtensor
(
input_padded
[:,
:,
:
i0
,
:
i1
,
:
i2
],
input
)
input
)
else
:
o2
=
i2
input_padded
=
input
filters_padded
=
T
.
zeros
((
oc
,
ic
,
o0
,
o1
,
o2
),
dtype
=
'float32'
)
filters_padded
=
T
.
zeros
((
oc
,
ic
,
o0
,
o1
,
o2
),
dtype
=
'float32'
)
filters_padded
=
T
.
set_subtensor
(
filters_padded
[:,
:,
:
f0
,
:
f1
,
:
f2
],
filters_padded
=
T
.
set_subtensor
(
filters_padded
[:,
:,
:
f0
,
:
f1
,
:
f2
],
filters
)
filters
)
...
@@ -585,7 +585,7 @@ def conv3d_fft(input, filters, image_shape=None, filter_shape=None,
...
@@ -585,7 +585,7 @@ def conv3d_fft(input, filters, image_shape=None, filter_shape=None,
o2
=
i2
+
2
*
(
f2
-
1
)
o2
=
i2
+
2
*
(
f2
-
1
)
if
pad_last_dim
:
if
pad_last_dim
:
o2
=
o2
+
1
o2
=
ifelse
(
is_odd
,
o2
+
1
,
o2
)
# We line up the filters and the images in a way
# We line up the filters and the images in a way
# such that the filters are tightly placed against the
# such that the filters are tightly placed against the
...
@@ -619,6 +619,8 @@ def conv3d_fft(input, filters, image_shape=None, filter_shape=None,
...
@@ -619,6 +619,8 @@ def conv3d_fft(input, filters, image_shape=None, filter_shape=None,
# the two dimensions intact.
# the two dimensions intact.
input_fft_v_shape
=
(
b
,
ic
,
o0
*
o1
,
o2
//
2
+
1
,
2
)
input_fft_v_shape
=
(
b
,
ic
,
o0
*
o1
,
o2
//
2
+
1
,
2
)
filters_fft_v_shape
=
(
oc
,
ic
,
o0
*
o1
,
o2
//
2
+
1
,
2
)
filters_fft_v_shape
=
(
oc
,
ic
,
o0
*
o1
,
o2
//
2
+
1
,
2
)
input_fft_v
=
input_fft_flat
.
reshape
(
input_fft_v_shape
)
input_fft_v
=
input_fft_flat
.
reshape
(
input_fft_v_shape
)
filters_fft_v
=
filters_fft_flat
.
reshape
(
filters_fft_v_shape
)
filters_fft_v
=
filters_fft_flat
.
reshape
(
filters_fft_v_shape
)
...
@@ -626,6 +628,7 @@ def conv3d_fft(input, filters, image_shape=None, filter_shape=None,
...
@@ -626,6 +628,7 @@ def conv3d_fft(input, filters, image_shape=None, filter_shape=None,
output_fft_s
=
mult_and_reduce
(
input_fft_v
,
filters_fft_v
,
output_fft_s
=
mult_and_reduce
(
input_fft_v
,
filters_fft_v
,
input_shape
=
input_fft_v_shape
,
input_shape
=
input_fft_v_shape
,
filter_shape
=
filters_fft_v_shape
)
filter_shape
=
filters_fft_v_shape
)
#output_fft_s = input_fft_v
# reshape for IFFT
# reshape for IFFT
...
@@ -649,6 +652,7 @@ def conv3d_fft(input, filters, image_shape=None, filter_shape=None,
...
@@ -649,6 +652,7 @@ def conv3d_fft(input, filters, image_shape=None, filter_shape=None,
output
=
output_circ
[:,
:,
(
f0
-
1
):(
f0
-
1
+
i0
+
f0
-
1
),
(
f1
-
1
):(
f1
-
1
+
i1
+
f1
-
1
),
(
f2
-
1
):(
f2
-
1
+
i2
+
f2
-
1
)]
output
=
output_circ
[:,
:,
(
f0
-
1
):(
f0
-
1
+
i0
+
f0
-
1
),
(
f1
-
1
):(
f1
-
1
+
i1
+
f1
-
1
),
(
f2
-
1
):(
f2
-
1
+
i2
+
f2
-
1
)]
else
:
else
:
raise
ValueError
(
'invalid mode'
)
raise
ValueError
(
'invalid mode'
)
#output = output_circ[:, :, :, :, :]
# Rescale manually. This is just a factor that comes in during the
# Rescale manually. This is just a factor that comes in during the
# trip through FFT and inverse FFT.
# trip through FFT and inverse FFT.
...
...
theano/sandbox/cuda/opt.py
浏览文件 @
95743e3c
...
@@ -1275,7 +1275,7 @@ def local_conv3d_fft(node):
...
@@ -1275,7 +1275,7 @@ def local_conv3d_fft(node):
# Shuffle filters from (oc, 0, 1, t, ic) to (oc, ic, 0, 1, t)
# Shuffle filters from (oc, 0, 1, t, ic) to (oc, ic, 0, 1, t)
f
=
node
.
inputs
[
1
]
f
=
node
.
inputs
[
1
]
f
=
gpu_from_host
(
f
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
f
=
gpu_from_host
(
f
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
rval
=
conv3d_fft
(
x
,
f
)
rval
=
conv3d_fft
(
x
,
f
,
border_mode
=
'valid'
,
pad_last_dim
=
True
)
# Shuffle from (oc, c, 0, 1, t) to (oc, 0, 1, t, c)
# Shuffle from (oc, c, 0, 1, t) to (oc, 0, 1, t, c)
return
[
gpu_from_host
(
rval
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)
+
node
.
inputs
[
2
])]
return
[
gpu_from_host
(
rval
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)
+
node
.
inputs
[
2
])]
...
@@ -1301,7 +1301,7 @@ def local_convgrad3d_fft(node):
...
@@ -1301,7 +1301,7 @@ def local_convgrad3d_fft(node):
# Shuffle dCdH from (b, 0, 1, t, oc) to (oc, b, 0, 1, t)
# Shuffle dCdH from (b, 0, 1, t, oc) to (oc, b, 0, 1, t)
f
=
node
.
inputs
[
3
]
f
=
node
.
inputs
[
3
]
f
=
f
.
dimshuffle
(
4
,
0
,
1
,
2
,
3
)
f
=
f
.
dimshuffle
(
4
,
0
,
1
,
2
,
3
)
rval
=
conv3d_fft
(
x
,
f
)
rval
=
conv3d_fft
(
x
,
f
,
border_mode
=
'valid'
,
pad_last_dim
=
True
)
# Shuffle from (ic, oc, 0, 1, t) to (oc, 0, 1, t, ic)
# Shuffle from (ic, oc, 0, 1, t) to (oc, 0, 1, t, ic)
return
[
gpu_from_host
(
rval
.
dimshuffle
(
1
,
2
,
3
,
4
,
0
))]
return
[
gpu_from_host
(
rval
.
dimshuffle
(
1
,
2
,
3
,
4
,
0
))]
...
@@ -1327,7 +1327,7 @@ def local_convtransp3d_fft(node):
...
@@ -1327,7 +1327,7 @@ def local_convtransp3d_fft(node):
# Shuffle dCdH from (b, 0, 1, t, oc) to (b, oc, 0, 1, t)
# Shuffle dCdH from (b, 0, 1, t, oc) to (b, oc, 0, 1, t)
f
=
node
.
inputs
[
3
]
f
=
node
.
inputs
[
3
]
f
=
f
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
)
f
=
f
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
)
rval
=
conv3d_fft
(
f
,
x
,
border_mode
=
'full'
)
rval
=
conv3d_fft
(
f
,
x
,
border_mode
=
'full'
,
pad_last_dim
=
True
)
# Shuffle from (ic, b, 0, 1, t) to (b, 0, 1, t, ic)
# Shuffle from (ic, b, 0, 1, t) to (b, 0, 1, t, ic)
return
[
gpu_from_host
(
rval
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
))]
return
[
gpu_from_host
(
rval
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
))]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论