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
David Youssefi
otb
Commits
3b49c568
Commit
3b49c568
authored
17 years ago
by
Thomas Feuvrier
Browse files
Options
Downloads
Patches
Plain Diff
Suppression de variable de classe non utilisées:
Sample VectorLabel
parent
db009d21
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Code/Learning/otbSVMClassifier.h
+3
-27
3 additions, 27 deletions
Code/Learning/otbSVMClassifier.h
Code/Learning/otbSVMClassifier.txx
+12
-160
12 additions, 160 deletions
Code/Learning/otbSVMClassifier.txx
with
15 additions
and
187 deletions
Code/Learning/otbSVMClassifier.h
+
3
−
27
View file @
3b49c568
...
...
@@ -74,34 +74,15 @@ public:
typedef
typename
Superclass
::
MembershipFunctionPointerVector
MembershipFunctionPointerVector
;
// FIXME : typedef TLabel ClassLabelType ;
typedef
unsigned
int
ClassLabelType
;
typedef
std
::
vector
<
ClassLabelType
>
ClassLabelVectorType
;
/** typedef for label type */
typedef
TLabel
ClassLabelType
;
// /** Sets the target data that will be classified by this */
// void SetSample(const TSample* sample) ;
// /** Returns the target data */
// const TSample* GetSample() const;
// /** Sets the user given class labels for membership functions.
// * If users do not provide class labels for membership functions by calling
// * this function, then the index of the membership function vector for a
// * membership function will be used as class label of measurement vectors
// * belong to the membership function */
// void SetMembershipFunctionClassLabels( ClassLabelVectorType& labels) ;
// /** Gets the user given class labels */
// ClassLabelVectorType& GetMembershipFunctionClassLabels()
// { return m_ClassLabels ; }
// /** Returns the classification result */
/** Returns the classification result */
OutputType
*
GetOutput
()
;
/** Type definitions for the SVM Model. */
typedef
SVMModel
<
InputPixelType
,
TLabel
>
SVMModelType
;
typedef
typename
SVMModelType
::
Pointer
SVMModelPointer
;
...
...
@@ -123,15 +104,10 @@ protected:
void
DoClassification
()
;
private
:
/** Target data sample pointer*/
const
TSample
*
m_Sample
;
/** Output pointer (MembershipSample) */
typename
OutputType
::
Pointer
m_Output
;
/** User given class labels for membership functions */
ClassLabelVectorType
m_ClassLabels
;
SVMModelPointer
m_Model
;
}
;
// end of class
...
...
This diff is collapsed.
Click to expand it.
Code/Learning/otbSVMClassifier.txx
+
12
−
160
View file @
3b49c568
...
...
@@ -27,7 +27,6 @@ template< class TSample, class TLabel >
SVMClassifier< TSample, TLabel >
::SVMClassifier()
{
m_Sample = 0 ;
m_Output = OutputType::New() ;
m_Model = SVMModelType::New();
}
...
...
@@ -38,51 +37,8 @@ SVMClassifier< TSample, TLabel >
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os,indent);
// os << indent << "Sample: " ;
// if ( m_Sample != 0 )
// {
// os << m_Sample << std::endl;
// }
// else
// {
// os << "not set." << std::endl ;
// }
// os << indent << "Output: " << m_Output << std::endl;
}
// template< class TSample, class TLabel >
// void
// SVMClassifier< TSample, TLabel >
// ::SetSample(const TSample* sample)
// {
// otbMsgDebugMacro( << "SVMClassifier::SetSample enter" );
// if ( m_Sample != sample )
// {
// m_Sample = sample ;
// m_Output->SetSample(sample) ;
// }
// otbMsgDebugMacro( << "SVMClassifier::SetSample exit" );
// }
// template< class TSample, class TLabel >
// const TSample*
// SVMClassifier< TSample, TLabel >
// ::GetSample() const
// {
// return m_Sample ;
// }
// template< class TSample, class TLabel >
// void
// SVMClassifier< TSample, TLabel >
// ::SetMembershipFunctionClassLabels(ClassLabelVectorType& labels)
// {
// m_ClassLabels = labels ;
// }
template< class TSample, class TLabel >
void
SVMClassifier< TSample, TLabel >
...
...
@@ -99,26 +55,18 @@ SVMClassifier< TSample, TLabel >
::GenerateData()
{
// otbMsgDebugMacro( << "Before Resize 0" );
/* unsigned int i ;
typename TSample::ConstIterator iter = this->GetSample()->Begin() ;
typename TSample::ConstIterator end = this->GetSample()->End() ;
typename TSample::MeasurementVectorType measurements ;
*/
// otbMsgDebugMacro( << "Before Resize " );
m_Output->SetSample(this->GetSample()) ;
otbMsgDe
bug
Macro( << "m_Output " << m_Output );
otbMsgDe
v
Macro( << "m_Output " << m_Output );
m_Output->Resize( this->GetSample()->Size() ) ;
otbMsgDe
bug
Macro( << "Resize to " << this->GetSample()->Size() );
otbMsgDe
bug
Macro( << "Resize to " << m_Output->GetSample()->Size() );
otbMsgDe
v
Macro( << "Resize to " << this->GetSample()->Size() );
otbMsgDe
v
Macro( << "Resize to " << m_Output->GetSample()->Size() );
//std::vector< double > discriminantScores ;
unsigned int numberOfClasses = this->GetNumberOfClasses() ;
otbMsgDe
bug
Macro( << "NbClass " << numberOfClasses );
otbMsgDe
v
Macro( << "NbClass " << numberOfClasses );
//discriminantScores.resize(numberOfClasses) ;
//unsigned int classLabel ;
...
...
@@ -128,41 +76,10 @@ SVMClassifier< TSample, TLabel >
/*typename Superclass::DecisionRuleType::Pointer rule =
this->GetDecisionRule() ;*/
otbMsgDe
bug
Macro( << "Do Classif " );
otbMsgDe
v
Macro( << "Do Classif " );
this->DoClassification();
otbMsgDebugMacro( << "End of classif" );
// if ( m_ClassLabels.size() != this->GetNumberOfMembershipFunctions() )
// {
// while (iter != end)
// {
// measurements = iter.GetMeasurementVector() ;
// for (i = 0 ; i < numberOfClasses ; i++)
// {
// discriminantScores[i] =
// (this->GetMembershipFunction(i))->Evaluate(measurements) ;
// }
// classLabel = rule->Evaluate(discriminantScores) ;
// m_Output->AddInstance(classLabel, iter.GetInstanceIdentifier()) ;
// ++iter ;
// }
// }
// else
// {
// while (iter != end)
// {
// measurements = iter.GetMeasurementVector() ;
// for (i = 0 ; i < numberOfClasses ; i++)
// {
// discriminantScores[i] =
// (this->GetMembershipFunction(i))->Evaluate(measurements) ;
// }
// classLabel = rule->Evaluate(discriminantScores) ;
// m_Output->AddInstance(m_ClassLabels[classLabel],
// iter.GetInstanceIdentifier()) ;
// ++iter ;
// }
// }
otbMsgDevMacro( << "End of classif" );
}
template< class TSample, class TLabel >
...
...
@@ -203,7 +120,7 @@ SVMClassifier< TSample, TLabel >
x = new svm_node[numberOfComponentsPerSample+1];//m_Model->GetXSpace();
otbMsgDe
bug
Macro( << "XSpace Allocated" );
otbMsgDe
v
Macro( << "XSpace Allocated" );
if(svm_check_probability_model(model)==0)
{
throw itk::ExceptionObject(__FILE__, __LINE__,
...
...
@@ -212,10 +129,10 @@ SVMClassifier< TSample, TLabel >
}
int svm_type=svm_get_svm_type(model);
otbMsgDe
bug
Macro( << "SVM Type = " << svm_type );
otbMsgDe
v
Macro( << "SVM Type = " << svm_type );
int nr_class=svm_get_nr_class(model);
otbMsgDe
bug
Macro( << "SVM nr_class = " << nr_class );
otbMsgDe
v
Macro( << "SVM nr_class = " << nr_class );
int *labels=(int *) malloc(nr_class*sizeof(int));
double *prob_estimates=NULL;
...
...
@@ -231,109 +148,52 @@ SVMClassifier< TSample, TLabel >
prob_estimates = (double *) malloc(nr_class*sizeof(double));
}
/*fprintf(output,"labels");
for(j=0;j<nr_class;j++)
fprintf(output," %d",labels[j]);
fprintf(output,"\n");*/
}
// while(1)
otbMsgDe
bug
Macro( << "Starting iterations " );
otbMsgDe
v
Macro( << "Starting iterations " );
while (iter != end && iterO != endO)
{
int i = 0;
double v;
/*
double target;
int c;
if (fscanf(input,"%lf",&target)==EOF)
break;*/
// while(1)
// {
// if(i>=max_nr_attr-1) // need one more for index = -1
// {
// max_nr_attr *= 2;
// x = (struct svm_node *) realloc(x,max_nr_attr*sizeof(struct svm_node));
// }
// do {
// c = getc(input);
// if(c=='\n' || c==EOF) goto out2;
// } while(isspace(c));
// ungetc(c,input);
// fscanf(input,"%d:%lf",&x[i].index,&x[i].value);
// ++i;
// }
// out2:
// x[i++].index = -1;
measurements = iter.GetMeasurementVector() ;
// otbMsgDe
bug
Macro( << "Loop on components " << svm_type );
// otbMsgDe
v
Macro( << "Loop on components " << svm_type );
for(i=0; i<numberOfComponentsPerSample; i++)
{
// otbMsgDebugMacro( << i << " " << measurements[i] );
// otbMsgDebugMacro( << "Index "<< x[i].index );
// otbMsgDebugMacro( << "Value "<< x[i].value );
x[i].index = i+1 ;
x[i].value = measurements[i];
// otbMsgDebugMacro( << "Index "<< x[i].index );
// otbMsgDebugMacro( << "Value "<< x[i].value );
// otbMsgDebugMacro( << "-------------------" );
}
x[i].index = -1;
// otbMsgDebugMacro( << "Starting prediction" );
if (predict_probability && (svm_type==C_SVC || svm_type==NU_SVC))
{
// otbMsgDebugMacro( << "With predict" );
v = svm_predict_probability(model,x,prob_estimates);
// otbMsgDebugMacro( << "Value : " << v );
/*fprintf(output,"%g ",v);
for(j=0;j<nr_class;j++)
fprintf(output,"%g ",prob_estimates[j]);
fprintf(output,"\n");*/
}
else
{
// otbMsgDebugMacro( << "Without predict" );
v = svm_predict(model,x);
// otbMsgDebugMacro( << "Value : " << v );
//fprintf(output,"%g\n",v);
}
ClassLabelType classLabel;
// if(nr_class == 2)
// classLabel = static_cast<ClassLabelType>(v+2);
// else
classLabel = static_cast<ClassLabelType>(v);
// otbMsgDebugMacro( << "Add instance " << classLabel );
// otbMsgDebugMacro( << "Add instance ident " << iterO.GetInstanceIdentifier() );
m_Output->AddInstance(classLabel, iterO.GetInstanceIdentifier()) ;
// otbMsgDebugMacro( << "After add instance " << iterO.GetClassLabel() );
++iter;
++iterO;
}
// otbMsgDebugMacro( << "End of iterations " );
if(predict_probability)
{
free(prob_estimates);
free(labels);
}
// otbMsgDebugMacro( << "End of iterations and free" );
// free(x);
delete [] x;
}
...
...
@@ -341,11 +201,3 @@ delete [] x;
} // end of namespace otb
#endif
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