From 4c1a32f77a6b15206551c4ebd51e75c0c14106f7 Mon Sep 17 00:00:00 2001
From: Guillaume Pasero <guillaume.pasero@c-s.fr>
Date: Thu, 14 Dec 2017 15:32:34 +0100
Subject: [PATCH] BUG: wrong dimension detected when reading AE model

---
 .../include/otbAutoencoderModel.txx                   | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModel.txx b/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModel.txx
index 96eb2aa76e..33f1c28e24 100644
--- a/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModel.txx
+++ b/Modules/Learning/DimensionalityReductionLearning/include/otbAutoencoderModel.txx
@@ -179,6 +179,7 @@ AutoencoderModel<TInputValue,NeuronType>
     shark::MaxIterations<> criterion(m_NumberOfIterationsFineTuning);
     TrainNetwork(criterion, inputSamples_copy, ofs);
     }
+  this->SetDimension(m_NumberOfHiddenNeurons[m_NumberOfHiddenNeurons.Size()-1]);
 }
 
 template <class TInputValue, class NeuronType>
@@ -387,8 +388,8 @@ AutoencoderModel<TInputValue,NeuronType>
 
   // This gives us the dimension if we keep the encoder and decoder
   size_t feature_layer_index = m_Net.layerMatrices().size()/2;
-  // number of neurons in the feature layer (first dimension of the first decoder weight matrix)
-  this->m_Dimension = m_Net.layerMatrix(feature_layer_index).size1(); 
+  // number of neurons in the feature layer (second dimension of the first decoder weight matrix)
+  this->SetDimension(m_Net.layerMatrix(feature_layer_index).size2());
 }
 
 template <class TInputValue, class NeuronType>
@@ -407,7 +408,8 @@ AutoencoderModel<TInputValue,NeuronType>
 
   shark::Data<shark::RealVector> data = shark::createDataFromRange(features);
 
-  data = m_Net.evalLayer( m_Net.layerMatrices().size()/2-1 ,data); // features layer for a network containing the encoder and decoder part
+  // features layer for a network containing the encoder and decoder part
+  data = m_Net.evalLayer( m_Net.layerMatrices().size()/2-1 ,data);
   TargetSampleType target;
   target.SetSize(this->m_Dimension);
 
@@ -432,7 +434,8 @@ AutoencoderModel<TInputValue,NeuronType>
   Shark::ListSampleRangeToSharkVector(input, features,startIndex,size);
   shark::Data<shark::RealVector> data = shark::createDataFromRange(features);
   TargetSampleType target;
-  data = m_Net.evalLayer( m_Net.layerMatrices().size()/2-1 ,data);   // features layer for a network containing the encoder and decoder part
+  // features layer for a network containing the encoder and decoder part
+  data = m_Net.evalLayer( m_Net.layerMatrices().size()/2-1 ,data);
 
   unsigned int id = startIndex;
   target.SetSize(this->m_Dimension);
-- 
GitLab