Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cd407f59
提交
cd407f59
authored
10月 18, 2017
作者:
notoraptor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move script dnn conv functions to private functions in dnn module.
上级
93bfb27d
全部展开
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
3 行增加
和
76 行删除
+3
-76
dnn.py
theano/gpuarray/dnn.py
+0
-0
check_dnn_conv.py
theano/gpuarray/tests/check_dnn_conv.py
+3
-76
没有找到文件。
theano/gpuarray/dnn.py
浏览文件 @
cd407f59
差异被折叠。
点击展开。
theano/gpuarray/tests/check_dnn_conv.py
浏览文件 @
cd407f59
...
@@ -26,88 +26,15 @@ from nose.plugins.skip import SkipTest
...
@@ -26,88 +26,15 @@ from nose.plugins.skip import SkipTest
import
theano
import
theano
import
theano.tests.unittest_tools
as
utt
import
theano.tests.unittest_tools
as
utt
from
theano.compat
import
ifilter
from
theano.compat
import
ifilter
from
theano.compile.ops
import
shape_i_op
from
theano.configdefaults
import
SUPPORTED_DNN_CONV_ALGO_RUNTIME
from
theano.configdefaults
import
SUPPORTED_DNN_CONV_ALGO_RUNTIME
from
theano.gpuarray
import
cudnn_defs
from
theano.gpuarray
import
cudnn_defs
from
theano.gpuarray.basic_ops
import
infer_context_name
,
as_gpuarray_variable
,
gpu_contiguous
,
GpuAllocEmpty
from
theano.gpuarray.dnn
import
(
GpuDnnConv
,
GpuDnnConvGradW
,
GpuDnnConvGradI
,
version
,
from
theano.gpuarray.dnn
import
GpuDnnConvDesc
,
GpuDnnConv
,
GpuDnnConvGradW
,
GpuDnnConvGradI
,
version
,
get_precision
_dnn_conv
as
dnn_conv
,
_dnn_gradinput
as
dnn_gradinput
,
_dnn_gradweight
as
dnn_gradweight
)
from
theano.gpuarray.tests.config
import
mode_with_gpu
,
ref_cast
from
theano.gpuarray.tests.config
import
mode_with_gpu
,
ref_cast
from
theano.tensor.nnet.abstract_conv
import
get_conv_output_shape
,
assert_conv_shape
from
theano.tensor.nnet.abstract_conv
import
get_conv_output_shape
,
assert_conv_shape
from
theano.tensor.nnet.corr
import
CorrMM
,
CorrMM_gradInputs
,
CorrMM_gradWeights
from
theano.tensor.nnet.corr
import
CorrMM
,
CorrMM_gradInputs
,
CorrMM_gradWeights
from
theano.tensor.nnet.corr3d
import
Corr3dMM
,
Corr3dMM_gradInputs
,
Corr3dMM_gradWeights
from
theano.tensor.nnet.corr3d
import
Corr3dMM
,
Corr3dMM_gradInputs
,
Corr3dMM_gradWeights
from
theano.tensor.opt
import
Assert
# We provide a special implementation of dnn_conv, dnn_gradweight and dnn_gradinput
# that support alpha, beta and out as parameters.
def
dnn_conv
(
img
,
kerns
,
alpha
=
1
,
beta
=
0
,
out
=
None
,
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
dilation
=
(
1
,
1
),
conv_mode
=
'conv'
,
algo
=
None
,
precision
=
None
,
num_groups
=
1
):
ctx_name
=
infer_context_name
(
img
,
kerns
)
img
=
gpu_contiguous
(
as_gpuarray_variable
(
img
,
ctx_name
))
kerns
=
gpu_contiguous
(
as_gpuarray_variable
(
kerns
,
ctx_name
))
precision
=
get_precision
(
precision
,
[
img
,
kerns
])
desc
=
GpuDnnConvDesc
(
border_mode
=
border_mode
,
subsample
=
subsample
,
dilation
=
dilation
,
conv_mode
=
conv_mode
,
precision
=
precision
,
num_groups
=
num_groups
)(
kerns
.
shape
)
desc_op
=
desc
.
owner
.
op
# We can use Shape_i and bypass the infer_shape here as this is on
# the input of node and it will always be present.
ishape
=
[
shape_i_op
(
i
)(
img
)
for
i
in
range
(
img
.
ndim
)]
kshape
=
[
shape_i_op
(
i
)(
kerns
)
for
i
in
range
(
kerns
.
ndim
)]
out_shp
=
get_conv_output_shape
(
ishape
,
kshape
,
desc_op
.
border_mode
,
desc_op
.
subsample
,
filter_dilation
=
dilation
)
out_shp
=
assert_conv_shape
(
out_shp
)
if
beta
==
0
:
real_out
=
GpuAllocEmpty
(
dtype
=
img
.
dtype
,
context_name
=
ctx_name
)(
*
out_shp
)
else
:
assert
out
is
not
None
out
=
gpu_contiguous
(
as_gpuarray_variable
(
out
,
ctx_name
))
check
=
Assert
(
'GpuDnnConv: qiven output (for beta not null) does not have expected shape'
)
real_out
=
check
(
out
,
theano
.
tensor
.
all
(
theano
.
tensor
.
eq
(
out
.
shape
,
out_shp
)))
return
GpuDnnConv
(
algo
=
algo
,
num_groups
=
num_groups
)(
img
,
kerns
,
real_out
,
desc
,
alpha
,
beta
)
def
dnn_gradweight
(
img
,
topgrad
,
kerns_shp
,
alpha
=
1
,
beta
=
0
,
out
=
None
,
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
dilation
=
(
1
,
1
),
conv_mode
=
'conv'
,
algo
=
None
,
precision
=
None
,
num_groups
=
1
):
ctx_name
=
infer_context_name
(
img
,
topgrad
)
img
=
gpu_contiguous
(
as_gpuarray_variable
(
img
,
ctx_name
))
topgrad
=
gpu_contiguous
(
as_gpuarray_variable
(
topgrad
,
ctx_name
))
kerns_shp
=
theano
.
tensor
.
as_tensor_variable
(
kerns_shp
)
precision
=
get_precision
(
precision
,
[
img
,
topgrad
],
for_grad
=
True
)
desc
=
GpuDnnConvDesc
(
border_mode
=
border_mode
,
subsample
=
subsample
,
dilation
=
dilation
,
conv_mode
=
conv_mode
,
precision
=
precision
,
num_groups
=
num_groups
)(
kerns_shp
)
if
beta
==
0
:
real_out
=
GpuAllocEmpty
(
dtype
=
img
.
dtype
,
context_name
=
ctx_name
)(
*
kerns_shp
)
else
:
assert
out
is
not
None
out
=
gpu_contiguous
(
as_gpuarray_variable
(
out
,
ctx_name
))
check
=
Assert
(
'GpuDnnConvGradW: qiven output (for beta not null) does not have expected shape'
)
real_out
=
check
(
out
,
theano
.
tensor
.
all
(
theano
.
tensor
.
eq
(
out
.
shape
,
kerns_shp
)))
return
GpuDnnConvGradW
(
algo
=
algo
,
num_groups
=
num_groups
)(
img
,
topgrad
,
real_out
,
desc
,
alpha
,
beta
)
def
dnn_gradinput
(
kerns
,
topgrad
,
img_shp
,
alpha
=
1
,
beta
=
0
,
out
=
None
,
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
dilation
=
(
1
,
1
),
conv_mode
=
'conv'
,
algo
=
None
,
precision
=
None
,
num_groups
=
1
):
ctx_name
=
infer_context_name
(
kerns
,
topgrad
)
kerns
=
gpu_contiguous
(
as_gpuarray_variable
(
kerns
,
ctx_name
))
topgrad
=
gpu_contiguous
(
as_gpuarray_variable
(
topgrad
,
ctx_name
))
img_shp
=
theano
.
tensor
.
as_tensor_variable
(
img_shp
)
precision
=
get_precision
(
precision
,
[
kerns
,
topgrad
],
for_grad
=
True
)
desc
=
GpuDnnConvDesc
(
border_mode
=
border_mode
,
subsample
=
subsample
,
dilation
=
dilation
,
conv_mode
=
conv_mode
,
precision
=
precision
,
num_groups
=
num_groups
)(
kerns
.
shape
)
if
beta
==
0
:
real_out
=
GpuAllocEmpty
(
dtype
=
kerns
.
dtype
,
context_name
=
ctx_name
)(
*
img_shp
)
else
:
assert
out
is
not
None
out
=
gpu_contiguous
(
as_gpuarray_variable
(
out
,
ctx_name
))
check
=
Assert
(
'GpuDnnConvGradI: qiven output (for beta not null) does not have expected shape'
)
real_out
=
check
(
out
,
theano
.
tensor
.
all
(
theano
.
tensor
.
eq
(
out
.
shape
,
img_shp
)))
return
GpuDnnConvGradI
(
algo
=
algo
,
num_groups
=
num_groups
)(
kerns
,
topgrad
,
real_out
,
desc
,
alpha
,
beta
)
def
check_dtype_config_support
(
dtype
,
precision
):
def
check_dtype_config_support
(
dtype
,
precision
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论