Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f13bed43
提交
f13bed43
authored
12月 04, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make CrossentropySoftmax1HotWithBiasDx support uint* as class dtype.
上级
9fc78f6a
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
15 行增加
和
7 行删除
+15
-7
nnet.py
theano/tensor/nnet/nnet.py
+7
-3
test_nnet.py
theano/tensor/nnet/tests/test_nnet.py
+8
-4
没有找到文件。
theano/tensor/nnet/nnet.py
浏览文件 @
f13bed43
...
...
@@ -1012,7 +1012,7 @@ class CrossentropySoftmax1HotWithBiasDx (gof.Op):
return
[
g_dy
,
g_sm
,
g_y_idx
]
def
c_code_cache_version
(
self
):
return
(
2
,)
return
(
3
,)
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
dnll
,
sm
,
y_idx
=
inp
...
...
@@ -1037,10 +1037,14 @@ class CrossentropySoftmax1HotWithBiasDx (gof.Op):
if ((PyArray_DESCR(
%(y_idx)
s)->type_num != NPY_INT64)
&& (PyArray_DESCR(
%(y_idx)
s)->type_num != NPY_INT32)
&& (PyArray_DESCR(
%(y_idx)
s)->type_num != NPY_INT16)
&& (PyArray_DESCR(
%(y_idx)
s)->type_num != NPY_INT8))
&& (PyArray_DESCR(
%(y_idx)
s)->type_num != NPY_INT8)
&& (PyArray_DESCR(
%(y_idx)
s)->type_num != NPY_UINT64)
&& (PyArray_DESCR(
%(y_idx)
s)->type_num != NPY_UINT32)
&& (PyArray_DESCR(
%(y_idx)
s)->type_num != NPY_UINT16)
&& (PyArray_DESCR(
%(y_idx)
s)->type_num != NPY_UINT8))
{
PyErr_SetString(PyExc_TypeError,
"y_idx not
int8, int16, int32, or
int64");
"y_idx not
[u]int8, [u]int16, [u]int32, or [u]
int64");
%(fail)
s;
}
if ((PyArray_NDIM(
%(dnll)
s) != 1)
...
...
theano/tensor/nnet/tests/test_nnet.py
浏览文件 @
f13bed43
...
...
@@ -194,16 +194,20 @@ class T_CrossentropySoftmax1Hot(unittest.TestCase):
class
T_CrossentropySoftmax1HotWithBiasDx
(
utt
.
InferShapeTester
):
def
test0
(
self
):
def
ff
(
class_dtype
):
def
f
(
sm
):
return
(
theano
.
tensor
.
nnet
.
crossentropy_softmax_1hot_with_bias_dx
(
# Class indices
y
=
numpy
.
random
.
randint
(
low
=
0
,
high
=
5
,
size
=
10
)
.
astype
(
class_dtype
)
return
theano
.
tensor
.
nnet
.
crossentropy_softmax_1hot_with_bias_dx
(
numpy
.
random
.
rand
(
10
),
# Gradient w.r.t. NLL.
sm
,
# Softmax output.
numpy
.
random
.
randint
(
low
=
0
,
high
=
5
,
size
=
10
)))
# Class indices.
y
)
return
f
# Build a random softmax output whose rows sum to 1.
softmax_output
=
numpy
.
random
.
rand
(
10
,
5
)
softmax_output
/=
softmax_output
.
sum
(
axis
=
1
)
.
reshape
(
10
,
1
)
utt
.
verify_grad
(
f
,
[
softmax_output
])
for
dtype
in
[
'uint8'
,
'int8'
,
'uint64'
,
'int64'
]:
utt
.
verify_grad
(
ff
(
dtype
),
[
softmax_output
])
def
test1
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论