Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
otb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
273
Issues
273
List
Boards
Labels
Service Desk
Milestones
Merge Requests
8
Merge Requests
8
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Main Repositories
otb
Commits
ec9b9e9f
Commit
ec9b9e9f
authored
Oct 30, 2015
by
Julien Michel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENH: Avoid possible division by zero and move methods body to a dedicated cxx file
parent
9e012a2d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
28 deletions
+57
-28
Modules/Learning/Supervised/include/otbCvRTreesWrapper.h
Modules/Learning/Supervised/include/otbCvRTreesWrapper.h
+3
-28
Modules/Learning/Supervised/src/CMakeLists.txt
Modules/Learning/Supervised/src/CMakeLists.txt
+1
-0
Modules/Learning/Supervised/src/otbCvRTreesWrapper.cxx
Modules/Learning/Supervised/src/otbCvRTreesWrapper.cxx
+53
-0
No files found.
Modules/Learning/Supervised/include/otbCvRTreesWrapper.h
View file @
ec9b9e9f
...
...
@@ -19,9 +19,6 @@
#define __otbCvRTreesWrapper_h
#include "otbOpenCVUtils.h"
#include <vector>
#include <algorithm>
namespace
otb
{
...
...
@@ -34,8 +31,8 @@ namespace otb
class
CV_EXPORTS_W
CvRTreesWrapper
:
public
CvRTrees
{
public:
CvRTreesWrapper
()
{}
;
virtual
~
CvRTreesWrapper
()
{}
;
CvRTreesWrapper
();
virtual
~
CvRTreesWrapper
();
/** Predict the confidence of the classifcation by computing the
difference in votes between the first and second most voted classes.
...
...
@@ -45,29 +42,7 @@ public:
*/
float
predict_confidence
(
const
cv
::
Mat
&
sample
,
const
cv
::
Mat
&
missing
=
cv
::
Mat
())
const
{
// Sanity check (division by ntrees later on)
if
(
ntrees
==
0
)
{
return
0.
;
}
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
];
}
// We only sort the 2 greatest elements
std
::
nth_element
(
classVotes
.
begin
(),
classVotes
.
begin
()
+
1
,
classVotes
.
end
(),
std
::
greater
<
unsigned
int
>
());
float
confidence
=
static_cast
<
float
>
(
classVotes
[
0
]
-
classVotes
[
1
])
/
ntrees
;
return
confidence
;
};
cv
::
Mat
())
const
;
};
}
...
...
Modules/Learning/Supervised/src/CMakeLists.txt
View file @
ec9b9e9f
set
(
OTBSupervised_SRC
otbCvRTreesWrapper.cxx
otbMachineLearningModelFactoryBase.cxx
otbMachineLearningUtils.cxx
)
...
...
Modules/Learning/Supervised/src/otbCvRTreesWrapper.cxx
0 → 100644
View file @
ec9b9e9f
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include "otbCvRTreesWrapper.h"
#include <vector>
#include <algorithm>
namespace
otb
{
CvRTreesWrapper
::
CvRTreesWrapper
(){}
CvRTreesWrapper
::~
CvRTreesWrapper
(){}
float
CvRTreesWrapper
::
predict_confidence
(
const
cv
::
Mat
&
sample
,
const
cv
::
Mat
&
missing
)
const
{
// Sanity check (division by ntrees later on)
if
(
ntrees
==
0
)
{
return
0.
;
}
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
];
}
// We only sort the 2 greatest elements
std
::
nth_element
(
classVotes
.
begin
(),
classVotes
.
begin
()
+
1
,
classVotes
.
end
(),
std
::
greater
<
unsigned
int
>
());
float
confidence
=
static_cast
<
float
>
(
classVotes
[
0
]
-
classVotes
[
1
])
/
ntrees
;
return
confidence
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment