Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
N
NiuTrans.Tensor
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
杨迪
NiuTrans.Tensor
Commits
9b87b785
Commit
9b87b785
authored
Jul 19, 2018
by
xiaotong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Back propagation for Unsqueeze
parent
1226160d
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
42 行增加
和
2 行删除
+42
-2
source/network/XBackwardShape.cpp
+32
-2
source/network/XBackwardShape.h
+4
-0
source/network/XNoder.cpp
+1
-0
source/tensor/core/shape/Unsqueeze.cpp
+5
-0
没有找到文件。
source/network/XBackwardShape.cpp
查看文件 @
9b87b785
...
...
@@ -41,6 +41,8 @@ void XShapeGrad::MakeGrad(XTensor * node)
GradMerge
(
node
);
else
if
(
operID
==
SHAPE_MERGE_LIST
)
GradMergeList
(
node
);
else
if
(
operID
==
SHAPE_UNSQUEEZE
)
GradUnsqueeze
(
node
);
else
{
ShowNTErrors
(
"TODO!"
);
}
...
...
@@ -142,6 +144,7 @@ dE/da = dE/dc_{split_0}
dE/db = dE/dc_{split_1}
i.e.,
list(dE/da, dE/db, ...) = split(dE/dc)
>> node - the node (c) for backward computation
*/
void
XShapeGrad
::
GradMergeList
(
XTensor
*
node
)
{
...
...
@@ -200,9 +203,9 @@ void XShapeGrad::GradMergeList(XTensor * node)
/* gradient accumulation for each split */
for
(
int
i
=
0
;
i
<
smalls
.
count
;
i
++
){
XTensor
*
small
Grad
=
(
XTensor
*
)
smallsGrad
.
Get
(
i
);
XTensor
*
input
Grad
=
(
XTensor
*
)
smallsGrad
.
Get
(
i
);
gradSmall
.
data
=
(
char
*
)
gradSplit
.
data
+
i
*
last
->
unitNum
*
last
->
unitSize
;
_Sum
(
smallGrad
,
&
gradSmall
,
small
Grad
);
_Sum
(
inputGrad
,
&
gradSmall
,
input
Grad
);
}
gradSmall
.
data
=
NULL
;
...
...
@@ -210,4 +213,30 @@ void XShapeGrad::GradMergeList(XTensor * node)
}
}
/*
gradient for unsqueezing a tensor
for
c = unsqueeze(a)
we have
dE/da = reduecesum(dE/dc)
>> node - the node (c) for backward computation
*/
void
XShapeGrad
::
GradUnsqueeze
(
XTensor
*
node
)
{
XLink
&
income
=
node
->
income
;
CheckNTErrors
(
income
.
tailNum
==
1
,
"Wrong input tensor number for UNSQUEEZE!"
);
XTensor
*
output
=
node
;
XTensor
*
input
=
income
.
tails
[
0
];
XNoder
::
MakeGrad
(
input
);
int
dim
=
income
.
GetParamInt
(
0
);
int
dSize
=
income
.
GetParamInt
(
1
);
CheckNTErrors
(
dSize
==
output
->
GetDim
(
dim
),
"Wrong dim size for UNSQUEEZE!"
);
CheckNTErrors
(
output
->
unitNum
=
input
->
unitNum
*
dSize
,
"Wrong tensor size!"
);
_ReduceSum
(
output
->
grad
,
input
->
grad
,
dim
);
}
}
\ No newline at end of file
source/network/XBackwardShape.h
查看文件 @
9b87b785
...
...
@@ -48,6 +48,10 @@ private:
/* gradient for merging a list of tensors : c = merge(list(a, b, ...)) */
static
void
GradMergeList
(
XTensor
*
node
);
/* gradient for unsqueezing a tensor : c = unsqueeze(a) */
static
void
GradUnsqueeze
(
XTensor
*
node
);
};
}
...
...
source/network/XNoder.cpp
查看文件 @
9b87b785
...
...
@@ -32,6 +32,7 @@ void XNoder::MakeGrad(XTensor * node)
if
(
!
XTensor
::
IsIdentical
(
node
,
node
->
grad
)){
delete
node
->
grad
;
node
->
grad
=
NewTensor
(
node
);
node
->
grad
->
SetZeroAll
();
}
}
...
...
source/tensor/core/shape/Unsqueeze.cpp
查看文件 @
9b87b785
...
...
@@ -129,6 +129,11 @@ XTensor Unsqueeze(const XTensor &a, int dim, int dSize)
/* call _Unsqueeze function */
_Unsqueeze
(
&
a
,
&
b
,
dim
,
dSize
);
/* tensor connections */
XLink
::
MakeLink
(
&
a
,
NULL
,
&
b
,
SHAPE_UNSQUEEZE
);
XLink
::
AddParamToHeadInt
(
&
b
,
dim
);
XLink
::
AddParamToHeadInt
(
&
b
,
dSize
);
/* destroy variables */
delete
[]
dimSize
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论