Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
otb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Cabieces
otb
Commits
e33657b4
Commit
e33657b4
authored
9 years ago
by
Jordi Inglada
Browse files
Options
Downloads
Patches
Plain Diff
ENH: simplify the vote counting
parent
ecd14f9f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Modules/Learning/Supervised/include/otbCvRTrees.h
+11
-33
11 additions, 33 deletions
Modules/Learning/Supervised/include/otbCvRTrees.h
with
11 additions
and
33 deletions
Modules/Learning/Supervised/include/otbCvRTrees.h
+
11
−
33
View file @
e33657b4
...
...
@@ -23,50 +23,28 @@
class
CV_EXPORTS_W
CvRTreesWrapper
:
public
CvRTrees
{
struct
ClassVotes
{
unsigned
int
votes
;
unsigned
int
class_idx
;
};
struct
MoreVotes
{
bool
operator
()(
ClassVotes
a
,
ClassVotes
b
)
{
return
(
a
.
votes
>
b
.
votes
);
}
};
typedef
std
::
vector
<
ClassVotes
>
ClassVotesVectorType
;
public:
CV_WRAP
CvRTreesWrapper
(){};
CvRTreesWrapper
(){};
virtual
~
CvRTreesWrapper
(){};
const
int
get_nclasses
()
const
{
return
nclasses
;
};
// CV_WRAP virtual float predict(const cv::Mat& sample, const cv::Mat& missing = cv::Mat() ) const{return CvRTrees::predict(sample,missing);};
virtual
const
float
predict_confidence
(
const
cv
::
Mat
&
sample
,
const
cv
::
Mat
&
missing
=
cv
::
Mat
())
const
float
predict_confidence
(
const
cv
::
Mat
&
sample
,
const
cv
::
Mat
&
missing
=
cv
::
Mat
())
const
{
cv
::
AutoBuffer
<
int
>
_votes
(
nclasses
);
ClassVotesVectorType
classVotes
(
nclasses
);
std
::
vector
<
unsigned
int
>
classVotes
(
nclasses
);
for
(
int
k
=
0
;
k
<
ntrees
;
k
++
)
{
CvDTreeNode
*
predicted_node
=
trees
[
k
]
->
predict
(
sample
,
missing
);
int
class_idx
=
predicted_node
->
class_idx
;
CV_Assert
(
0
<=
class_idx
&&
class_idx
<
nclasses
);
classVotes
[
class_idx
].
votes
+=
1
;
classVotes
[
class_idx
].
class_idx
=
class_idx
;
++
classVotes
[
class_idx
];
}
std
::
nth_element
(
classVotes
.
begin
(),
classVotes
.
begin
()
+
1
,
classVotes
.
end
(),
MoreVotes
());
unsigned
int
maxVotes
=
classVotes
[
0
].
votes
;
unsigned
int
secondVotes
=
classVotes
[
2
].
votes
;
return
static_cast
<
float
>
(
maxVotes
-
secondVotes
)
/
ntrees
;
classVotes
.
end
(),
std
::
greater
<>
());
unsigned
int
maxVotes
=
classVotes
[
0
];
unsigned
int
secondVotes
=
classVotes
[
1
];
float
confidence
=
static_cast
<
float
>
(
maxVotes
-
secondVotes
)
/
ntrees
;
return
confidence
;
};
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment