diff --git a/CMakeLists.txt b/CMakeLists.txt index d44bf84f11214fe6d5ef1f6eee3f6956767ac213..b1d9bfe596db9e3d70b74d75b4f3101a14381200 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,3 +3,4 @@ cmake_minimum_required(VERSION 2.8.9) project(CbDimensionalityReduction) #set(CbDimensionalityReduction_LIBRARIES CbDimensionalityReduction) otb_module_impl() + diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index cdb4d73fb7aebfc8b6d2ac2d5cc7cc11d63786f4..5dc561a0858a0032d11542a0d20cbcf6b43ac3ed 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -1,4 +1,11 @@ -OTB_CREATE_APPLICATION(NAME CbDimensionalityReductionTrainer +OTB_CREATE_APPLICATION( +NAME CbDimensionalityReductionTrainer SOURCES cbDimensionalityReductionTrainer.cxx LINK_LIBRARIES ${${otb-module}_LIBRARIES} ) + +OTB_CREATE_APPLICATION( +NAME CbDimensionalityReduction +SOURCES cbDimensionalityReduction.cxx +LINK_LIBRARIES ${${otb-module}_LIBRARIES} ${OTBCommon_LIBRARIES} ${OTBITK_LIBRARIES} ${OTBBoost_LIBRARIES} ${OTBShark_LIBRARIES} +) diff --git a/app/cbDimensionalityReduction.cxx b/app/cbDimensionalityReduction.cxx index 5986fd3a74a0939b569aa08b2c9e52ba9d80e9f0..a6362a4b4f700fdb2f1b62635716ec0a3938e507 100644 --- a/app/cbDimensionalityReduction.cxx +++ b/app/cbDimensionalityReduction.cxx @@ -1,5 +1,26 @@ #include "otbWrapperApplication.h" #include "otbWrapperApplicationFactory.h" +#include "otbWrapperChoiceParameter.h" + +#include <iostream> + +#include "otbImage.h" +//#include "otbVectorImage.h" +#include "otbImageFileReader.h" +#include "otbImageFileWriter.h" + + +#include <shark/Models/Autoencoder.h>//normal autoencoder model + +#include <shark/Models/TiedAutoencoder.h>//autoencoder with tied weights +#include <shark/Models/Normalizer.h> + +#include "encode_filter.h" + +namespace otb +{ +namespace Wrapper +{ class CbDimensionalityReduction : public otb::Wrapper::Application { @@ -13,6 +34,19 @@ private: { SetName("CbDimensionalityReduction"); SetDescription("Perform dimensionality reduction on the input image"); + + AddParameter(ParameterType_InputImage, "in", "Input Image"); + SetParameterDescription( "in", "The input image to perform dimensionality reduction on."); + + AddParameter(ParameterType_InputFilename, "model", "Model file"); + SetParameterDescription("model", "A model file (produced by the cbDimensionalityReductionTrainer application)."); + + AddParameter(ParameterType_InputFilename, "normalizer", "Normalizer model file"); + SetParameterDescription("normalizer", "A normalizer model file (produced by the cbDimensionalityReductionTrainer application)."); + + AddParameter(ParameterType_OutputImage, "out", "Output Image"); + SetParameterDescription("out", "Output image"); + AddRAMParameter(); } @@ -22,10 +56,36 @@ private: void DoExecute() { + typedef shark::TiedAutoencoder< shark::TanhNeuron, shark::LinearNeuron> AutoencoderType; + + using image_type = otb::VectorImage<double, 2>; + using FilterType = EncodeFilter<image_type, AutoencoderType, shark::Normalizer<shark::RealVector>> ; + std::cout << "Appli !" << std::endl; - int ThisDoesNothing = 0; + FloatVectorImageType::Pointer inImage = GetParameterImage("in"); + std::string encoderPath = GetParameterString("model"); + std::string normalizerPath = GetParameterString("normalizer"); + + //inImage->UpdateOutputInformation(); + + using ReaderType = otb::ImageFileReader<image_type>; + + ReaderType::Pointer reader = ReaderType::New(); + reader->SetFileName("/mnt/data/home/vincenta/features_2014/SL_MultiTempGapF_Brightness_NDVI_NDWI__.tif"); + + FilterType::Pointer filter = FilterType::New(); + filter->SetAutoencoderModel(encoderPath); + filter->SetNormalizerModel(normalizerPath); + filter->SetInput(reader->GetOutput()); + //filter->SetInput(inImage); + + filter->UpdateOutputInformation(); + + SetParameterOutputImage("out", filter->GetOutput()); + } }; - -OTB_APPLICATION_EXPORT(CbDimensionalityReduction) +} +} +OTB_APPLICATION_EXPORT(otb::Wrapper::CbDimensionalityReduction) diff --git a/app/cbDimensionalityReductionTrainer.cxx b/app/cbDimensionalityReductionTrainer.cxx index daa5d6766d5ebe3c4b452803cbab9ebb4e0497a1..cd18d7e5c412bc8e6e98e0a7f0502021b1f414be 100644 --- a/app/cbDimensionalityReductionTrainer.cxx +++ b/app/cbDimensionalityReductionTrainer.cxx @@ -13,6 +13,7 @@ private: { SetName("CbDimensionalityReductionTrainer"); SetDescription("Trainer for the dimensionality reduction algorithms used in the cbDimensionalityReduction application."); + AddRAMParameter(); } void DoUpdateParameters() @@ -20,7 +21,8 @@ private: } void DoExecute() - { + { + std::cout << "Appli !" << std::endl; int ThisDoesNothing = 0; } diff --git a/otb-module.cmake b/otb-module.cmake index c2861a847fc80187a29fd8c0504dba0df7f895c4..5797e5c7cb8d9b004ce5aaa5555f1e89b09bfda9 100644 --- a/otb-module.cmake +++ b/otb-module.cmake @@ -3,7 +3,9 @@ otb_module(CbDimensionalityReduction DEPENDS OTBCommon OTBApplicationEngine - + OTBITK + OTBShark + OTBBoost DESCRIPTION "${DOCUMENTATION}" )