Skip to content
Snippets Groups Projects
Commit c1227031 authored by Arnaud Jaen's avatar Arnaud Jaen
Browse files

TEST: Add tests on CanReadFile method of MachineLearningModel derived classes

parent e935fdc7
No related branches found
No related tags found
No related merge requests found
......@@ -724,6 +724,48 @@ IF(OTB_USE_OPENCV)
${INPUTDATA}/letter.scale
${TEMP}/libsvm_model.txt
)
ADD_TEST(leTuImageClassificationFilterNew ${LEARNING_TESTS6}
otbImageClassificationFilterNew)
ADD_TEST(leTvImageClassificationFilterLibSVM ${LEARNING_TESTS6}
--compare-image ${NOTOL}
${BASELINE}/leSVMImageClassificationFilterOutput.tif
${TEMP}/leImageClassificationFilterLibSVMOutput.tif
otbImageClassificationFilter
${INPUTDATA}/ROI_QB_MUL_4.tif
${INPUTDATA}/svm_model_image
${TEMP}/leImageClassificationFilterLibSVMOutput.tif
)
ADD_TEST(leTvImageClassificationFilterSVM ${LEARNING_TESTS6}
--compare-image ${NOTOL}
${BASELINE}/leImageClassificationFilterSVMOutput.tif
${TEMP}/leImageClassificationFilterSVMOutput.tif
otbImageClassificationFilter
${INPUTDATA}/ROI_QB_MUL_4.tif
${INPUTDATA}/ROI_QB_MUL_4_svmModel.txt
${TEMP}/leImageClassificationFilterSVMOutput.tif
)
ADD_TEST(leTuLibSVMMachineLearningModelCanRead ${LEARNING_TESTS6}
otbLibSVMMachineLearningModelCanRead
${INPUTDATA}/svm_model_image
)
ADD_TEST(leTuSVMMachineLearningModelCanRead ${LEARNING_TESTS6}
otbSVMMachineLearningModelCanRead
${INPUTDATA}/svm_model_image
)
ADD_TEST(leTuRandomForestsMachineLearningModelCanRead ${LEARNING_TESTS6}
otbRandomForestsMachineLearningModelCanRead
${TEMP}/RandomForestsMachineLearningModel.txt
)
SET_TESTS_PROPERTIES(leTuRandomForestsMachineLearningModelCanRead
PROPERTIES DEPENDS leTvRandomForestsMachineLearningModel)
ENDIF(OTB_USE_OPENCV)
# Testing srcs
......@@ -811,6 +853,8 @@ IF(OTB_USE_OPENCV)
SET(BasicLearning_SRCS6
otbLearningTests6.cxx
otbTrainMachineLearningModel.cxx
otbImageClassificationFilter.cxx
otbMachineLearningModelCanRead.cxx
)
ENDIF(OTB_USE_OPENCV)
......
......@@ -32,4 +32,9 @@ void RegisterTests()
REGISTER_TEST(otbKNearestNeighborsMachineLearningModel);
REGISTER_TEST(otbRandomForestsMachineLearningModelNew);
REGISTER_TEST(otbRandomForestsMachineLearningModel);
REGISTER_TEST(otbImageClassificationFilterNew);
REGISTER_TEST(otbImageClassificationFilter);
REGISTER_TEST(otbLibSVMMachineLearningModelCanRead);
REGISTER_TEST(otbSVMMachineLearningModelCanRead);
REGISTER_TEST(otbRandomForestsMachineLearningModelCanRead);
}
/*=========================================================================
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 "otbMachineLearningModel.h"
#include "otbLibSVMMachineLearningModel.h"
#include "otbSVMMachineLearningModel.h"
#include "otbRandomForestsMachineLearningModel.h"
#include <iostream>
typedef otb::MachineLearningModel<float,short> MachineLearningModelType;
typedef MachineLearningModelType::InputValueType InputValueType;
typedef MachineLearningModelType::InputSampleType InputSampleType;
typedef MachineLearningModelType::InputListSampleType InputListSampleType;
typedef MachineLearningModelType::TargetValueType TargetValueType;
typedef MachineLearningModelType::TargetSampleType TargetSampleType;
typedef MachineLearningModelType::TargetListSampleType TargetListSampleType;
int otbLibSVMMachineLearningModelCanRead(int argc, char* argv[])
{
if (argc != 2)
{
std::cerr << "Usage: " << argv[0]
<< "<model>" << std::endl;
std::cerr << "Called here with " << argc << " arguments\n";
for (int i = 1; i < argc; ++i)
{
std::cerr << " - " << argv[i] << "\n";
}
return EXIT_FAILURE;
}
std::string filename(argv[1]);
typedef otb::LibSVMMachineLearningModel<InputValueType, TargetValueType> SVMType;
SVMType::Pointer classifier = SVMType::New();
bool lCanRead = classifier->CanReadFile(filename);
if (lCanRead == false)
{
std::cerr << "Erreur otb::LibSVMMachineLearningModel : impossible to open the file " << filename << "." << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int otbSVMMachineLearningModelCanRead(int argc, char* argv[])
{
if (argc != 2)
{
std::cerr << "Usage: " << argv[0]
<< "<model>" << std::endl;
std::cerr << "Called here with " << argc << " arguments\n";
for (int i = 1; i < argc; ++i)
{
std::cerr << " - " << argv[i] << "\n";
}
return EXIT_FAILURE;
}
std::string filename(argv[1]);
typedef otb::SVMMachineLearningModel<InputValueType, TargetValueType> SVMType;
SVMType::Pointer classifier = SVMType::New();
bool lCanRead = classifier->CanReadFile(filename);
if (lCanRead == false)
{
std::cerr << "Erreur otb::SVMMachineLearningModel : impossible to open the file " << filename << "." << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
int otbRandomForestsMachineLearningModelCanRead(int argc, char* argv[])
{
if (argc != 2)
{
std::cerr << "Usage: " << argv[0]
<< "<model>" << std::endl;
std::cerr << "Called here with " << argc << " arguments\n";
for (int i = 1; i < argc; ++i)
{
std::cerr << " - " << argv[i] << "\n";
}
return EXIT_FAILURE;
}
std::string filename(argv[1]);
typedef otb::RandomForestsMachineLearningModel<InputValueType, TargetValueType> RFType;
RFType::Pointer classifier = RFType::New();
bool lCanRead = classifier->CanReadFile(filename);
if (lCanRead == false)
{
std::cerr << "Erreur otb::RandomForestsMachineLearningModel : impossible to open the file " << filename << "." << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment