Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7ec0c018
提交
7ec0c018
authored
5月 14, 2014
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Attempt at adding support for the 'full' border mode.
上级
a50a7986
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
40 行增加
和
18 行删除
+40
-18
fftconv.py
theano/sandbox/cuda/fftconv.py
+40
-18
没有找到文件。
theano/sandbox/cuda/fftconv.py
浏览文件 @
7ec0c018
...
@@ -373,13 +373,16 @@ def mult_and_reduce(input_fft_v, filters_fft_v, input_shape=None,
...
@@ -373,13 +373,16 @@ def mult_and_reduce(input_fft_v, filters_fft_v, input_shape=None,
return
output
return
output
def
conv2d_fft
(
input
,
filters
,
image_shape
=
None
,
filter_shape
=
None
):
def
conv2d_fft
(
input
,
filters
,
image_shape
=
None
,
filter_shape
=
None
,
border_mode
=
'valid'
):
"""
"""
expects bc01 input
expects bc01 input
performs a valid convolution
performs a valid
/full
convolution
input: (b, ic, i0, i1)
input: (b, ic, i0, i1)
filters: (oc, ic, f0, f1)
filters: (oc, ic, f0, f1)
bocder_mode: 'valid' of 'full'
"""
"""
# use symbolic shapes to compute shape info at runtime if not specified
# use symbolic shapes to compute shape info at runtime if not specified
...
@@ -394,44 +397,63 @@ def conv2d_fft(input, filters, image_shape=None, filter_shape=None):
...
@@ -394,44 +397,63 @@ def conv2d_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
=
filter_shape
oc
,
ic_
,
f0
,
f1
=
filter_shape
# pad filters to input shape
# pad filters/image to output shape
filters_padded
=
T
.
zeros
((
oc
,
ic
,
i0
,
i1
))
if
border_mode
==
'valid'
:
filters_padded
=
T
.
set_subtensor
(
filters_padded
[:,
:,
:
f0
,
:
f1
],
filters
)
o0
=
i0
o1
=
i1
filters_padded
=
T
.
zeros
((
oc
,
ic
,
o0
,
o1
),
dtype
=
'float32'
)
filters_padded
=
T
.
set_subtensor
(
filters_padded
[:,
:,
:
f0
,
:
f1
],
filters
)
input_padded
=
input
elif
mode
==
'full'
:
o0
=
i0
+
f0
-
1
o1
=
i1
+
f1
-
1
filters_padded
=
T
.
zeros
((
oc
,
ic
,
o0
,
o1
),
dtype
=
'float32'
)
filters_padded
=
T
.
set_subtensor
(
filters_padded
[:,
:,
:
f0
,
:
f1
],
filters
)
input_padded
=
T
.
zeros
((
oc
,
ic
,
o0
,
o1
),
dtype
=
'float32'
)
input_padded
=
T
.
set_subtensor
(
input_padded
[:,
:,
:
i0
,
:
i1
],
input
)
else
:
raise
ValueError
(
'invalid mode'
)
# reshape for FFT
# reshape for FFT
input_flat
=
input
.
reshape
((
b
*
ic
,
i0
,
i
1
))
input_flat
=
input
_padded
.
reshape
((
b
*
ic
,
o0
,
o
1
))
filters_flat
=
filters_padded
.
reshape
((
oc
*
ic
,
i0
,
i
1
))
filters_flat
=
filters_padded
.
reshape
((
oc
*
ic
,
o0
,
o
1
))
# perform FFT
# perform FFT
input_fft_flat
=
cufft
(
input_flat
)
# (b * ic,
i0, i
1//2 + 1, 2)
input_fft_flat
=
cufft
(
input_flat
)
# (b * ic,
o0, o
1//2 + 1, 2)
filters_fft_flat
=
cufft
(
filters_flat
)
# (oc * ic,
i0, i
1//2 + 1, 2)
filters_fft_flat
=
cufft
(
filters_flat
)
# (oc * ic,
o0, o
1//2 + 1, 2)
# unfold ic dimension
# unfold ic dimension
input_fft_v_shape
=
(
b
,
ic
,
i0
,
i
1
//
2
+
1
,
2
)
input_fft_v_shape
=
(
b
,
ic
,
o0
,
o
1
//
2
+
1
,
2
)
filters_fft_v_shape
=
(
oc
,
ic
,
i0
,
i
1
//
2
+
1
,
2
)
filters_fft_v_shape
=
(
oc
,
ic
,
o0
,
o
1
//
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
)
# (b, oc,
i0, i
1//2 + 1, 2)
# (b, oc,
o0, o
1//2 + 1, 2)
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
)
# reshape for IFFT
# reshape for IFFT
output_fft_flat
=
output_fft_s
.
reshape
((
b
*
oc
,
i0
,
i
1
//
2
+
1
,
2
))
output_fft_flat
=
output_fft_s
.
reshape
((
b
*
oc
,
o0
,
o
1
//
2
+
1
,
2
))
# perform IFFT
# perform IFFT
output_flat
=
cuifft
(
output_fft_flat
)
# (b * oc,
i0, i
1)
output_flat
=
cuifft
(
output_fft_flat
)
# (b * oc,
o0, o
1)
# reshape
# reshape
output_circ
=
output_flat
.
reshape
((
b
,
oc
,
i0
,
i
1
))
# circular!
output_circ
=
output_flat
.
reshape
((
b
,
oc
,
o0
,
o
1
))
# circular!
# slice because the convolution was circular, we need it to be valid
# slice because the convolution was circular, we need it to be valid
output
=
output_circ
[:,
:,
f0
-
1
:,
f1
-
1
:]
if
border_mode
==
'valid'
:
output
=
output_circ
[:,
:,
f0
-
1
:,
f1
-
1
:]
else
:
output
=
output_circ
# rescale manually
# rescale manually
output
=
(
1.0
/
T
.
cast
(
i0
*
i1
,
theano
.
config
.
floatX
))
*
output
output
=
(
1.0
/
T
.
cast
(
o0
*
o1
,
'float32'
))
*
output
# output should now be the result of a batched valid convolution
# output should now be the result of a batched valid convolution
# of the input with the filters.
# of the input with the filters.
return
output
return
basic_ops
.
as_cuda_ndarray_variable
(
output
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论