Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cf2116ba
提交
cf2116ba
authored
3月 18, 2010
作者:
Pierre-Antoine Manzagol
浏览文件
操作
浏览文件
下载
差异文件
merge.
上级
29cbd921
7e43e43c
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
41 行增加
和
9 行删除
+41
-9
conv.py
theano/tensor/nnet/conv.py
+24
-0
opt.py
theano/tensor/opt.py
+17
-9
没有找到文件。
theano/tensor/nnet/conv.py
浏览文件 @
cf2116ba
...
...
@@ -53,7 +53,11 @@ def conv2d(input, filters, image_shape=None, filter_shape=None,
(batch size, nb filters, output row, output col)
"""
if
image_shape
and
filter_shape
:
try
:
assert
image_shape
[
1
]
==
filter_shape
[
1
]
except
:
print
'image '
,
image_shape
,
' filters '
,
filter_shape
raise
if
filter_shape
is
not
None
:
nkern
=
filter_shape
[
0
]
...
...
@@ -149,7 +153,10 @@ def conv2d_offset(input, filters, image_shape=None, filter_shape=None,
outputs
.
append
(
out
)
# Join the outputs on the leading axis.
if
len
(
outputs
)
>
1
:
output
=
tensor
.
join
(
1
,
*
outputs
)
else
:
output
=
outputs
[
0
]
outshp
=
ConvOp
.
getOutputShape
(
sub_image_shape
[
2
:],
filter_shape
[
2
:],
subsample
,
border_mode
)
...
...
@@ -476,6 +483,23 @@ class ConvOp(Op):
return
gof
.
Apply
(
self
,
[
_inputs
,
_kerns
],
[
output
])
def
infer_shape
(
self
,
node
,
input_shapes
):
imshp
=
input_shapes
[
0
]
kshp
=
input_shapes
[
1
]
batch_size
=
imshp
[
0
]
fmo
=
kshp
[
0
]
if
self
.
imshp
is
not
None
and
self
.
kshp
is
not
None
:
fmshp
=
ConvOp
.
getOutputShape
(
self
.
imshp
[
1
:],
self
.
kshp
,
(
self
.
dx
,
self
.
dy
),
self
.
out_mode
)
outshp
=
(
batch_size
,
fmo
)
+
tuple
(
fmshp
)
return
[
outshp
]
else
:
# Haven't implemented this case. imshp and kshp may be symbollic
# and ConvOp.getOutputShape doesn't handle this. In this case
# we simply let the default function do its work.
return
node
.
env
.
shape_feature
.
default_infer_shape
(
node
,
ishapes
)
def
perform
(
self
,
node
,
(
img2d
,
filtersflipped
),
(
z
,)):
"""
By default if len(img2d.shape)==3, we
...
...
theano/tensor/opt.py
浏览文件 @
cf2116ba
...
...
@@ -7,7 +7,8 @@ import logging
_logger
=
logging
.
getLogger
(
'theano.tensor.opt'
)
from
theano
import
gof
from
theano.gof
import
opt
,
InconsistencyError
,
TopoOptimizer
,
graph
,
Variable
from
theano.gof
import
opt
,
InconsistencyError
,
TopoOptimizer
,
graph
from
theano.gof
import
Variable
,
Constant
from
theano.gof.utils
import
MethodNotDefined
from
theano.configparser
import
config
from
elemwise
import
Elemwise
,
DimShuffle
...
...
@@ -74,7 +75,7 @@ def get_constant_value(v):
is.
"""
if
isinstance
(
v
,
gof
.
Constant
):
if
isinstance
(
v
,
Constant
):
#TODO: consider checking for arrays of the form e.g. [1,1,1,1] where
# it is not a constant, but in some cases it *could* be replaced with one.
# Note that this would have an effect on the broadcasting of inputs and so on
...
...
@@ -374,7 +375,7 @@ class ShapeFeature(object):
if
s_i
==
1
:
# don't make the optimizer merge a zillion ones together
return
self
.
lscalar_one
if
type
(
s_i
)
is
int
:
if
type
(
s_i
)
is
int
or
isinstance
(
s_i
,
numpy
.
integer
)
:
# this shape is a constant
assert
s_i
>=
0
return
T
.
constant
(
s_i
,
dtype
=
'int64'
)
...
...
@@ -567,9 +568,16 @@ def local_subtensor_make_vector(node):
except
:
#'how can you have multiple indexes into a shape?'
raise
if
isinstance
(
idx
,
(
scalar
.
Scalar
,
T
.
TensorType
)):
# The idx is a Scalar, ie a Type. This means the actual index
# is contained in node.inputs[1]
old_idx
,
idx
=
idx
,
node
.
inputs
[
1
]
assert
idx
.
type
==
old_idx
if
isinstance
(
idx
,
(
int
,
numpy
.
integer
)):
return
[
x
.
owner
.
inputs
[
idx
]]
elif
isinstance
(
idx
,
(
T
.
TensorVariable
,
T
.
TensorConstant
)
):
elif
isinstance
(
idx
,
Variable
):
# if it is a constant we can do something with it
try
:
v
=
get_constant_value
(
idx
)
...
...
@@ -1044,7 +1052,7 @@ class Canonizer(gof.LocalOptimizer):
@staticmethod
def
get_constant
(
v
):
"""
Returns a numeric constant if v is a
gof.
Constant or, well, a
Returns a numeric constant if v is a Constant or, well, a
numeric constant. If v is a plain Variable, returns None.
"""
if
isinstance
(
v
,
Variable
):
...
...
@@ -1126,7 +1134,7 @@ class Canonizer(gof.LocalOptimizer):
# we can't allow ct == []
# TODO: why is this branch needed when merge_num_denum does it for us?
ct
=
[
self
.
calculate
(
numct
,
denumct
,
aslist
=
False
,
out_type
=
out_type
)]
# TODO: why are we not wrapping ct in a
gof.
Constant right now?
# TODO: why are we not wrapping ct in a Constant right now?
if
orig_num
and
len
(
numct
)
==
1
and
len
(
denumct
)
==
0
and
ct
and
N
.
all
(
ct
==
self
.
get_constant
(
orig_num
[
0
])):
# this is an important trick :( if it so happens that:
...
...
@@ -1352,7 +1360,7 @@ def local_neg_div_neg(node):
# No other clients of the original division
new_num
=
num
.
owner
.
inputs
[
0
]
return
[
T
.
true_div
(
new_num
,
denom
)]
elif
numpy
.
all
(
num
.
broadcastable
)
and
isinstance
(
num
,
gof
.
Constant
):
elif
numpy
.
all
(
num
.
broadcastable
)
and
isinstance
(
num
,
Constant
):
if
len
(
frac
.
clients
)
==
1
:
new_num
=
-
num
.
data
return
[
T
.
true_div
(
new_num
,
denom
)]
...
...
@@ -1715,7 +1723,7 @@ register_canonicalize(local_greedy_distributor)
@gof.local_optimizer
([
None
])
def
constant_folding
(
node
):
for
input
in
node
.
inputs
:
if
not
isinstance
(
input
,
gof
.
Constant
):
if
not
isinstance
(
input
,
Constant
):
return
False
try
:
storage
=
[[
None
]
for
output
in
node
.
outputs
]
...
...
@@ -1735,7 +1743,7 @@ def constant_folding(node):
try
:
constant
=
output
.
type
.
Constant
except
:
constant
=
gof
.
Constant
constant
=
Constant
msg
+=
[
constant
(
output
.
type
,
s
[
0
])]
return
msg
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论