Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
ff549527
O
Opencv
项目概览
Greenplum
/
Opencv
11 个月 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ff549527
编写于
2月 15, 2016
作者:
M
Marina Noskova
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Corrected spelling mistakes
上级
5496dedd
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
15 addition
and
16 deletion
+15
-16
modules/ml/include/opencv2/ml.hpp
modules/ml/include/opencv2/ml.hpp
+1
-1
modules/ml/src/svmsgd.cpp
modules/ml/src/svmsgd.cpp
+11
-12
modules/ml/test/test_svmsgd.cpp
modules/ml/test/test_svmsgd.cpp
+1
-1
samples/cpp/train_svmsgd.cpp
samples/cpp/train_svmsgd.cpp
+2
-2
未找到文件。
modules/ml/include/opencv2/ml.hpp
浏览文件 @
ff549527
...
...
@@ -1535,7 +1535,7 @@ The margin type may have one of the following values: \ref SOFT_MARGIN or \ref H
- You should use \ref HARD_MARGIN type, if you have linearly separable sets.
- You should use \ref SOFT_MARGIN type, if you have non-linearly separable sets or sets with outliers.
- In the general case (if you know nothing about linear
ly
separability of your sets), use SOFT_MARGIN.
- In the general case (if you know nothing about linear separability of your sets), use SOFT_MARGIN.
The other parameters may be described as follows:
- \f$\lambda\f$ parameter is responsible for weights decreasing at each step and for the strength of restrictions on outliers
...
...
modules/ml/src/svmsgd.cpp
浏览文件 @
ff549527
...
...
@@ -11,7 +11,7 @@
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Copyright (C) 201
4
, Itseez Inc, all rights reserved.
// Copyright (C) 201
6
, Itseez Inc, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
...
...
@@ -103,7 +103,7 @@ public:
CV_IMPL_PROPERTY_S
(
cv
::
TermCriteria
,
TermCriteria
,
params
.
termCrit
)
private:
void
updateWeights
(
InputArray
sample
,
bool
is
FirstClass
,
float
gamma
,
Mat
&
weights
);
void
updateWeights
(
InputArray
sample
,
bool
is
Positive
,
float
gamma
,
Mat
&
weights
);
std
::
pair
<
bool
,
bool
>
areClassesEmpty
(
Mat
responses
);
...
...
@@ -111,7 +111,7 @@ private:
void
readParams
(
const
FileNode
&
fn
);
static
inline
bool
is
FirstClass
(
float
val
)
{
return
val
>
0
;
}
static
inline
bool
is
Positive
(
float
val
)
{
return
val
>
0
;
}
static
void
normalizeSamples
(
Mat
&
matrix
,
Mat
&
average
,
float
&
multiplier
);
...
...
@@ -152,7 +152,7 @@ std::pair<bool,bool> SVMSGDImpl::areClassesEmpty(Mat responses)
for
(
int
index
=
0
;
index
<
limit_index
;
index
++
)
{
if
(
is
FirstClass
(
responses
.
at
<
float
>
(
index
)))
if
(
is
Positive
(
responses
.
at
<
float
>
(
index
)))
emptyInClasses
.
first
=
false
;
else
emptyInClasses
.
second
=
false
;
...
...
@@ -172,7 +172,7 @@ void SVMSGDImpl::normalizeSamples(Mat &samples, Mat &average, float &multiplier)
average
=
Mat
(
1
,
featuresCount
,
samples
.
type
());
for
(
int
featureIndex
=
0
;
featureIndex
<
featuresCount
;
featureIndex
++
)
{
Scalar
scalAverage
=
mean
(
samples
.
col
(
featureIndex
))
[
0
]
;
Scalar
scalAverage
=
mean
(
samples
.
col
(
featureIndex
));
average
.
at
<
float
>
(
featureIndex
)
=
static_cast
<
float
>
(
scalAverage
[
0
]);
}
...
...
@@ -190,13 +190,13 @@ void SVMSGDImpl::normalizeSamples(Mat &samples, Mat &average, float &multiplier)
void
SVMSGDImpl
::
makeExtendedTrainSamples
(
const
Mat
&
trainSamples
,
Mat
&
extendedTrainSamples
,
Mat
&
average
,
float
&
multiplier
)
{
Mat
normali
s
edTrainSamples
=
trainSamples
.
clone
();
int
samplesCount
=
normali
s
edTrainSamples
.
rows
;
Mat
normali
z
edTrainSamples
=
trainSamples
.
clone
();
int
samplesCount
=
normali
z
edTrainSamples
.
rows
;
normalizeSamples
(
normali
s
edTrainSamples
,
average
,
multiplier
);
normalizeSamples
(
normali
z
edTrainSamples
,
average
,
multiplier
);
Mat
onesCol
=
Mat
::
ones
(
samplesCount
,
1
,
CV_32F
);
cv
::
hconcat
(
normali
s
edTrainSamples
,
onesCol
,
extendedTrainSamples
);
cv
::
hconcat
(
normali
z
edTrainSamples
,
onesCol
,
extendedTrainSamples
);
}
void
SVMSGDImpl
::
updateWeights
(
InputArray
_sample
,
bool
firstClass
,
float
gamma
,
Mat
&
weights
)
...
...
@@ -231,7 +231,7 @@ float SVMSGDImpl::calcShift(InputArray _samples, InputArray _responses) const
Mat
currentSample
=
trainSamples
.
row
(
samplesIndex
);
float
dotProduct
=
static_cast
<
float
>
(
currentSample
.
dot
(
weights_
));
bool
firstClass
=
is
FirstClass
(
trainResponses
.
at
<
float
>
(
samplesIndex
));
bool
firstClass
=
is
Positive
(
trainResponses
.
at
<
float
>
(
samplesIndex
));
int
index
=
firstClass
?
0
:
1
;
float
signToMul
=
firstClass
?
1.
f
:
-
1.
f
;
float
curDistance
=
dotProduct
*
signToMul
;
...
...
@@ -297,11 +297,10 @@ bool SVMSGDImpl::train(const Ptr<TrainData>& data, int)
int
randomNumber
=
rng
.
uniform
(
0
,
extendedTrainSamplesCount
);
//generate sample number
Mat
currentSample
=
extendedTrainSamples
.
row
(
randomNumber
);
bool
firstClass
=
isFirstClass
(
trainResponses
.
at
<
float
>
(
randomNumber
));
float
gamma
=
params
.
gamma0
*
std
::
pow
((
1
+
params
.
lambda
*
params
.
gamma0
*
(
float
)
iter
),
(
-
params
.
c
));
//update gamma
updateWeights
(
currentSample
,
firstClass
,
gamma
,
extendedWeights
);
updateWeights
(
currentSample
,
isPositive
(
trainResponses
.
at
<
float
>
(
randomNumber
))
,
gamma
,
extendedWeights
);
//average weights (only for ASGD model)
if
(
params
.
svmsgdType
==
ASGD
)
...
...
modules/ml/test/test_svmsgd.cpp
浏览文件 @
ff549527
...
...
@@ -134,7 +134,7 @@ void CV_SVMSGDTrainTest::makeTestData(Mat weights, float shift)
{
int
testSamplesCount
=
100000
;
int
featureCount
=
weights
.
cols
;
cv
::
RNG
rng
(
0
);
cv
::
RNG
rng
(
42
);
testSamples
.
create
(
testSamplesCount
,
featureCount
,
CV_32FC1
);
for
(
int
featureIndex
=
0
;
featureIndex
<
featureCount
;
featureIndex
++
)
...
...
samples/cpp/train_svmsgd.cpp
浏览文件 @
ff549527
...
...
@@ -6,8 +6,6 @@
using
namespace
cv
;
using
namespace
cv
::
ml
;
#define WIDTH 841
#define HEIGHT 594
struct
Data
{
...
...
@@ -17,6 +15,8 @@ struct Data
Data
()
{
const
int
WIDTH
=
841
;
const
int
HEIGHT
=
594
;
img
=
Mat
::
zeros
(
HEIGHT
,
WIDTH
,
CV_8UC3
);
imshow
(
"Train svmsgd"
,
img
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录