Commit af9aeea9 authored by Cédric Traizet's avatar Cédric Traizet
Browse files

some temporary cout added for testing purposes

No related merge requests found
Showing with 53 additions and 16 deletions
+53 -16
...@@ -100,7 +100,8 @@ void AutoencoderModel<TInputValue,AutoencoderType>::TrainOneLayer(shark::Abstrac ...@@ -100,7 +100,8 @@ void AutoencoderModel<TInputValue,AutoencoderType>::TrainOneLayer(shark::Abstrac
std::size_t inputs = dataDimension(samples); std::size_t inputs = dataDimension(samples);
net.setStructure(inputs, nbneuron); net.setStructure(inputs, nbneuron);
initRandomUniform(net,-0.1*std::sqrt(1.0/inputs),0.1*std::sqrt(1.0/inputs)); //initRandomUniform(net,-0.1*std::sqrt(1.0/inputs),0.1*std::sqrt(1.0/inputs));
initRandomUniform(net,-1,1);
shark::ImpulseNoiseModel noise(noise_strength,0.0); //set an input pixel with probability m_Noise to 0 shark::ImpulseNoiseModel noise(noise_strength,0.0); //set an input pixel with probability m_Noise to 0
shark::ConcatenatedModel<shark::RealVector,shark::RealVector> model = noise>> net; shark::ConcatenatedModel<shark::RealVector,shark::RealVector> model = noise>> net;
shark::LabeledData<shark::RealVector,shark::RealVector> trainSet(samples,samples);//labels identical to inputs shark::LabeledData<shark::RealVector,shark::RealVector> trainSet(samples,samples);//labels identical to inputs
...@@ -145,8 +146,8 @@ void AutoencoderModel<TInputValue,AutoencoderType>::TrainOneSparseLayer(shark::A ...@@ -145,8 +146,8 @@ void AutoencoderModel<TInputValue,AutoencoderType>::TrainOneSparseLayer(shark::A
std::size_t inputs = dataDimension(samples); std::size_t inputs = dataDimension(samples);
net.setStructure(inputs, nbneuron); net.setStructure(inputs, nbneuron);
initRandomUniform(net,-0.1*std::sqrt(1.0/inputs),0.1*std::sqrt(1.0/inputs)); //initRandomUniform(net,-0.1*std::sqrt(1.0/inputs),0.1*std::sqrt(1.0/inputs));
initRandomUniform(net,-1,1);
shark::LabeledData<shark::RealVector,shark::RealVector> trainSet(samples,samples);//labels identical to inputs shark::LabeledData<shark::RealVector,shark::RealVector> trainSet(samples,samples);//labels identical to inputs
shark::SquaredLoss<shark::RealVector> loss; shark::SquaredLoss<shark::RealVector> loss;
shark::SparseAutoencoderError error(trainSet,&net, &loss, rho, beta); shark::SparseAutoencoderError error(trainSet,&net, &loss, rho, beta);
...@@ -219,7 +220,33 @@ void AutoencoderModel<TInputValue,AutoencoderType>::Save(const std::string & fil ...@@ -219,7 +220,33 @@ void AutoencoderModel<TInputValue,AutoencoderType>::Save(const std::string & fil
otxt << m_net[i].encoderMatrix() << std::endl; otxt << m_net[i].encoderMatrix() << std::endl;
otxt << m_net[i].hiddenBias() << std::endl; otxt << m_net[i].hiddenBias() << std::endl;
} }
std::vector<shark::RealVector> features;
shark::SquaredLoss<shark::RealVector> loss;
Shark::ListSampleToSharkVector(this->GetInputListSample(), features);
shark::Data<shark::RealVector> inputSamples = shark::createDataFromRange( features );
shark::Data<shark::RealVector> outputSamples = inputSamples;
for (unsigned int i = 0 ; i < m_NumberOfHiddenNeurons.Size(); ++i)
{
outputSamples = m_net[i].encode(outputSamples);
}
for (unsigned int i = 0 ; i < m_NumberOfHiddenNeurons.Size(); ++i)
{
outputSamples = m_net[m_NumberOfHiddenNeurons.Size()-i-1].decode(outputSamples); // We decode the data starting from the smallest layer
}
otxt << "Reconstruction error : " << loss.eval(inputSamples,outputSamples) << std::endl; // the mean squared error is returned
std::cout << "Reconstruction error : " << loss.eval(inputSamples,outputSamples) << std::endl; // the mean squared error is returned
std::cout << "in" << inputSamples.element(0) << std::endl;
std::cout << "out" << outputSamples.element(0) << std::endl;
otxt.close(); otxt.close();
} }
......
...@@ -35,11 +35,13 @@ namespace otb ...@@ -35,11 +35,13 @@ namespace otb
{ {
template <class TInputValue, class TTargetValue> template <class TInputValue, class TTargetValue>
using AutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::Autoencoder<shark::LogisticNeuron, shark::LogisticNeuron>> ; // using AutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::Autoencoder<shark::TanhNeuron, shark::LinearNeuron>> ;
using AutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::Autoencoder<shark::TanhNeuron, shark::TanhNeuron>> ;
template <class TInputValue, class TTargetValue> template <class TInputValue, class TTargetValue>
using TiedAutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::TiedAutoencoder< shark::LogisticNeuron, shark::LogisticNeuron>> ; // using TiedAutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::TiedAutoencoder< shark::TanhNeuron, shark::LinearNeuron>> ;
using TiedAutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::TiedAutoencoder< shark::TanhNeuron, shark::TanhNeuron>> ;
template <class TInputValue, class TTargetValue> template <class TInputValue, class TTargetValue>
......
...@@ -134,7 +134,6 @@ void ImageDimensionalityReductionFilter<TInputImage, TOutputImage, TMaskImage>:: ...@@ -134,7 +134,6 @@ void ImageDimensionalityReductionFilter<TInputImage, TOutputImage, TMaskImage>::
{ {
Superclass::GenerateOutputInformation(); Superclass::GenerateOutputInformation();
this->GetOutput()->SetNumberOfComponentsPerPixel( m_Model->GetDimension() ); this->GetOutput()->SetNumberOfComponentsPerPixel( m_Model->GetDimension() );
std::cout << m_Model->GetDimension() << std::endl;
} }
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include <shark/ObjectiveFunctions/Loss/SquaredLoss.h> // squared loss used for regression #include <shark/ObjectiveFunctions/Loss/SquaredLoss.h> // squared loss used for regression
#include <shark/ObjectiveFunctions/Regularizer.h> //L2 regulariziation #include <shark/ObjectiveFunctions/Regularizer.h> //L2 regulariziation
#include <shark/ObjectiveFunctions/ErrorFunction.h>
namespace otb namespace otb
{ {
...@@ -83,9 +85,16 @@ void PCAModel<TInputValue>::Save(const std::string & filename, const std::string ...@@ -83,9 +85,16 @@ void PCAModel<TInputValue>::Save(const std::string & filename, const std::string
{ {
std::ofstream otxt(filename+".txt"); std::ofstream otxt(filename+".txt");
otxt << m_pca.eigenvectors() << std::endl; otxt << "Eigenvectors : " << m_pca.eigenvectors() << std::endl;
otxt << m_pca.eigenvalues() << std::endl; otxt << "Eigenvalues : " << m_pca.eigenvalues() << std::endl;
std::vector<shark::RealVector> features;
shark::SquaredLoss<shark::RealVector> loss;
Shark::ListSampleToSharkVector(this->GetInputListSample(), features);
shark::Data<shark::RealVector> inputSamples = shark::createDataFromRange( features );
otxt << "Reconstruction error : " << loss.eval(inputSamples,m_decoder(m_encoder(inputSamples))) << std::endl;
std::cout << "Reconstruction error : " << loss.eval(inputSamples,m_decoder(m_encoder(inputSamples))) << std::endl;
otxt.close(); otxt.close();
} }
} }
...@@ -109,16 +118,13 @@ void PCAModel<TInputValue>::Load(const std::string & filename, const std::string ...@@ -109,16 +118,13 @@ void PCAModel<TInputValue>::Load(const std::string & filename, const std::string
{ {
this->m_Dimension = m_encoder.outputSize(); this->m_Dimension = m_encoder.outputSize();
} }
else
{
std::cout << "yo" << std::endl;
}
auto eigenvectors = m_encoder.matrix(); auto eigenvectors = m_encoder.matrix();
eigenvectors.resize(this->m_Dimension,m_encoder.inputSize()); eigenvectors.resize(this->m_Dimension,m_encoder.inputSize());
m_encoder.setStructure(eigenvectors, m_encoder.offset() ); m_encoder.setStructure(eigenvectors, m_encoder.offset() );
std::cout << m_encoder.matrix() << "end" << std::endl;
//this->m_Size = m_NumberOfHiddenNeurons;
} }
......
...@@ -101,10 +101,13 @@ public: ...@@ -101,10 +101,13 @@ public:
#ifdef OTB_USE_SHARK #ifdef OTB_USE_SHARK
typedef shark::Autoencoder< shark::LogisticNeuron, shark::LogisticNeuron> AutoencoderType;
// typedef shark::Autoencoder< shark::TanhNeuron, shark::LinearNeuron> AutoencoderType;
typedef shark::Autoencoder< shark::TanhNeuron, shark::TanhNeuron> AutoencoderType;
typedef otb::AutoencoderModel<InputValueType, AutoencoderType> AutoencoderModelType; typedef otb::AutoencoderModel<InputValueType, AutoencoderType> AutoencoderModelType;
typedef shark::TiedAutoencoder< shark::LogisticNeuron, shark::LogisticNeuron> TiedAutoencoderType; // typedef shark::TiedAutoencoder< shark::TanhNeuron, shark::LinearNeuron> TiedAutoencoderType;
typedef shark::TiedAutoencoder< shark::TanhNeuron, shark::TanhNeuron> TiedAutoencoderType;
typedef otb::AutoencoderModel<InputValueType, TiedAutoencoderType> TiedAutoencoderModelType; typedef otb::AutoencoderModel<InputValueType, TiedAutoencoderType> TiedAutoencoderModelType;
typedef otb::PCAModel<InputValueType> PCAModelType; typedef otb::PCAModel<InputValueType> PCAModelType;
......
Supports Markdown
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