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
Container Registry
Model registry
Operate
Environments
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
Sébastien Peillet
otb
Commits
0c0351e2
Commit
0c0351e2
authored
7 years ago
by
Cédric Traizet
Browse files
Options
Downloads
Patches
Plain Diff
added denoising autoencoder (noise strength is now a parameter of cbdimensionalityreductiontrainer
parent
4442d2af
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/AutoencoderModel.h
+4
-0
4 additions, 0 deletions
include/AutoencoderModel.h
include/AutoencoderModel.txx
+6
-5
6 additions, 5 deletions
include/AutoencoderModel.txx
include/cbTrainAutoencoder.txx
+7
-0
7 additions, 0 deletions
include/cbTrainAutoencoder.txx
with
17 additions
and
5 deletions
include/AutoencoderModel.h
+
4
−
0
View file @
0c0351e2
...
...
@@ -37,6 +37,9 @@ public:
itkGetMacro
(
Regularization
,
double
);
itkSetMacro
(
Regularization
,
double
);
itkGetMacro
(
Noise
,
double
);
itkSetMacro
(
Noise
,
double
);
bool
CanReadFile
(
const
std
::
string
&
filename
);
bool
CanWriteFile
(
const
std
::
string
&
filename
);
...
...
@@ -60,6 +63,7 @@ private:
unsigned
int
m_NumberOfHiddenNeurons
;
unsigned
int
m_NumberOfIterations
;
double
m_Regularization
;
double
m_Noise
;
};
}
// end namespace otb
...
...
This diff is collapsed.
Click to expand it.
include/AutoencoderModel.txx
+
6
−
5
View file @
0c0351e2
...
...
@@ -11,6 +11,8 @@
#include <shark/Algorithms/GradientDescent/Rprop.h>// the RProp optimization algorithm
#include <shark/ObjectiveFunctions/Loss/SquaredLoss.h> // squared loss used for regression
#include <shark/ObjectiveFunctions/Regularizer.h> //L2 regulariziation
#include <shark/Models/ImpulseNoiseModel.h>//noise source to corrupt the inputs
#include <shark/Models/ConcatenatedModel.h>//to concatenate the noise with the model
namespace otb
{
...
...
@@ -32,7 +34,6 @@ AutoencoderModel<TInputValue,AutoencoderType>::~AutoencoderModel()
template <class TInputValue, class AutoencoderType>
void AutoencoderModel<TInputValue,AutoencoderType>::Train()
{
std::vector<shark::RealVector> features;
Shark::ListSampleToSharkVector(this->GetInputListSample(), features);
...
...
@@ -42,10 +43,12 @@ void AutoencoderModel<TInputValue,AutoencoderType>::Train()
std::size_t inputs = dataDimension(inputSamples);
m_net.setStructure(inputs, m_NumberOfHiddenNeurons);
initRandomUniform(m_net,-0.1*std::sqrt(1.0/inputs),0.1*std::sqrt(1.0/inputs));
shark::ImpulseNoiseModel noise(m_Noise,0.0);//set an input pixel with probability p to 0
shark::ConcatenatedModel<shark::RealVector,shark::RealVector> model = noise>> m_net;
shark::LabeledData<shark::RealVector,shark::RealVector> trainSet(inputSamples,inputSamples);//labels identical to inputs
shark::SquaredLoss<shark::RealVector> loss;
shark::ErrorFunction error(trainSet, &m
_net
, &loss);
shark::ErrorFunction error(trainSet, &m
odel
, &loss);
shark::TwoNormRegularizer regularizer(error.numberOfVariables());
error.setRegularizer(m_Regularization,®ularizer);
...
...
@@ -117,7 +120,6 @@ template <class TInputValue, class AutoencoderType>
typename AutoencoderModel<TInputValue,AutoencoderType>::TargetSampleType
AutoencoderModel<TInputValue,AutoencoderType>::DoPredict(const InputSampleType & value) const
{
std::cout << "SINGLE PIXEL " ;
shark::RealVector samples(value.Size());
for(size_t i = 0; i < value.Size();i++)
{
...
...
@@ -144,7 +146,6 @@ template <class TInputValue, class AutoencoderType>
void AutoencoderModel<TInputValue,AutoencoderType>
::DoPredictBatch(const InputListSampleType *input, const unsigned int & startIndex, const unsigned int & size, TargetListSampleType * targets) const
{
std::cout << "BATCH" << std::endl;
std::vector<shark::RealVector> features;
Shark::ListSampleRangeToSharkVector(input, features,startIndex,size);
shark::Data<shark::RealVector> data = shark::createDataFromRange(features);
...
...
This diff is collapsed.
Click to expand it.
include/cbTrainAutoencoder.txx
+
7
−
0
View file @
0c0351e2
...
...
@@ -58,6 +58,12 @@ cbLearningApplicationBaseDR<TInputValue,TOutputValue>
SetParameterFloat("model.autoencoder.regularization",0, false);
SetParameterDescription("model.autoencoder.regularization",
"Strength of the L2 regularization used during training");
//Noise strength
AddParameter(ParameterType_Float, "model.autoencoder.noise", "Strength of the noise");
SetParameterFloat("model.autoencoder.noise",0, false);
SetParameterDescription("model.autoencoder.noise",
"Strength of the noise");
}
...
...
@@ -97,6 +103,7 @@ void cbLearningApplicationBaseDR<TInputValue,TOutputValue>
dimredTrainer->SetNumberOfHiddenNeurons(GetParameterInt("model.autoencoder.nbneuron"));
dimredTrainer->SetNumberOfIterations(GetParameterInt("model.autoencoder.nbiter"));
dimredTrainer->SetRegularization(GetParameterFloat("model.autoencoder.regularization"));
dimredTrainer->SetRegularization(GetParameterFloat("model.autoencoder.noise"));
dimredTrainer->SetInputListSample(trainingListSample);
dimredTrainer->Train();
dimredTrainer->Save(modelPath);
...
...
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