Commit 4f474c69 authored by Guillaume Pasero's avatar Guillaume Pasero

TEST: fix tests for SVM classes

parent 01e15a37
......@@ -25,6 +25,7 @@ otbObjectDetectionTestDriver.cxx
otbLabeledSampleLocalizationGenerator.cxx
otbStandardMetaImageFunctionBuilder.cxx
otbDescriptorsListSampleGenerator.cxx
otbObjectDetectionClassifier.cxx
)
add_executable(otbObjectDetectionTestDriver ${OTBObjectDetectionTests})
......@@ -97,3 +98,32 @@ otb_add_test(NAME odTuDescriptorsListSampleGeneratorNew COMMAND otbObjectDetecti
otbDescriptorsListSampleGeneratorNew
)
otb_add_test(NAME odTuObjectDetectionClassifierNew COMMAND otbObjectDetectionTestDriver
otbObjectDetectionClassifierNew
)
otb_add_test(NAME odTvObjectDetectionClassifierStreaming COMMAND otbObjectDetectionTestDriver
--compare-ascii ${NOTOL}
${BASELINE_FILES}/TvObjectDetectionClassifierOutput.txt
${TEMP}/TvObjectDetectionClassifierOutputStreaming.txt
otbObjectDetectionClassifier
${INPUTDATA}/ObjectReco/Boats/maur_B010202_01_extract_amplitude.tif
${INPUTDATA}/ObjectReco/Boats/FeatureStats_RadiometricMoments_amplitude.xml
${BASELINE_FILES}/TvDescriptorsSVMModelCreation.svm
${TEMP}/TvObjectDetectionClassifierOutputStreaming.txt
50 # streaming
5 # neighborhood radius
)
otb_add_test(NAME odTvObjectDetectionClassifier COMMAND otbObjectDetectionTestDriver
--compare-ascii ${NOTOL}
${BASELINE_FILES}/TvObjectDetectionClassifierOutput.txt
${TEMP}/TvObjectDetectionClassifierOutput.txt
otbObjectDetectionClassifier
${INPUTDATA}/ObjectReco/Boats/maur_B010202_01_extract_amplitude.tif
${INPUTDATA}/ObjectReco/Boats/FeatureStats_RadiometricMoments_amplitude.xml
${BASELINE_FILES}/TvDescriptorsSVMModelCreation.svm
${TEMP}/TvObjectDetectionClassifierOutput.txt
0 # streaming
5 # neighborhood radius
)
......@@ -32,6 +32,7 @@
#include "otbImageFunctionAdaptor.h"
#include "otbStatisticsXMLFileReader.h"
#include "itkPreOrderTreeIterator.h"
#include "otbLibSVMMachineLearningModel.h"
const unsigned int Dimension = 2;
typedef int LabelType;
......@@ -56,8 +57,8 @@ typedef otb::ImageFunctionAdaptor<FunctionType, FunctionPrecisionType> AdaptedF
typedef otb::ImageFileReader<ImageType> ImageReaderType;
typedef ObjectDetectionClassifierType::SVMModelType SVMModelType;
typedef ObjectDetectionClassifierType::SVMModelPointerType SVMModelPointerType;
typedef otb::LibSVMMachineLearningModel<PixelType,LabelType> SVMModelType;
typedef SVMModelType::Pointer SVMModelPointerType;
typedef otb::StatisticsXMLFileReader<AdaptedFunctionType::OutputType> StatisticsXMLFileReaderType;
......@@ -118,7 +119,7 @@ int otbObjectDetectionClassifier(int argc, char* argv[])
SVMModelPointerType svmModel = SVMModelType::New();
svmModel->LoadModel(inputSVMModel);
svmModel->Load(inputSVMModel);
AdaptedFunctionType::Pointer descriptorsFunction = AdaptedFunctionType::New();
descriptorsFunction->SetInputImage(imageReader->GetOutput());
......@@ -127,7 +128,7 @@ int otbObjectDetectionClassifier(int argc, char* argv[])
ObjectDetectionClassifierType::Pointer classifier = ObjectDetectionClassifierType::New();
classifier->SetInputImage(imageReader->GetOutput());
classifier->SetNeighborhoodRadius(neighborhood);
classifier->SetSVMModel(svmModel);
classifier->SetModel(svmModel);
classifier->SetDescriptorsFunction(descriptorsFunction);
classifier->SetNoClassLabel(0);
classifier->SetClassKey("Class");
......
......@@ -29,4 +29,6 @@ void RegisterTests()
REGISTER_TEST(otbDescriptorsListSampleGeneratorNew);
REGISTER_TEST(otbDescriptorsListSampleGenerator);
REGISTER_TEST(otbDescriptorsSVMModelCreation);
REGISTER_TEST(otbObjectDetectionClassifierNew);
REGISTER_TEST(otbObjectDetectionClassifier);
}
......@@ -27,6 +27,11 @@ otbMachineLearningModelCanRead.cxx
otbTrainMachineLearningModel.cxx
otbImageClassificationFilter.cxx
otbMachineLearningRegressionTests.cxx
otbExhaustiveExponentialOptimizerNew.cxx
otbExhaustiveExponentialOptimizerTest.cxx
otbLabelMapClassifier.cxx
otbSVMCrossValidationCostFunctionNew.cxx
otbSVMMarginSampler.cxx
)
if(OTB_USE_SHARK)
......@@ -70,6 +75,16 @@ otb_add_test(NAME leTvConfusionMatrixConcatenateTest COMMAND otbSupervisedTestDr
${INPUTDATA}/Classification/QB_1_ortho_C5.csv
${INPUTDATA}/Classification/QB_1_ortho_C6.csv)
otb_add_test(NAME leTuExhaustiveExponentialOptimizerNew COMMAND otbSupervisedTestDriver
otbExhaustiveExponentialOptimizerNew)
otb_add_test(NAME leTvExhaustiveExponentialOptimizerTest COMMAND otbSupervisedTestDriver
--compare-ascii ${NOTOL}
${BASELINE_FILES}/leTvExhaustiveExponentialOptimizerOutput.txt
${TEMP}/leTvExhaustiveExponentialOptimizerTestOutput.txt
otbExhaustiveExponentialOptimizerTest
${TEMP}/leTvExhaustiveExponentialOptimizerTestOutput.txt)
if(OTB_USE_LIBSVM)
include(tests-libsvm.cmake)
endif()
......
......@@ -31,8 +31,8 @@
#include "otbShapeAttributesLabelMapFilter.h"
#include "otbBandsStatisticsAttributesLabelMapFilter.h"
#include "otbLabelMapWithClassLabelToLabeledSampleListFilter.h"
#include "otbSVMSampleListModelEstimator.h"
#include "otbLabelMapSVMClassifier.h"
#include "otbLibSVMMachineLearningModel.h"
#include "otbLabelMapClassifier.h"
#include "otbLabelMapWithClassLabelToClassLabelImageFilter.h"
const unsigned int Dimension = 2;
......@@ -60,12 +60,9 @@ typedef itk::Statistics::ListSample<VectorType> ListSampleType;
typedef itk::Statistics::ListSample<TrainingVectorType> TrainingListSampleType;
typedef otb::LabelMapWithClassLabelToLabeledSampleListFilter<LabelMapType, ListSampleType, TrainingListSampleType>
ListSampleFilterType;
typedef otb::LibSVMMachineLearningModel<double,LabelType> SVMType;
typedef otb::Functor::VariableLengthVectorToMeasurementVectorFunctor<VectorType> MeasurementVectorFunctorType;
typedef otb::SVMSampleListModelEstimator<ListSampleType, TrainingListSampleType,
MeasurementVectorFunctorType> SVMEstimatorType;
typedef otb::LabelMapSVMClassifier<LabelMapType> ClassifierType;
typedef otb::LabelMapClassifier<LabelMapType> ClassifierType;
typedef otb::LabelMapWithClassLabelToClassLabelImageFilter
<LabelMapType, LabeledImageType> ClassifImageGeneratorType;
......@@ -78,13 +75,13 @@ LabelObjectType::Pointer makeTrainingSample(LabelMapType* labelMap, LabelType la
return newLabelObject;
}
int otbLabelMapSVMClassifierNew(int itkNotUsed(argc), char * itkNotUsed(argv)[])
int otbLabelMapClassifierNew(int itkNotUsed(argc), char * itkNotUsed(argv)[])
{
ClassifierType::Pointer classifier = ClassifierType::New();
return EXIT_SUCCESS;
}
int otbLabelMapSVMClassifier(int itkNotUsed(argc), char * argv[])
int otbLabelMapClassifier(int itkNotUsed(argc), char * argv[])
{
const char * infname = argv[1];
const char * lfname = argv[2];
......@@ -98,7 +95,7 @@ int otbLabelMapSVMClassifier(int itkNotUsed(argc), char * argv[])
BandsStatisticsFilterType::Pointer radiometricFilter = BandsStatisticsFilterType::New();
LabelMapType::Pointer trainingLabelMap = LabelMapType::New();
ListSampleFilterType::Pointer labelMap2SampleList = ListSampleFilterType::New();
SVMEstimatorType::Pointer svmEstim = SVMEstimatorType::New();
SVMType::Pointer model = SVMType::New();
ClassifierType::Pointer classifier = ClassifierType::New();
ClassifImageGeneratorType::Pointer imGenerator = ClassifImageGeneratorType::New();
LabeledWriterType::Pointer writer = LabeledWriterType::New();
......@@ -153,14 +150,13 @@ int otbLabelMapSVMClassifier(int itkNotUsed(argc), char * argv[])
labelMap2SampleList->Update();
// Estimate SVM model
svmEstim->SetInputSampleList(labelMap2SampleList->GetOutputSampleList());
svmEstim->SetTrainingSampleList(labelMap2SampleList->GetOutputTrainingSampleList());
svmEstim->Modified();
svmEstim->Update();
model->SetInputListSample(const_cast<SVMType::InputListSampleType*>(labelMap2SampleList->GetOutputSampleList()));
model->SetTargetListSample(const_cast<SVMType::TargetListSampleType*>(labelMap2SampleList->GetOutputTrainingSampleList()));
model->Train();
// Classify using the whole LabelMap with estimated model
classifier->SetInput(labelMap);
classifier->SetModel(svmEstim->GetModel());
classifier->SetModel(model);
for (attrIt = attributes.begin(); attrIt != attributes.end(); ++attrIt)
{
......
......@@ -25,6 +25,7 @@
#include "otbImage.h"
#include <iostream>
#include "otbLibSVMMachineLearningModel.h"
#include "otbSVMCrossValidationCostFunction.h"
int otbSVMCrossValidationCostFunctionNew(int itkNotUsed(argc), char * itkNotUsed(argv) [])
......@@ -32,7 +33,7 @@ int otbSVMCrossValidationCostFunctionNew(int itkNotUsed(argc), char * itkNotUsed
typedef unsigned char InputPixelType;
typedef unsigned char LabelPixelType;
typedef otb::SVMModel<InputPixelType, LabelPixelType> ModelType;
typedef otb::LibSVMMachineLearningModel<InputPixelType,LabelPixelType> ModelType;
typedef otb::SVMCrossValidationCostFunction<ModelType> FunctionType;
FunctionType::Pointer function = FunctionType::New();
......
......@@ -25,14 +25,13 @@
#include "itkListSample.h"
#include "otbSVMMarginSampler.h"
#include "otbSVMModel.h"
#include "otbLibSVMMachineLearningModel.h"
int otbSVMMarginSamplerNew(int itkNotUsed(argc), char * itkNotUsed(argv) [])
{
typedef itk::VariableLengthVector<double> SampleType;
typedef itk::Statistics::ListSample<SampleType> SampleListType;
typedef otb::SVMModel<SampleListType::MeasurementType,
unsigned int> SVMModelType;
typedef otb::LibSVMMachineLearningModel<double,unsigned int> SVMModelType;
typedef otb::SVMMarginSampler<SampleListType,SVMModelType> MarginSamplerType;
MarginSamplerType::Pointer marginSampler = MarginSamplerType::New();
......
......@@ -31,34 +31,32 @@ void RegisterTests()
REGISTER_TEST(otbConfusionMatrixMeasurementsNew);
REGISTER_TEST(otbConfusionMatrixMeasurementsTest);
REGISTER_TEST(otbConfusionMatrixConcatenateTest);
REGISTER_TEST(otbExhaustiveExponentialOptimizerNew);
REGISTER_TEST(otbExhaustiveExponentialOptimizerTest);
#ifdef OTB_USE_LIBSVM
REGISTER_TEST(otbLibSVMMachineLearningModelCanRead);
REGISTER_TEST(otbLibSVMMachineLearningModelNew);
REGISTER_TEST(otbLibSVMMachineLearningModel);
REGISTER_TEST(otbLibSVMRegressionTests);
REGISTER_TEST(otbLabelMapClassifierNew);
REGISTER_TEST(otbLabelMapClassifier);
REGISTER_TEST(otbSVMCrossValidationCostFunctionNew);
REGISTER_TEST(otbSVMMarginSamplerNew);
#endif
#ifdef OTB_USE_OPENCV
// can read tests
REGISTER_TEST(otbSVMMachineLearningModelCanRead);
REGISTER_TEST(otbRandomForestsMachineLearningModelCanRead);
REGISTER_TEST(otbBoostMachineLearningModelCanRead);
REGISTER_TEST(otbNeuralNetworkMachineLearningModelCanRead);
REGISTER_TEST(otbNormalBayesMachineLearningModelCanRead);
REGISTER_TEST(otbDecisionTreeMachineLearningModelCanRead);
#ifndef OTB_OPENCV_3
REGISTER_TEST(otbGradientBoostedTreeMachineLearningModelCanRead);
#endif
REGISTER_TEST(otbKNNMachineLearningModelCanRead);
#endif
#ifdef OTB_USE_LIBSVM
REGISTER_TEST(otbLibSVMMachineLearningModelNew);
REGISTER_TEST(otbLibSVMMachineLearningModel);
REGISTER_TEST(otbLibSVMRegressionTests);
#endif
#ifdef OTB_USE_OPENCV
// training tests
REGISTER_TEST(otbSVMMachineLearningModelNew);
REGISTER_TEST(otbSVMMachineLearningModel);
REGISTER_TEST(otbSVMMachineLearningRegressionModel);
REGISTER_TEST(otbKNearestNeighborsMachineLearningModelNew);
REGISTER_TEST(otbKNearestNeighborsMachineLearningModel);
REGISTER_TEST(otbRandomForestsMachineLearningModelNew);
......@@ -71,17 +69,20 @@ void RegisterTests()
REGISTER_TEST(otbNormalBayesMachineLearningModel);
REGISTER_TEST(otbDecisionTreeMachineLearningModelNew);
REGISTER_TEST(otbDecisionTreeMachineLearningModel);
#ifndef OTB_OPENCV_3
REGISTER_TEST(otbGradientBoostedTreeMachineLearningModelNew);
REGISTER_TEST(otbGradientBoostedTreeMachineLearningModel);
REGISTER_TEST(otbGradientBoostedTreeRegressionTests);
#endif
// regression tests
REGISTER_TEST(otbNeuralNetworkRegressionTests);
REGISTER_TEST(otbSVMRegressionTests);
REGISTER_TEST(otbSVMMachineLearningRegressionModel);
REGISTER_TEST(otbDecisionTreeRegressionTests);
REGISTER_TEST(otbKNearestNeighborsRegressionTests);
REGISTER_TEST(otbRandomForestsRegressionTests);
#endif
#ifndef OTB_OPENCV_3
REGISTER_TEST(otbGradientBoostedTreeMachineLearningModelCanRead);
REGISTER_TEST(otbGradientBoostedTreeMachineLearningModelNew);
REGISTER_TEST(otbGradientBoostedTreeMachineLearningModel);
REGISTER_TEST(otbGradientBoostedTreeRegressionTests);
#endif
#endif
#ifdef OTB_USE_SHARK
REGISTER_TEST(otbSharkRFMachineLearningModelNew);
......
......@@ -45,3 +45,18 @@ set_property(TEST leTvLibSVMMachineLearningModelCanRead PROPERTY DEPENDS leTvLib
otb_add_test(NAME leTvLibSVMMachineLearningModelReg COMMAND otbSupervisedTestDriver
otbLibSVMRegressionTests
)
#otb_add_test(NAME obTvLabelMapSVMClassifier COMMAND otbSupervisedTestDriver
#otbLabelMapClassifier
#${INPUTDATA}/maur.tif
#${INPUTDATA}/maur_labelled.tif
#${TEMP}/obTvLabelMapSVMClassifierLabeledOutput.tif)
otb_add_test(NAME obTuLabelMapSVMClassifierNew COMMAND otbSupervisedTestDriver
otbLabelMapClassifierNew)
otb_add_test(NAME leTuSVMCrossValidationCostFunctionNew COMMAND otbSupervisedTestDriver
otbSVMCrossValidationCostFunctionNew)
otb_add_test(NAME leTuSVMMarginSamplerNew COMMAND otbSupervisedTestDriver
otbSVMMarginSamplerNew)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment