Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
74c87a26
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,发现更多精彩内容 >>
提交
74c87a26
编写于
2月 25, 2016
作者:
M
Marina Noskova
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Delete function areClassesEmpty().
上级
068677ad
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
12 addition
and
46 deletion
+12
-46
modules/ml/include/opencv2/ml.hpp
modules/ml/include/opencv2/ml.hpp
+2
-5
modules/ml/src/svmsgd.cpp
modules/ml/src/svmsgd.cpp
+10
-38
modules/ml/test/test_svmsgd.cpp
modules/ml/test/test_svmsgd.cpp
+0
-2
samples/cpp/train_svmsgd.cpp
samples/cpp/train_svmsgd.cpp
+0
-1
未找到文件。
modules/ml/include/opencv2/ml.hpp
浏览文件 @
74c87a26
...
...
@@ -1507,7 +1507,7 @@ public:
SVMSGD provides a fast and easy-to-use implementation of the SVM classifier using the Stochastic Gradient Descent approach,
as presented in @cite bottou2010large.
The classifier has
5 parameters. These are
The classifier has
following parameters:
- model type,
- margin type,
- margin regularization (\f$\lambda\f$),
...
...
@@ -1567,11 +1567,8 @@ To use SVMSGD algorithm do as follows:
// Create empty object
cv::Ptr<SVMSGD> svmsgd = SVMSGD::create();
// Set parameters
svmsgd->setOptimalParameters();
// Train the Stochastic Gradient Descent SVM
SvmS
gd->train(trainData);
svms
gd->train(trainData);
// Predict labels for the new samples
svmsgd->predict(samples, responses);
...
...
modules/ml/src/svmsgd.cpp
浏览文件 @
74c87a26
...
...
@@ -99,8 +99,6 @@ public:
private:
void
updateWeights
(
InputArray
sample
,
bool
isPositive
,
float
stepSize
,
Mat
&
weights
);
std
::
pair
<
bool
,
bool
>
areClassesEmpty
(
Mat
responses
);
void
writeParams
(
FileStorage
&
fs
)
const
;
void
readParams
(
const
FileNode
&
fn
);
...
...
@@ -138,26 +136,6 @@ Ptr<SVMSGD> SVMSGD::create()
return
makePtr
<
SVMSGDImpl
>
();
}
std
::
pair
<
bool
,
bool
>
SVMSGDImpl
::
areClassesEmpty
(
Mat
responses
)
{
CV_Assert
(
responses
.
cols
==
1
||
responses
.
rows
==
1
);
std
::
pair
<
bool
,
bool
>
emptyInClasses
(
true
,
true
);
int
limitIndex
=
responses
.
rows
;
for
(
int
index
=
0
;
index
<
limitIndex
;
index
++
)
{
if
(
isPositive
(
responses
.
at
<
float
>
(
index
)))
emptyInClasses
.
first
=
false
;
else
emptyInClasses
.
second
=
false
;
if
(
!
emptyInClasses
.
first
&&
!
emptyInClasses
.
second
)
break
;
}
return
emptyInClasses
;
}
void
SVMSGDImpl
::
normalizeSamples
(
Mat
&
samples
,
Mat
&
average
,
float
&
multiplier
)
{
int
featuresCount
=
samples
.
cols
;
...
...
@@ -248,16 +226,20 @@ bool SVMSGDImpl::train(const Ptr<TrainData>& data, int)
int
featureCount
=
trainSamples
.
cols
;
Mat
trainResponses
=
data
->
getTrainResponses
();
// (trainSamplesCount x 1) matrix
std
::
pair
<
bool
,
bool
>
areEmpty
=
areClassesEmpty
(
trainResponse
s
);
CV_Assert
(
trainResponses
.
rows
==
trainSamples
.
row
s
);
if
(
areEmpty
.
first
&&
areEmpty
.
second
)
if
(
trainResponses
.
empty
()
)
{
return
false
;
}
if
(
areEmpty
.
first
||
areEmpty
.
second
)
int
positiveCount
=
countNonZero
(
trainResponses
>=
0
);
int
negativeCount
=
countNonZero
(
trainResponses
<
0
);
if
(
positiveCount
<=
0
||
negativeCount
<=
0
)
{
weights_
=
Mat
::
zeros
(
1
,
featureCount
,
CV_32F
);
shift_
=
areEmpty
.
first
?
-
1.
f
:
1.
f
;
shift_
=
(
positiveCount
>
0
)
?
1.
f
:
-
1.
f
;
return
true
;
}
...
...
@@ -340,7 +322,7 @@ float SVMSGDImpl::predict( InputArray _samples, OutputArray _results, int ) cons
int
nSamples
=
samples
.
rows
;
cv
::
Mat
results
;
CV_Assert
(
samples
.
cols
==
weights_
.
cols
&&
samples
.
type
()
==
CV_32F
);
CV_Assert
(
samples
.
cols
==
weights_
.
cols
&&
samples
.
type
()
==
CV_32F
C1
);
if
(
_results
.
needed
()
)
{
...
...
@@ -498,17 +480,7 @@ void SVMSGDImpl::clear()
SVMSGDImpl
::
SVMSGDImpl
()
{
clear
();
params
.
svmsgdType
=
-
1
;
params
.
marginType
=
-
1
;
// Parameters for learning
params
.
marginRegularization
=
0
;
// regularization
params
.
initialStepSize
=
0
;
// learning rate (ideally should be large at beginning and decay each iteration)
params
.
stepDecreasingPower
=
0
;
TermCriteria
_termCrit
(
TermCriteria
::
COUNT
+
TermCriteria
::
EPS
,
0
,
0
);
params
.
termCrit
=
_termCrit
;
setOptimalParameters
();
}
void
SVMSGDImpl
::
setOptimalParameters
(
int
svmsgdType
,
int
marginType
)
...
...
modules/ml/test/test_svmsgd.cpp
浏览文件 @
74c87a26
...
...
@@ -182,8 +182,6 @@ void CV_SVMSGDTrainTest::run( int /*start_from*/ )
{
cv
::
Ptr
<
SVMSGD
>
svmsgd
=
SVMSGD
::
create
();
svmsgd
->
setOptimalParameters
();
svmsgd
->
train
(
data
);
Mat
responses
;
...
...
samples/cpp/train_svmsgd.cpp
浏览文件 @
74c87a26
...
...
@@ -46,7 +46,6 @@ void addPointRetrainAndRedraw(Data &data, int x, int y, int response);
bool
doTrain
(
const
Mat
samples
,
const
Mat
responses
,
Mat
&
weights
,
float
&
shift
)
{
cv
::
Ptr
<
SVMSGD
>
svmsgd
=
SVMSGD
::
create
();
svmsgd
->
setOptimalParameters
();
cv
::
Ptr
<
TrainData
>
trainData
=
TrainData
::
create
(
samples
,
cv
::
ml
::
ROW_SAMPLE
,
responses
);
svmsgd
->
train
(
trainData
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录