Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3c1025e4
提交
3c1025e4
authored
2月 06, 2015
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Reimplement shape_i to not disable shape optimization in some cases
上级
ae0797b3
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
30 行增加
和
11 行删除
+30
-11
ops.py
theano/compile/ops.py
+23
-6
dnn.py
theano/sandbox/cuda/dnn.py
+7
-5
没有找到文件。
theano/compile/ops.py
浏览文件 @
3c1025e4
...
@@ -387,17 +387,34 @@ class Shape_i(gof.Op):
...
@@ -387,17 +387,34 @@ class Shape_i(gof.Op):
return
[
None
]
return
[
None
]
def
shape_i
(
var
,
i
):
def
shape_i
(
var
,
i
,
fgraph
=
None
):
"""This is useful in optimization that need to get the shape. This
"""Equivalent of var.shape[i], but apply if possible the shape
feature optimization
This is useful in optimization that need to get the shape. This
remove the need of the following shape_feature optimization that
remove the need of the following shape_feature optimization that
convert it. So this speed up optimization and remove Equilibrium
convert it. So this speed up optimization and remove Equilibrium
max iteration problems.
max iteration problems.
:param var: the variable we want to take the shape of
:param i: The shape dimensions we want
:param fgraph: optional. If var.fgraph do not exist, the fgraph that
have the shape_feature to introduce var in to get the optimized shape.
"""
"""
if
(
hasattr
(
var
,
'fgraph'
)
and
if
fgraph
is
None
and
hasattr
(
var
,
'fgraph'
):
hasattr
(
node
.
outputs
[
0
]
.
fgraph
,
'shape_feature'
)):
fgraph
=
var
.
fgraph
return
node
.
outputs
[
0
]
.
fgraph
.
shape_feature
.
shape_of
[
var
][
i
]
if
fgraph
and
hasattr
(
fgraph
,
'shape_feature'
):
return
Shape_i
(
i
)(
var
)
if
var
not
in
fgraph
.
shape_feature
.
shape_of
:
# If var isn't in the ShapeFeature, add it.
fgraph
.
shape_feature
.
on_import
(
fgraph
,
var
.
owner
,
'gof.ops.shape_i'
)
return
fgraph
.
shape_feature
.
shape_of
[
var
][
i
]
# If we are not able to use the shape feature, we should not put
# Shape_i in the graph. Otherwise, the shape feature optimization
# won't get applied.
return
var
.
shape
[
i
]
def
register_shape_i_c_code
(
typ
,
code
,
check_input
,
version
=
()):
def
register_shape_i_c_code
(
typ
,
code
,
check_input
,
version
=
()):
...
...
theano/sandbox/cuda/dnn.py
浏览文件 @
3c1025e4
...
@@ -576,6 +576,7 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
...
@@ -576,6 +576,7 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
capability of 3.0 or higer. This means that older GPU will not
capability of 3.0 or higer. This means that older GPU will not
work with this Op.
work with this Op.
"""
"""
fgraph
=
getattr
(
img
,
'fgraph'
,
None
)
or
getattr
(
kerns
,
'fgraph'
,
None
)
if
(
border_mode
==
'valid'
and
subsample
==
(
1
,
1
)
and
if
(
border_mode
==
'valid'
and
subsample
==
(
1
,
1
)
and
direction_hint
==
'bprop weights'
):
direction_hint
==
'bprop weights'
):
# Special case: We are asked to use GpuDnnConvGradW. We need to set
# Special case: We are asked to use GpuDnnConvGradW. We need to set
...
@@ -602,13 +603,14 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
...
@@ -602,13 +603,14 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
img
=
gpu_contiguous
(
img
)
img
=
gpu_contiguous
(
img
)
kerns
=
gpu_contiguous
(
kerns
.
dimshuffle
(
1
,
0
,
2
,
3
))
kerns
=
gpu_contiguous
(
kerns
.
dimshuffle
(
1
,
0
,
2
,
3
))
conv_mode
=
'cross'
if
conv_mode
==
'conv'
else
'conv'
conv_mode
=
'cross'
if
conv_mode
==
'conv'
else
'conv'
shape2
=
shape_i
(
img
,
2
,
fgraph
)
+
shape_i
(
kerns
,
2
,
fgraph
)
-
1
shape
=
theano
.
tensor
.
stack
(
shape_i
(
img
,
0
),
shape_i
(
kerns
,
1
),
shape3
=
shape_i
(
img
,
3
,
fgraph
)
+
shape_i
(
kerns
,
3
,
fgraph
)
-
1
shape_i
(
img
,
2
)
+
shape_i
(
kerns
,
2
)
-
1
,
shape
=
theano
.
tensor
.
stack
(
shape_i
(
img
,
0
,
fgraph
),
shape_i
(
img
,
3
)
+
shape_i
(
kerns
,
3
)
-
1
)
shape_i
(
kerns
,
1
,
fgraph
),
shape2
,
shape3
)
desc
=
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
desc
=
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
conv_mode
=
conv_mode
)(
shape
,
kerns
.
shape
)
conv_mode
=
conv_mode
)(
shape
,
kerns
.
shape
)
return
GpuDnnConvGradI
()(
kerns
,
img
,
desc
,
shape
[
2
],
shape
[
3
]
)
return
GpuDnnConvGradI
()(
kerns
,
img
,
desc
,
shape
2
,
shape3
)
# Standard case: We use GpuDnnConv with suitable padding.
# Standard case: We use GpuDnnConv with suitable padding.
img
=
gpu_contiguous
(
img
)
img
=
gpu_contiguous
(
img
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论