diff --git a/Modules/Detection/ObjectDetection/test/CMakeLists.txt b/Modules/Detection/ObjectDetection/test/CMakeLists.txt index 88857c53f7d956c1eae4b5a89afcb326839dabb1..3408fe2a0eb5d1e9225599e2e043c77807a1da60 100644 --- a/Modules/Detection/ObjectDetection/test/CMakeLists.txt +++ b/Modules/Detection/ObjectDetection/test/CMakeLists.txt @@ -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 + ) diff --git a/Modules/Detection/ObjectDetection/test/otbObjectDetectionClassifier.cxx b/Modules/Detection/ObjectDetection/test/otbObjectDetectionClassifier.cxx index 011310acc46985fc4fe7ba48070d12a22605b626..8d12d62a618130ad4524ad274a74d5c197259d8f 100644 --- a/Modules/Detection/ObjectDetection/test/otbObjectDetectionClassifier.cxx +++ b/Modules/Detection/ObjectDetection/test/otbObjectDetectionClassifier.cxx @@ -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"); diff --git a/Modules/Detection/ObjectDetection/test/otbObjectDetectionTestDriver.cxx b/Modules/Detection/ObjectDetection/test/otbObjectDetectionTestDriver.cxx index 055b0aa4b871bfefd76f6804eb8619f162b24591..afed2f209e643e5dde468565067defbfcc18175e 100644 --- a/Modules/Detection/ObjectDetection/test/otbObjectDetectionTestDriver.cxx +++ b/Modules/Detection/ObjectDetection/test/otbObjectDetectionTestDriver.cxx @@ -29,4 +29,6 @@ void RegisterTests() REGISTER_TEST(otbDescriptorsListSampleGeneratorNew); REGISTER_TEST(otbDescriptorsListSampleGenerator); REGISTER_TEST(otbDescriptorsSVMModelCreation); + REGISTER_TEST(otbObjectDetectionClassifierNew); + REGISTER_TEST(otbObjectDetectionClassifier); } diff --git a/Modules/Learning/Supervised/test/CMakeLists.txt b/Modules/Learning/Supervised/test/CMakeLists.txt index edeb96d0cde66eae5456db2cb539c0bde665c9fb..858f9f84ea9592a96da94b17d6c9cf4074fc6994 100644 --- a/Modules/Learning/Supervised/test/CMakeLists.txt +++ b/Modules/Learning/Supervised/test/CMakeLists.txt @@ -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() diff --git a/Modules/Learning/Supervised/test/otbLabelMapClassifier.cxx b/Modules/Learning/Supervised/test/otbLabelMapClassifier.cxx index 634a41f5511b33fcdd42c9044ec2deb0a9a568c7..094e3e3a23256ad05a6708ccd234469eae5dbeba 100644 --- a/Modules/Learning/Supervised/test/otbLabelMapClassifier.cxx +++ b/Modules/Learning/Supervised/test/otbLabelMapClassifier.cxx @@ -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) { diff --git a/Modules/Learning/Supervised/test/otbSVMCrossValidationCostFunctionNew.cxx b/Modules/Learning/Supervised/test/otbSVMCrossValidationCostFunctionNew.cxx index a8865b5300655ac69f9279ee4abeb44e48aa57c3..06ec8c1b6a3bc53bb4c7c5f7095042c0ecd273ed 100644 --- a/Modules/Learning/Supervised/test/otbSVMCrossValidationCostFunctionNew.cxx +++ b/Modules/Learning/Supervised/test/otbSVMCrossValidationCostFunctionNew.cxx @@ -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(); diff --git a/Modules/Learning/Supervised/test/otbSVMMarginSampler.cxx b/Modules/Learning/Supervised/test/otbSVMMarginSampler.cxx index a0822eeb8d3a8e68562c2ad4b663033d10f20d42..f70bb88332dcd2adbf04ddb7140c63094fb2e916 100644 --- a/Modules/Learning/Supervised/test/otbSVMMarginSampler.cxx +++ b/Modules/Learning/Supervised/test/otbSVMMarginSampler.cxx @@ -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(); diff --git a/Modules/Learning/Supervised/test/otbSupervisedTestDriver.cxx b/Modules/Learning/Supervised/test/otbSupervisedTestDriver.cxx index c3236411d51895fde5a566c252fc1407af1fa1db..5d0ccbe17c48695077cefec52e2114ca9e0f659b 100644 --- a/Modules/Learning/Supervised/test/otbSupervisedTestDriver.cxx +++ b/Modules/Learning/Supervised/test/otbSupervisedTestDriver.cxx @@ -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); diff --git a/Modules/Learning/Supervised/test/tests-libsvm.cmake b/Modules/Learning/Supervised/test/tests-libsvm.cmake index a9f08a966682b39a7659e8711370f4d01c20f27b..bbf6647ab09866b3074d840a84e301f9956bc48f 100644 --- a/Modules/Learning/Supervised/test/tests-libsvm.cmake +++ b/Modules/Learning/Supervised/test/tests-libsvm.cmake @@ -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)