Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
5b5346ec
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5b5346ec
编写于
6月 13, 2017
作者:
Y
yangyaming
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Follow comments.
上级
e7ac2889
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
61 addition
and
50 deletion
+61
-50
paddle/gserver/layers/DetectionUtil.cpp
paddle/gserver/layers/DetectionUtil.cpp
+45
-38
paddle/gserver/layers/DetectionUtil.h
paddle/gserver/layers/DetectionUtil.h
+16
-12
未找到文件。
paddle/gserver/layers/DetectionUtil.cpp
浏览文件 @
5b5346ec
...
@@ -16,29 +16,33 @@ limitations under the License. */
...
@@ -16,29 +16,33 @@ limitations under the License. */
namespace
paddle
{
namespace
paddle
{
size_t
appendWithPermute
(
const
Matrix
Ptr
inMatrix
,
size_t
appendWithPermute
(
const
Matrix
&
inMatrix
,
size_t
height
,
size_t
height
,
size_t
width
,
size_t
width
,
size_t
outTotalSize
,
size_t
outTotalSize
,
size_t
outOffset
,
size_t
outOffset
,
size_t
batchSize
,
size_t
batchSize
,
Matrix
Ptr
outMatrix
,
Matrix
&
outMatrix
,
PermMode
permMode
,
PermMode
permMode
,
bool
useGpu
)
{
bool
useGpu
)
{
if
(
permMode
==
NCHWTO
NHWC
)
{
if
(
permMode
==
kNCHWTo
NHWC
)
{
size_t
inElementCnt
=
inMatrix
->
getElementCnt
();
size_t
inElementCnt
=
inMatrix
.
getElementCnt
();
size_t
channels
=
inElementCnt
/
(
height
*
width
*
batchSize
);
size_t
channels
=
inElementCnt
/
(
height
*
width
*
batchSize
);
size_t
imgSize
=
height
*
width
;
size_t
imgSize
=
height
*
width
;
for
(
size_t
i
=
0
;
i
<
batchSize
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
batchSize
;
++
i
)
{
size_t
offset
=
i
*
(
outTotalSize
/
batchSize
)
+
outOffset
;
size_t
offset
=
i
*
(
outTotalSize
/
batchSize
)
+
outOffset
;
const
MatrixPtr
inTmp
=
const
MatrixPtr
inTmp
=
Matrix
::
create
(
Matrix
::
create
(
inMatrix
->
getData
(
)
+
i
*
channels
*
imgSize
,
const_cast
<
real
*>
(
inMatrix
.
getData
()
)
+
i
*
channels
*
imgSize
,
channels
,
channels
,
imgSize
,
imgSize
,
false
,
false
,
useGpu
);
useGpu
);
MatrixPtr
outTmp
=
Matrix
::
create
(
MatrixPtr
outTmp
=
outMatrix
->
getData
()
+
offset
,
imgSize
,
channels
,
false
,
useGpu
);
Matrix
::
create
(
const_cast
<
real
*>
(
outMatrix
.
getData
())
+
offset
,
imgSize
,
channels
,
false
,
useGpu
);
inTmp
->
transpose
(
outTmp
,
false
);
inTmp
->
transpose
(
outTmp
,
false
);
}
}
return
channels
*
imgSize
;
return
channels
*
imgSize
;
...
@@ -47,25 +51,29 @@ size_t appendWithPermute(const MatrixPtr inMatrix,
...
@@ -47,25 +51,29 @@ size_t appendWithPermute(const MatrixPtr inMatrix,
}
}
}
}
size_t
decomposeWithPermute
(
const
Matrix
Ptr
inMatrix
,
size_t
decomposeWithPermute
(
const
Matrix
&
inMatrix
,
size_t
height
,
size_t
height
,
size_t
width
,
size_t
width
,
size_t
inTotalSize
,
size_t
inTotalSize
,
size_t
inOffset
,
size_t
inOffset
,
size_t
batchSize
,
size_t
batchSize
,
Matrix
Ptr
outMatrix
,
Matrix
&
outMatrix
,
PermMode
permMode
,
PermMode
permMode
,
bool
useGpu
)
{
bool
useGpu
)
{
if
(
permMode
==
NHWCTO
NCHW
)
{
if
(
permMode
==
kNHWCTo
NCHW
)
{
size_t
outElementCnt
=
outMatrix
->
getElementCnt
();
size_t
outElementCnt
=
outMatrix
.
getElementCnt
();
size_t
channels
=
outElementCnt
/
(
height
*
width
*
batchSize
);
size_t
channels
=
outElementCnt
/
(
height
*
width
*
batchSize
);
size_t
imgSize
=
height
*
width
;
size_t
imgSize
=
height
*
width
;
for
(
size_t
i
=
0
;
i
<
batchSize
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
batchSize
;
++
i
)
{
size_t
offset
=
i
*
(
inTotalSize
/
batchSize
)
+
inOffset
;
size_t
offset
=
i
*
(
inTotalSize
/
batchSize
)
+
inOffset
;
const
MatrixPtr
inTmp
=
Matrix
::
create
(
const
MatrixPtr
inTmp
=
inMatrix
->
getData
()
+
offset
,
imgSize
,
channels
,
false
,
useGpu
);
Matrix
::
create
(
const_cast
<
real
*>
(
inMatrix
.
getData
())
+
offset
,
MatrixPtr
outTmp
=
imgSize
,
Matrix
::
create
(
outMatrix
->
getData
()
+
i
*
channels
*
imgSize
,
channels
,
false
,
useGpu
);
MatrixPtr
outTmp
=
Matrix
::
create
(
const_cast
<
real
*>
(
outMatrix
.
getData
())
+
i
*
channels
*
imgSize
,
channels
,
channels
,
imgSize
,
imgSize
,
false
,
false
,
...
@@ -99,9 +107,10 @@ real jaccardOverlap(const NormalizedBBox& bbox1, const NormalizedBBox& bbox2) {
...
@@ -99,9 +107,10 @@ real jaccardOverlap(const NormalizedBBox& bbox1, const NormalizedBBox& bbox2) {
}
}
}
}
v
ector
<
real
>
encodeBBoxWithVar
(
const
NormalizedBBox
&
priorBBox
,
v
oid
encodeBBoxWithVar
(
const
NormalizedBBox
&
priorBBox
,
const
vector
<
real
>
priorBBoxVar
,
const
vector
<
real
>
priorBBoxVar
,
const
NormalizedBBox
&
gtBBox
)
{
const
NormalizedBBox
&
gtBBox
,
vector
<
real
>&
outVec
)
{
real
priorBBoxWidth
=
priorBBox
.
getWidth
();
real
priorBBoxWidth
=
priorBBox
.
getWidth
();
real
priorBBoxHeight
=
priorBBox
.
getHeight
();
real
priorBBoxHeight
=
priorBBox
.
getHeight
();
real
priorBBoxCenterX
=
priorBBox
.
getCenterX
();
real
priorBBoxCenterX
=
priorBBox
.
getCenterX
();
...
@@ -112,17 +121,15 @@ vector<real> encodeBBoxWithVar(const NormalizedBBox& priorBBox,
...
@@ -112,17 +121,15 @@ vector<real> encodeBBoxWithVar(const NormalizedBBox& priorBBox,
real
gtBBoxCenterX
=
gtBBox
.
getCenterX
();
real
gtBBoxCenterX
=
gtBBox
.
getCenterX
();
real
gtBBoxCenterY
=
gtBBox
.
getCenterY
();
real
gtBBoxCenterY
=
gtBBox
.
getCenterY
();
vector
<
real
>
offsetParam
;
outVec
.
clear
()
;
o
ffsetParam
.
push_back
((
gtBBoxCenterX
-
priorBBoxCenterX
)
/
priorBBoxWidth
/
o
utVec
.
push_back
((
gtBBoxCenterX
-
priorBBoxCenterX
)
/
priorBBoxWidth
/
priorBBoxVar
[
0
]);
priorBBoxVar
[
0
]);
o
ffsetParam
.
push_back
((
gtBBoxCenterY
-
priorBBoxCenterY
)
/
priorBBoxHeight
/
o
utVec
.
push_back
((
gtBBoxCenterY
-
priorBBoxCenterY
)
/
priorBBoxHeight
/
priorBBoxVar
[
1
]);
priorBBoxVar
[
1
]);
o
ffsetParam
.
push_back
(
std
::
log
(
std
::
fabs
(
gtBBoxWidth
/
priorBBoxWidth
))
/
o
utVec
.
push_back
(
std
::
log
(
std
::
fabs
(
gtBBoxWidth
/
priorBBoxWidth
))
/
priorBBoxVar
[
2
]);
priorBBoxVar
[
2
]);
o
ffsetParam
.
push_back
(
std
::
log
(
std
::
fabs
(
gtBBoxHeight
/
priorBBoxHeight
))
/
o
utVec
.
push_back
(
std
::
log
(
std
::
fabs
(
gtBBoxHeight
/
priorBBoxHeight
))
/
priorBBoxVar
[
3
]);
priorBBoxVar
[
3
]);
return
offsetParam
;
}
}
NormalizedBBox
decodeBBoxWithVar
(
const
NormalizedBBox
&
priorBBox
,
NormalizedBBox
decodeBBoxWithVar
(
const
NormalizedBBox
&
priorBBox
,
...
@@ -318,9 +325,9 @@ void matchBBox(const vector<NormalizedBBox>& priorBBoxes,
...
@@ -318,9 +325,9 @@ void matchBBox(const vector<NormalizedBBox>& priorBBoxes,
}
}
pair
<
size_t
,
size_t
>
generateMatchIndices
(
pair
<
size_t
,
size_t
>
generateMatchIndices
(
const
Matrix
Ptr
priorValue
,
const
Matrix
&
priorValue
,
const
size_t
numPriorBBoxes
,
const
size_t
numPriorBBoxes
,
const
Matrix
Ptr
gtValue
,
const
Matrix
&
gtValue
,
const
int
*
gtStartPosPtr
,
const
int
*
gtStartPosPtr
,
const
size_t
seqNum
,
const
size_t
seqNum
,
const
vector
<
vector
<
real
>>&
maxConfScore
,
const
vector
<
vector
<
real
>>&
maxConfScore
,
...
@@ -331,7 +338,7 @@ pair<size_t, size_t> generateMatchIndices(
...
@@ -331,7 +338,7 @@ pair<size_t, size_t> generateMatchIndices(
vector
<
vector
<
int
>>*
matchIndicesVecPtr
,
vector
<
vector
<
int
>>*
matchIndicesVecPtr
,
vector
<
vector
<
int
>>*
negIndicesVecPtr
)
{
vector
<
vector
<
int
>>*
negIndicesVecPtr
)
{
vector
<
NormalizedBBox
>
priorBBoxes
;
// share same prior bboxes
vector
<
NormalizedBBox
>
priorBBoxes
;
// share same prior bboxes
getBBoxFromPriorData
(
priorValue
->
getData
(),
numPriorBBoxes
,
priorBBoxes
);
getBBoxFromPriorData
(
priorValue
.
getData
(),
numPriorBBoxes
,
priorBBoxes
);
size_t
totalPos
=
0
;
size_t
totalPos
=
0
;
size_t
totalNeg
=
0
;
size_t
totalNeg
=
0
;
for
(
size_t
n
=
0
;
n
<
batchSize
;
++
n
)
{
for
(
size_t
n
=
0
;
n
<
batchSize
;
++
n
)
{
...
@@ -349,7 +356,7 @@ pair<size_t, size_t> generateMatchIndices(
...
@@ -349,7 +356,7 @@ pair<size_t, size_t> generateMatchIndices(
}
}
vector
<
NormalizedBBox
>
gtBBoxes
;
vector
<
NormalizedBBox
>
gtBBoxes
;
getBBoxFromLabelData
(
getBBoxFromLabelData
(
gtValue
->
getData
()
+
gtStartPosPtr
[
n
]
*
6
,
numGTBBoxes
,
gtBBoxes
);
gtValue
.
getData
()
+
gtStartPosPtr
[
n
]
*
6
,
numGTBBoxes
,
gtBBoxes
);
matchBBox
(
matchBBox
(
priorBBoxes
,
gtBBoxes
,
overlapThreshold
,
&
matchIndices
,
&
matchOverlaps
);
priorBBoxes
,
gtBBoxes
,
overlapThreshold
,
&
matchIndices
,
&
matchOverlaps
);
...
@@ -523,7 +530,7 @@ void getDetectionOutput(const real* confData,
...
@@ -523,7 +530,7 @@ void getDetectionOutput(const real* confData,
const
size_t
batchSize
,
const
size_t
batchSize
,
const
vector
<
map
<
size_t
,
vector
<
size_t
>>>&
allIndices
,
const
vector
<
map
<
size_t
,
vector
<
size_t
>>>&
allIndices
,
const
vector
<
vector
<
NormalizedBBox
>>&
allDecodedBBoxes
,
const
vector
<
vector
<
NormalizedBBox
>>&
allDecodedBBoxes
,
Matrix
Ptr
out
)
{
Matrix
&
out
)
{
MatrixPtr
outBuffer
;
MatrixPtr
outBuffer
;
Matrix
::
resizeOrCreate
(
outBuffer
,
numKept
,
7
,
false
,
false
);
Matrix
::
resizeOrCreate
(
outBuffer
,
numKept
,
7
,
false
,
false
);
real
*
bufferData
=
outBuffer
->
getData
();
real
*
bufferData
=
outBuffer
->
getData
();
...
@@ -550,7 +557,7 @@ void getDetectionOutput(const real* confData,
...
@@ -550,7 +557,7 @@ void getDetectionOutput(const real* confData,
}
}
}
}
}
}
out
->
copyFrom
(
bufferData
,
numKept
*
7
);
out
.
copyFrom
(
bufferData
,
numKept
*
7
);
}
}
NormalizedBBox
clipBBox
(
const
NormalizedBBox
&
bbox
)
{
NormalizedBBox
clipBBox
(
const
NormalizedBBox
&
bbox
)
{
...
...
paddle/gserver/layers/DetectionUtil.h
浏览文件 @
5b5346ec
...
@@ -42,10 +42,12 @@ struct BBoxBase {
...
@@ -42,10 +42,12 @@ struct BBoxBase {
T
getSize
()
const
{
return
getWidth
()
*
getHeight
();
}
T
getSize
()
const
{
return
getWidth
()
*
getHeight
();
}
// coordinate of bounding box
T
xMin
;
T
xMin
;
T
yMin
;
T
yMin
;
T
xMax
;
T
xMax
;
T
yMax
;
T
yMax
;
// whether difficult object (e.g. object with heavy occlusion is difficult)
bool
isDifficult
;
bool
isDifficult
;
};
};
...
@@ -53,31 +55,31 @@ struct NormalizedBBox : BBoxBase<real> {
...
@@ -53,31 +55,31 @@ struct NormalizedBBox : BBoxBase<real> {
NormalizedBBox
()
:
BBoxBase
<
real
>
()
{}
NormalizedBBox
()
:
BBoxBase
<
real
>
()
{}
};
};
enum
PermMode
{
NCHWTONHWC
,
NHWCTO
NCHW
};
enum
PermMode
{
kNCHWToNHWC
,
kNHWCTo
NCHW
};
/**
/**
* @brief First permute input maxtrix then append to output matrix
* @brief First permute input maxtrix then append to output matrix
*/
*/
size_t
appendWithPermute
(
const
Matrix
Ptr
inMatrix
,
size_t
appendWithPermute
(
const
Matrix
&
inMatrix
,
size_t
height
,
size_t
height
,
size_t
width
,
size_t
width
,
size_t
outTotalSize
,
size_t
outTotalSize
,
size_t
outOffset
,
size_t
outOffset
,
size_t
batchSize
,
size_t
batchSize
,
Matrix
Ptr
outMatrix
,
Matrix
&
outMatrix
,
PermMode
permMode
,
PermMode
permMode
,
bool
useGpu
);
bool
useGpu
);
/**
/**
* @brief First permute input maxtrix then decompose to output
* @brief First permute input maxtrix then decompose to output
*/
*/
size_t
decomposeWithPermute
(
const
Matrix
Ptr
inMatrix
,
size_t
decomposeWithPermute
(
const
Matrix
&
inMatrix
,
size_t
height
,
size_t
height
,
size_t
width
,
size_t
width
,
size_t
totalSize
,
size_t
totalSize
,
size_t
offset
,
size_t
offset
,
size_t
batchSize
,
size_t
batchSize
,
Matrix
Ptr
outMatrix
,
Matrix
&
outMatrix
,
PermMode
permMode
,
PermMode
permMode
,
bool
useGpu
);
bool
useGpu
);
...
@@ -89,15 +91,17 @@ size_t decomposeWithPermute(const MatrixPtr inMatrix,
...
@@ -89,15 +91,17 @@ size_t decomposeWithPermute(const MatrixPtr inMatrix,
real
jaccardOverlap
(
const
NormalizedBBox
&
bbox1
,
const
NormalizedBBox
&
bbox2
);
real
jaccardOverlap
(
const
NormalizedBBox
&
bbox1
,
const
NormalizedBBox
&
bbox2
);
/**
/**
* @brief Compute offset parameters between prior bbox and groundtruth bbox
* @brief Compute offset parameters between prior bbox and ground
truth bbox
* and variances of prior bbox are considered
* and variances of prior bbox are considered
* @param priorBBox Input prior bbox
* @param priorBBox Input prior bbox
* @param priorBBoxVar Variance parameters of prior bbox
* @param priorBBoxVar Variance parameters of prior bbox
* @param gtBBox Groundtruth bbox
* @param gtBBox Groundtruth bbox
* @param outVec Output vector
*/
*/
v
ector
<
real
>
encodeBBoxWithVar
(
const
NormalizedBBox
&
priorBBox
,
v
oid
encodeBBoxWithVar
(
const
NormalizedBBox
&
priorBBox
,
const
vector
<
real
>
priorBBoxVar
,
const
vector
<
real
>
priorBBoxVar
,
const
NormalizedBBox
&
gtBBox
);
const
NormalizedBBox
&
gtBBox
,
vector
<
real
>&
outVec
);
/**
/**
* @brief Decode prior bbox with offset parameters
* @brief Decode prior bbox with offset parameters
...
@@ -194,9 +198,9 @@ negative examples
...
@@ -194,9 +198,9 @@ negative examples
* @param negIndicesVecPtr Save indices of negative prior bbox
* @param negIndicesVecPtr Save indices of negative prior bbox
*/
*/
pair
<
size_t
,
size_t
>
generateMatchIndices
(
pair
<
size_t
,
size_t
>
generateMatchIndices
(
const
Matrix
Ptr
priorValue
,
const
Matrix
&
priorValue
,
const
size_t
numPriorBBoxes
,
const
size_t
numPriorBBoxes
,
const
Matrix
Ptr
gtValue
,
const
Matrix
&
gtValue
,
const
int
*
gtStartPosPtr
,
const
int
*
gtStartPosPtr
,
const
size_t
seqNum
,
const
size_t
seqNum
,
const
vector
<
vector
<
real
>>&
maxConfScore
,
const
vector
<
vector
<
real
>>&
maxConfScore
,
...
@@ -298,7 +302,7 @@ void getDetectionOutput(const real* confData,
...
@@ -298,7 +302,7 @@ void getDetectionOutput(const real* confData,
const
size_t
batchSize
,
const
size_t
batchSize
,
const
vector
<
map
<
size_t
,
vector
<
size_t
>>>&
allIndices
,
const
vector
<
map
<
size_t
,
vector
<
size_t
>>>&
allIndices
,
const
vector
<
vector
<
NormalizedBBox
>>&
allDecodedBBoxes
,
const
vector
<
vector
<
NormalizedBBox
>>&
allDecodedBBoxes
,
Matrix
Ptr
out
);
Matrix
&
out
);
NormalizedBBox
clipBBox
(
const
NormalizedBBox
&
bbox
);
NormalizedBBox
clipBBox
(
const
NormalizedBBox
&
bbox
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录