Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c880fff7
提交
c880fff7
authored
11月 22, 2012
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make opt work when shape has been specified.
上级
b624e3aa
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
78 行增加
和
2 行删除
+78
-2
nnet.py
theano/tensor/nnet/nnet.py
+15
-1
test_nnet.py
theano/tensor/nnet/tests/test_nnet.py
+63
-1
没有找到文件。
theano/tensor/nnet/nnet.py
浏览文件 @
c880fff7
...
...
@@ -1378,7 +1378,21 @@ def local_argmax_pushdown(node):
def
_check_rows_is_arange_len_labels
(
rows
,
labels
):
'''Check that 'rows' is the same node as T.arange(labels.shape[0])'''
'''Check that 'rows' is the same node as T.arange(labels.shape[0])
Also considers the case where labels.shape[0] is constant and equal
to 1, and T.arange(labels.shape[0]) has been constant-folded into 0.
'''
if
labels
.
owner
and
hasattr
(
labels
.
owner
.
fgraph
,
'shape_feature'
):
shape_of
=
labels
.
owner
.
fgraph
.
shape_feature
.
shape_of
# TODO: consider cases where shape_of[labels] is constant, and
# has a value different from 1.
# This case is harder, as _is_const only accepts a scalar value
# as second argument, so checking for
# _is_const(rows, numpy.arange(...)) does not work for the moment.
if
len
(
shape_of
[
labels
])
==
1
and
_is_const
(
shape_of
[
labels
][
0
],
1
):
return
_is_const
(
rows
,
0
)
if
rows
.
owner
and
isinstance
(
rows
.
owner
.
op
,
tensor
.
ARange
):
start
,
stop
,
step
=
rows
.
owner
.
inputs
...
...
theano/tensor/nnet/tests/test_nnet.py
浏览文件 @
c880fff7
...
...
@@ -925,7 +925,69 @@ class T_CrossentropyCategorical1Hot(utt.InferShapeTester):
config
.
warn
.
sum_div_dimshuffle_bug
=
backup
if
verbose
:
print_graph
(
g
)
self
.
print_graph
(
g
)
try
:
ops
=
[
node
.
op
for
node
in
g
.
maker
.
fgraph
.
toposort
()]
assert
len
(
ops
)
<=
6
assert
crossentropy_softmax_1hot_with_bias_dx
in
ops
assert
softmax_with_bias
in
ops
assert
softmax_grad
not
in
ops
g
(
x_val
,
b_val
,
y_val
)
except
Exception
:
theano
.
printing
.
debugprint
(
g
)
raise
def
test_optimize_xent_vector4
(
self
):
# Same as test_optimize_xent_vector2, but y is the result of
# a "specify_shape" that indicates its length is 1, so the
# constant-folding of arange(y.shape[0]) happen before the xent
# optimization
verbose
=
0
mode
=
theano
.
compile
.
mode
.
get_default_mode
()
if
mode
==
theano
.
compile
.
mode
.
get_mode
(
'FAST_COMPILE'
):
mode
=
'FAST_RUN'
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
x_val
=
rng
.
randn
(
5
)
.
astype
(
config
.
floatX
)
b_val
=
rng
.
randn
(
5
)
.
astype
(
config
.
floatX
)
y_val
=
numpy
.
asarray
([
2
])
x
=
T
.
vector
(
'x'
)
b
=
T
.
vector
(
'b'
)
y_
=
T
.
lvector
(
'y_'
)
y
=
T
.
specify_shape
(
y_
,
(
1
,))
## Test that a biased softmax is optimized correctly
bias_expressions
=
[
T
.
sum
(
-
T
.
log
(
softmax
(
x
+
b
)[
T
.
arange
(
y
.
shape
[
0
]),
y
])),
-
T
.
sum
(
T
.
log
(
softmax
(
b
+
x
)[
T
.
arange
(
y
.
shape
[
0
]),
y
])),
-
T
.
sum
(
T
.
log
(
softmax
(
x
+
b
))[
T
.
arange
(
y
.
shape
[
0
]),
y
]),
T
.
sum
(
-
T
.
log
(
softmax
(
b
+
x
))[
T
.
arange
(
y
.
shape
[
0
]),
y
])]
for
expr
in
bias_expressions
:
f
=
theano
.
function
([
x
,
b
,
y_
],
expr
,
mode
=
mode
)
if
verbose
:
self
.
print_graph
(
f
)
try
:
ops
=
[
node
.
op
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
# [big_op, sum, dim_shuffle, specify_shape]
assert
len
(
ops
)
<=
4
assert
crossentropy_softmax_argmax_1hot_with_bias
in
ops
assert
not
[
1
for
o
in
ops
if
isinstance
(
o
,
T
.
AdvancedSubtensor
)]
f
(
x_val
,
b_val
,
y_val
)
except
Exception
:
theano
.
printing
.
debugprint
(
f
)
raise
backup
=
config
.
warn
.
sum_div_dimshuffle_bug
config
.
warn
.
sum_div_dimshuffle_bug
=
False
try
:
g
=
theano
.
function
([
x
,
b
,
y
],
T
.
grad
(
expr
,
x
),
mode
=
mode
)
finally
:
config
.
warn
.
sum_div_dimshuffle_bug
=
backup
if
verbose
:
self
.
print_graph
(
g
)
try
:
ops
=
[
node
.
op
for
node
in
g
.
maker
.
fgraph
.
toposort
()]
assert
len
(
ops
)
<=
6
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论