Commit baa86840 authored by Laurențiu Nicola's avatar Laurențiu Nicola
Browse files

COMP: Ignore -Wdeprecated-copy on Shark headers

parent 0499b4f9
......@@ -45,6 +45,7 @@
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-copy"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
#pragma GCC diagnostic ignored "-Wshadow"
......
......@@ -26,6 +26,7 @@
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-copy"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
......@@ -70,10 +71,10 @@ template <class TInputValue, class NeuronType>
class ITK_EXPORT AutoencoderModel : public MachineLearningModel<itk::VariableLengthVector<TInputValue>, itk::VariableLengthVector<TInputValue>>
{
public:
typedef AutoencoderModel Self;
typedef AutoencoderModel Self;
typedef MachineLearningModel<itk::VariableLengthVector<TInputValue>, itk::VariableLengthVector<TInputValue>> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef typename Superclass::InputValueType InputValueType;
typedef typename Superclass::InputSampleType InputSampleType;
......@@ -91,7 +92,7 @@ public:
typedef typename Superclass::ProbaSampleType ProbaSampleType;
typedef typename Superclass::ProbaListSampleType ProbaListSampleType;
/// Neural network related typedefs
typedef shark::ConcatenatedModel<shark::RealVector> ModelType;
typedef shark::ConcatenatedModel<shark::RealVector> ModelType;
typedef shark::LinearModel<shark::RealVector, NeuronType> LayerType;
typedef shark::LinearModel<shark::RealVector, shark::LinearNeuron> OutLayerType;
......
......@@ -27,6 +27,7 @@
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-copy"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
......@@ -145,7 +146,7 @@ void AutoencoderModel<TInputValue, NeuronType>::TrainOneLayer(shark::AbstractSto
shark::Data<shark::RealVector>& samples, std::ostream& File)
{
typedef shark::AbstractModel<shark::RealVector, shark::RealVector> BaseModelType;
ModelType net;
ModelType net;
net.add(&(m_InLayers[layer_index]), true);
net.add((layer_index ? (BaseModelType*)&(m_InLayers[m_NumberOfHiddenNeurons.Size() * 2 - 1 - layer_index]) : (BaseModelType*)&m_OutLayer), true);
......@@ -156,7 +157,7 @@ void AutoencoderModel<TInputValue, NeuronType>::TrainOneLayer(shark::AbstractSto
//~ shark::ImpulseNoiseModel noise(inputs,m_Noise[layer_index],1.0); //set an input pixel with probability m_Noise to 0
//~ shark::ConcatenatedModel<shark::RealVector,shark::RealVector> model = noise>> net;
shark::LabeledData<shark::RealVector, shark::RealVector> trainSet(samples, samples); // labels identical to inputs
shark::SquaredLoss<shark::RealVector> loss;
shark::SquaredLoss<shark::RealVector> loss;
//~ shark::ErrorFunction error(trainSet, &model, &loss);
shark::ErrorFunction<> error(trainSet, &net, &loss);
......@@ -194,7 +195,7 @@ void AutoencoderModel<TInputValue, NeuronType>::TrainOneSparseLayer(shark::Abstr
shark::Data<shark::RealVector>& samples, std::ostream& File)
{
typedef shark::AbstractModel<shark::RealVector, shark::RealVector> BaseModelType;
ModelType net;
ModelType net;
net.add(&(m_InLayers[layer_index]), true);
net.add((layer_index ? (BaseModelType*)&(m_InLayers[m_NumberOfHiddenNeurons.Size() * 2 - 1 - layer_index]) : (BaseModelType*)&m_OutLayer), true);
......@@ -204,7 +205,7 @@ void AutoencoderModel<TInputValue, NeuronType>::TrainOneSparseLayer(shark::Abstr
// Idea : set the initials value for the output weights higher than the input weights
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, m_Rho[layer_index], m_Beta[layer_index]);
// SparseAutoencoderError doesn't exist anymore, for now use a plain ErrorFunction
shark::ErrorFunction<> error(trainSet, &net, &loss);
......@@ -249,7 +250,7 @@ void AutoencoderModel<TInputValue, NeuronType>::TrainNetwork(shark::AbstractStop
// labels identical to inputs
shark::LabeledData<shark::RealVector, shark::RealVector> trainSet(samples, samples);
shark::SquaredLoss<shark::RealVector> loss;
shark::SquaredLoss<shark::RealVector> loss;
shark::ErrorFunction<> error(trainSet, &net, &loss);
shark::TwoNormRegularizer<> regularizer(error.numberOfVariables());
......
......@@ -25,6 +25,7 @@
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-copy"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
......@@ -65,10 +66,10 @@ template <class TInputValue>
class ITK_EXPORT PCAModel : public MachineLearningModel<itk::VariableLengthVector<TInputValue>, itk::VariableLengthVector<TInputValue>>
{
public:
typedef PCAModel Self;
typedef PCAModel Self;
typedef MachineLearningModel<itk::VariableLengthVector<TInputValue>, itk::VariableLengthVector<TInputValue>> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef typename Superclass::InputValueType InputValueType;
typedef typename Superclass::InputSampleType InputSampleType;
......
......@@ -26,6 +26,7 @@
#include "itkMacro.h"
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-copy"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
......
......@@ -26,6 +26,7 @@
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-copy"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
......@@ -71,10 +72,10 @@ class ITK_EXPORT SharkRandomForestsMachineLearningModel : public MachineLearning
{
public:
/** Standard class typedefs. */
typedef SharkRandomForestsMachineLearningModel Self;
typedef SharkRandomForestsMachineLearningModel Self;
typedef MachineLearningModel<TInputValue, TTargetValue> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef typename Superclass::InputValueType InputValueType;
typedef typename Superclass::InputSampleType InputSampleType;
......@@ -120,22 +121,22 @@ public:
itkSetMacro(MTry, unsigned int);
/** From Shark doc: Controls when a node is considered pure. If set
* to 1, a node is pure when it only consists of a single node.
*/
* to 1, a node is pure when it only consists of a single node.
*/
itkGetMacro(NodeSize, unsigned int);
/** From Shark doc: Controls when a node is considered pure. If
* set to 1, a node is pure when it only consists of a single node.
*/
* set to 1, a node is pure when it only consists of a single node.
*/
itkSetMacro(NodeSize, unsigned int);
/** From Shark doc: Get the fraction of the original training
* dataset to use as the out of bag sample. The default value is
* 0.66.*/
* dataset to use as the out of bag sample. The default value is
* 0.66.*/
itkGetMacro(OobRatio, float);
/** From Shark doc: Set the fraction of the original training
* dataset to use as the out of bag sample. The default value is 0.66.
*/
* dataset to use as the out of bag sample. The default value is 0.66.
*/
itkSetMacro(OobRatio, float);
/** If true, margin confidence value will be computed */
......
......@@ -27,6 +27,7 @@
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-copy"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
......@@ -75,10 +76,10 @@ class ITK_EXPORT SharkKMeansMachineLearningModel : public MachineLearningModel<T
{
public:
/** Standard class typedefs. */
typedef SharkKMeansMachineLearningModel Self;
typedef SharkKMeansMachineLearningModel Self;
typedef MachineLearningModel<TInputValue, TTargetValue> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef typename Superclass::InputValueType InputValueType;
typedef typename Superclass::InputSampleType InputSampleType;
......
......@@ -28,6 +28,7 @@
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-copy"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
......
......@@ -27,6 +27,7 @@
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-copy"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wsign-compare"
......@@ -55,35 +56,37 @@ namespace otb
{
namespace Shark
{
template <class T> void ListSampleRangeToSharkVector(const T * listSample, std::vector<shark::RealVector> & output, unsigned int start, unsigned int size)
template <class T>
void ListSampleRangeToSharkVector(const T* listSample, std::vector<shark::RealVector>& output, unsigned int start, unsigned int size)
{
assert(listSample != nullptr);
if(start+size>listSample->Size())
{
std::out_of_range e_(std::string("otb::Shark::ListSampleRangeToSharkVector "
": Requested range is out of list sample bounds"));
if (start + size > listSample->Size())
{
std::out_of_range e_(
std::string("otb::Shark::ListSampleRangeToSharkVector "
": Requested range is out of list sample bounds"));
throw e_;
}
}
output.clear();
// Sample index
unsigned int sampleIdx = start;
//Check for valid listSample
if(listSample->Size()>0)
{
// Check for valid listSample
if (listSample->Size() > 0)
{
// Retrieve samples size alike
const unsigned int sampleSize = listSample->GetMeasurementVectorSize();
// Fill the output vector
for (auto const endOfRange = start+size ; sampleIdx < endOfRange ; ++sampleIdx)
{
for (auto const endOfRange = start + size; sampleIdx < endOfRange; ++sampleIdx)
{
// Retrieve sample
typename T::MeasurementVectorType const & sample = listSample->GetMeasurementVector(sampleIdx);
typename T::MeasurementVectorType const& sample = listSample->GetMeasurementVector(sampleIdx);
// // Define a shark::RealVector
// shark::RealVector rv(sampleSize);
// // Loop on sample size
......@@ -94,83 +97,88 @@ template <class T> void ListSampleRangeToSharkVector(const T * listSample, std::
// using std::move;
// output.emplace_back(move(rv));
output.emplace_back(&sample[0], &sample[0]+sampleSize);
}
output.emplace_back(&sample[0], &sample[0] + sampleSize);
}
}
}
template <class T> void ListSampleRangeToSharkVector(const T * listSample, std::vector<unsigned int> & output, unsigned int start, unsigned int size)
template <class T>
void ListSampleRangeToSharkVector(const T* listSample, std::vector<unsigned int>& output, unsigned int start, unsigned int size)
{
assert(listSample != nullptr);
if(start+size>listSample->Size())
{
std::out_of_range e_(std::string("otb::Shark::ListSampleRangeToSharkVector "
": Requested range is out of list sample bounds"));
if (start + size > listSample->Size())
{
std::out_of_range e_(
std::string("otb::Shark::ListSampleRangeToSharkVector "
": Requested range is out of list sample bounds"));
throw e_;
}
}
output.clear();
// Sample index
unsigned int sampleIdx = start;
//Check for valid listSample
if(listSample->Size()>0)
{
// Check for valid listSample
if (listSample->Size() > 0)
{
// Fill the output vector
while(sampleIdx<start+size)
{
while (sampleIdx < start + size)
{
// Retrieve sample
typename T::MeasurementVectorType const & sample = listSample->GetMeasurementVector(sampleIdx);
typename T::MeasurementVectorType const& sample = listSample->GetMeasurementVector(sampleIdx);
// Define a shark::RealVector
output.push_back(sample[0]);
++sampleIdx;
}
}
}
}
}
template <class T> void ListSampleToSharkVector(const T * listSample, std::vector<shark::RealVector> & output)
template <class T>
void ListSampleToSharkVector(const T* listSample, std::vector<shark::RealVector>& output)
{
assert(listSample != nullptr);
ListSampleRangeToSharkVector(listSample,output,0U,static_cast<unsigned int>(listSample->Size()));
ListSampleRangeToSharkVector(listSample, output, 0U, static_cast<unsigned int>(listSample->Size()));
}
template <class T> void ListSampleToSharkVector(const T * listSample, std::vector<unsigned int> & output)
template <class T>
void ListSampleToSharkVector(const T* listSample, std::vector<unsigned int>& output)
{
assert(listSample != nullptr);
ListSampleRangeToSharkVector(listSample,output,0, static_cast<unsigned int>(listSample->Size()));
ListSampleRangeToSharkVector(listSample, output, 0, static_cast<unsigned int>(listSample->Size()));
}
/** Shark assumes that labels are 0 ... (nbClasses-1). This function modifies the labels contained in the input vector and returns a vector with size = nbClasses which allows the translation from the normalised labels to the new ones oldLabel = dictionary[newLabel].
When we want to generate the image containing the probability for each class, we need to ensure that the probabilities are in the correct order wrt the incoming labels. We therefore sort the labels before building the encoding.
/** Shark assumes that labels are 0 ... (nbClasses-1). This function modifies the labels contained in the input vector and returns a vector with size =
nbClasses which allows the translation from the normalised labels to the new ones oldLabel = dictionary[newLabel]. When we want to generate the image containing
the probability for each class, we need to ensure that the probabilities are in the correct order wrt the incoming labels. We therefore sort the labels before
building the encoding.
*/
template <typename T> void NormalizeLabelsAndGetDictionary(std::vector<T>& labels,
std::vector<T>& dictionary)
template <typename T>
void NormalizeLabelsAndGetDictionary(std::vector<T>& labels, std::vector<T>& dictionary)
{
std::vector<T> sorted_labels = labels;
std::sort(std::begin(sorted_labels), std::end(sorted_labels));
auto last = std::unique(std::begin(sorted_labels), std::end(sorted_labels));
sorted_labels.erase(last, std::end(sorted_labels));
std::unordered_map<T, T> dictMap;
T labelCount{0};
for(const auto& l : sorted_labels)
{
if(dictMap.find(l)==dictMap.end())
T labelCount{0};
for (const auto& l : sorted_labels)
{
if (dictMap.find(l) == dictMap.end())
dictMap.insert({l, labelCount++});
}
}
dictionary.resize(labelCount);
for(auto& l : labels)
{
auto newLabel = dictMap[l];
for (auto& l : labels)
{
auto newLabel = dictMap[l];
dictionary[newLabel] = l;
l = newLabel;
}
}
}
l = newLabel;
}
}
#endif
} // namespace Shark
} // namespace otb
#endif
Markdown is supported
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