Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Main Repositories
otb
Commits
ef2ae905
Commit
ef2ae905
authored
Apr 10, 2017
by
Guillaume Pasero
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
REFAC: generic LabelMapClassifier works with any ML model
parent
4997b3a0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
31 deletions
+31
-31
Modules/Learning/Supervised/include/otbLabelMapClassifier.h
Modules/Learning/Supervised/include/otbLabelMapClassifier.h
+20
-21
Modules/Learning/Supervised/include/otbLabelMapClassifier.txx
...les/Learning/Supervised/include/otbLabelMapClassifier.txx
+10
-10
Modules/Learning/Supervised/otb-module.cmake
Modules/Learning/Supervised/otb-module.cmake
+1
-0
No files found.
Modules/Learning/Supervised/include/otbLabelMapClassifier.h
View file @
ef2ae905
...
...
@@ -18,17 +18,17 @@
* limitations under the License.
*/
#ifndef otbLabelMap
SVM
Classifier_h
#define otbLabelMap
SVM
Classifier_h
#ifndef otbLabelMapClassifier_h
#define otbLabelMapClassifier_h
#include "itkInPlaceLabelMapFilter.h"
#include "otb
SVM
Model.h"
#include "otb
MachineLearning
Model.h"
#include "itkListSample.h"
#include "otbAttributesMapLabelObject.h"
namespace
otb
{
/** \class LabelMap
SVM
Classifier
/** \class LabelMapClassifier
* \brief Classify each LabelObject of the input LabelMap in place
*
* \sa otb::AttributesMapLabelObject
...
...
@@ -38,12 +38,12 @@ namespace otb {
* \ingroup OTBSVMLearning
*/
template
<
class
TInputLabelMap
>
class
ITK_EXPORT
LabelMap
SVM
Classifier
:
class
ITK_EXPORT
LabelMapClassifier
:
public
itk
::
InPlaceLabelMapFilter
<
TInputLabelMap
>
{
public:
/** Standard class typedefs. */
typedef
LabelMap
SVM
Classifier
Self
;
typedef
LabelMapClassifier
Self
;
typedef
itk
::
InPlaceLabelMapFilter
<
TInputLabelMap
>
Superclass
;
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
typedef
itk
::
SmartPointer
<
const
Self
>
ConstPointer
;
...
...
@@ -56,27 +56,26 @@ public:
typedef
typename
LabelObjectType
::
AttributesValueType
AttributesValueType
;
typedef
typename
LabelObjectType
::
ClassLabelType
ClassLabelType
;
typedef
std
::
vector
<
AttributesValueType
>
MeasurementVectorType
;
typedef
Functor
::
AttributesMapMeasurementFunctor
<
LabelObjectType
,
MeasurementVectorType
>
MeasurementFunctorType
;
/** ImageDimension constants */
itkStaticConstMacro
(
InputImageDimension
,
unsigned
int
,
TInputLabelMap
::
ImageDimension
);
/** Type definitions for the SVM Model. */
typedef
SVMModel
<
AttributesValueType
,
ClassLabelType
>
SVMModelType
;
typedef
typename
SVMModelType
::
Pointer
SVMModelPointer
;
/** Type definitions for the learning model. */
typedef
MachineLearningModel
<
AttributesValueType
,
ClassLabelType
>
ModelType
;
typedef
typename
ModelType
::
Pointer
ModelPointer
;
typedef
typename
ModelType
::
InputSampleType
MeasurementVectorType
;
typedef
Functor
::
AttributesMapMeasurementFunctor
<
LabelObjectType
,
MeasurementVectorType
>
MeasurementFunctorType
;
/** Standard New method. */
itkNewMacro
(
Self
);
/** Runtime information support. */
itkTypeMacro
(
LabelMap
SVM
Classifier
,
itkTypeMacro
(
LabelMapClassifier
,
itk
::
InPlaceLabelMapFilter
);
itkSetObjectMacro
(
Model
,
SVM
ModelType
);
itkSetObjectMacro
(
Model
,
ModelType
);
void
SetMeasurementFunctor
(
const
MeasurementFunctorType
&
functor
)
{
...
...
@@ -89,8 +88,8 @@ public:
}
protected:
LabelMap
SVM
Classifier
();
~
LabelMap
SVM
Classifier
()
ITK_OVERRIDE
{};
LabelMapClassifier
();
~
LabelMapClassifier
()
ITK_OVERRIDE
{};
void
ThreadedProcessLabelObject
(
LabelObjectType
*
labelObject
)
ITK_OVERRIDE
;
...
...
@@ -98,11 +97,11 @@ protected:
private:
LabelMap
SVM
Classifier
(
const
Self
&
);
//purposely not implemented
LabelMapClassifier
(
const
Self
&
);
//purposely not implemented
void
operator
=
(
const
Self
&
);
//purposely not implemented
/** The
SVM
model used for classification */
SVM
ModelPointer
m_Model
;
/** The
learning
model used for classification */
ModelPointer
m_Model
;
/** The functor used to build the measurement vector */
MeasurementFunctorType
m_MeasurementFunctor
;
...
...
@@ -112,7 +111,7 @@ private:
}
// end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbLabelMap
SVM
Classifier.txx"
#include "otbLabelMapClassifier.txx"
#endif
#endif
...
...
Modules/Learning/Supervised/include/otbLabelMapClassifier.txx
View file @
ef2ae905
...
...
@@ -18,27 +18,27 @@
* limitations under the License.
*/
#ifndef otbLabelMap
SVM
Classifier_txx
#define otbLabelMap
SVM
Classifier_txx
#ifndef otbLabelMapClassifier_txx
#define otbLabelMapClassifier_txx
#include "otbLabelMap
SVM
Classifier.h"
#include "otbLabelMapClassifier.h"
namespace otb {
template <class TInputImage>
LabelMap
SVM
Classifier<TInputImage>
::LabelMap
SVM
Classifier()
LabelMapClassifier<TInputImage>
::LabelMapClassifier()
{
// Force to single-threaded
(SVMM
odel is not thread
-
safe
)
// Force to single-threaded
in case the learning m
odel is not thread
safe
// This way, we benefit of the LabelMapFilter design and only need
// to implement ThreadedProcessLabelObject
this->SetNumberOfThreads(1);
this->SetNumberOfThreads(1);
// TODO : check if still needed
}
template<class TInputImage>
void
LabelMap
SVM
Classifier<TInputImage>
LabelMapClassifier<TInputImage>
::ReleaseInputs( )
{
// by pass itk::InPlaceLabelMapFilter::ReleaseInputs() implementation,
...
...
@@ -48,10 +48,10 @@ LabelMapSVMClassifier<TInputImage>
template<class TInputImage>
void
LabelMap
SVM
Classifier<TInputImage>
LabelMapClassifier<TInputImage>
::ThreadedProcessLabelObject( LabelObjectType * labelObject )
{
ClassLabelType classLabel = m_Model->
EvaluateLabel
(m_MeasurementFunctor(labelObject));
ClassLabelType classLabel =
(
m_Model->
Predict
(m_MeasurementFunctor(labelObject))
)[0]
;
labelObject->SetClassLabel(classLabel);
}
...
...
Modules/Learning/Supervised/otb-module.cmake
View file @
ef2ae905
...
...
@@ -29,6 +29,7 @@ ENABLE_SHARED
OTBCommon
OTBITK
OTBImageBase
OTBLabelMap
OPTIONAL_DEPENDS
OTBOpenCV
...
...
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