Skip to content
Snippets Groups Projects
Commit 94ab0bf1 authored by Cédric Traizet's avatar Cédric Traizet
Browse files

learning curves added, field for points ID added in vector dr app output shapefile

parent 67b19129
No related branches found
No related tags found
No related merge requests found
...@@ -106,6 +106,11 @@ class CbDimensionalityReductionVector : public Application ...@@ -106,6 +106,11 @@ class CbDimensionalityReductionVector : public Application
SetParameterDescription("out","Output vector data file storing sample values (OGR format)." SetParameterDescription("out","Output vector data file storing sample values (OGR format)."
"If not given, the input vector data file is updated."); "If not given, the input vector data file is updated.");
MandatoryOff("out"); MandatoryOff("out");
AddParameter(ParameterType_Int, "indim", "Dimension of the input vector");
SetParameterDescription("indim","Dimension of the whole input vector, this value is required if only a part of the bands contained in the vector are used."
"If not given, the dimension is deduced from the length of the 'feat' parameter");
MandatoryOff("indim");
AddParameter(ParameterType_Int, "pcadim", "Principal component"); // AddParameter(ParameterType_Int, "pcadim", "Principal component"); //
SetParameterDescription("pcadim","This optional parameter can be set to reduce the number of eignevectors used in the PCA model file."); // SetParameterDescription("pcadim","This optional parameter can be set to reduce the number of eignevectors used in the PCA model file."); //
...@@ -167,7 +172,8 @@ class CbDimensionalityReductionVector : public Application ...@@ -167,7 +172,8 @@ class CbDimensionalityReductionVector : public Application
otb::ogr::DataSource::Pointer source = otb::ogr::DataSource::New(shapefile, otb::ogr::DataSource::Modes::Read); otb::ogr::DataSource::Pointer source = otb::ogr::DataSource::New(shapefile, otb::ogr::DataSource::Modes::Read);
otb::ogr::Layer layer = source->GetLayer(0); otb::ogr::Layer layer = source->GetLayer(0);
ListSampleType::Pointer input = ListSampleType::New(); ListSampleType::Pointer input = ListSampleType::New();
const int nbFeatures = GetSelectedItems("feat").size(); int nbFeatures = GetSelectedItems("feat").size();
input->SetMeasurementVectorSize(nbFeatures); input->SetMeasurementVectorSize(nbFeatures);
otb::ogr::Layer::const_iterator it = layer.cbegin(); otb::ogr::Layer::const_iterator it = layer.cbegin();
otb::ogr::Layer::const_iterator itEnd = layer.cend(); otb::ogr::Layer::const_iterator itEnd = layer.cend();
...@@ -247,6 +253,10 @@ class CbDimensionalityReductionVector : public Application ...@@ -247,6 +253,10 @@ class CbDimensionalityReductionVector : public Application
ogr::DataSource::Pointer output; ogr::DataSource::Pointer output;
ogr::DataSource::Pointer buffer = ogr::DataSource::New(); ogr::DataSource::Pointer buffer = ogr::DataSource::New();
bool updateMode = false; bool updateMode = false;
int nbBands = nbFeatures;
if (HasValue("indim") && IsParameterEnabled("indim"))
{nbBands = GetParameterInt("indim");}
if (IsParameterEnabled("out") && HasValue("out")) if (IsParameterEnabled("out") && HasValue("out"))
...@@ -258,7 +268,7 @@ class CbDimensionalityReductionVector : public Application ...@@ -258,7 +268,7 @@ class CbDimensionalityReductionVector : public Application
layer.GetGeomType()); layer.GetGeomType());
// Copy existing fields // Copy existing fields
OGRFeatureDefn &inLayerDefn = layer.GetLayerDefn(); OGRFeatureDefn &inLayerDefn = layer.GetLayerDefn();
for (int k=0 ; k<inLayerDefn.GetFieldCount()-nbFeatures ; k++) // we don't copy the original bands for (int k=0 ; k<inLayerDefn.GetFieldCount()-nbBands ; k++) // we don't copy the original bands
{ {
OGRFieldDefn fieldDefn(inLayerDefn.GetFieldDefn(k)); OGRFieldDefn fieldDefn(inLayerDefn.GetFieldDefn(k));
newLayer.CreateField(fieldDefn); newLayer.CreateField(fieldDefn);
...@@ -279,8 +289,7 @@ class CbDimensionalityReductionVector : public Application ...@@ -279,8 +289,7 @@ class CbDimensionalityReductionVector : public Application
// Re-open input data source in update mode // Re-open input data source in update mode
output = otb::ogr::DataSource::New(shapefile, otb::ogr::DataSource::Modes::Update_LayerUpdate); output = otb::ogr::DataSource::New(shapefile, otb::ogr::DataSource::Modes::Update_LayerUpdate);
}*/ }*/
otb::ogr::Layer outLayer = output->GetLayer(0); otb::ogr::Layer outLayer = output->GetLayer(0);
OGRErr errStart = outLayer.ogr().StartTransaction(); OGRErr errStart = outLayer.ogr().StartTransaction();
...@@ -310,12 +319,18 @@ class CbDimensionalityReductionVector : public Application ...@@ -310,12 +319,18 @@ class CbDimensionalityReductionVector : public Application
} }
} }
// Add an ID field. (The ID already contained in the layer refers to the polygon)
OGRFieldDefn IDField("ID_point", OFTInteger);
ogr::FieldDefn IDFieldDef(IDField);
outLayer.CreateField(IDFieldDef);
// Fill output layer // Fill output layer
unsigned int count=0; unsigned int count=0;
auto classfieldname = GetParameterStringList("featout"); auto classfieldname = GetParameterStringList("featout");
it = layer.cbegin(); it = layer.cbegin();
itEnd = layer.cend(); itEnd = layer.cend();
int id=0;
for( ; it!=itEnd ; ++it, ++count) for( ; it!=itEnd ; ++it, ++count)
{ {
ogr::Feature dstFeature(outLayer.GetLayerDefn()); ogr::Feature dstFeature(outLayer.GetLayerDefn());
...@@ -324,6 +339,7 @@ class CbDimensionalityReductionVector : public Application ...@@ -324,6 +339,7 @@ class CbDimensionalityReductionVector : public Application
for (std::size_t i=0; i<classfieldname.size(); ++i){ for (std::size_t i=0; i<classfieldname.size(); ++i){
dstFeature[classfieldname[i]].SetValue<ValueType>(target->GetMeasurementVector(count)[i]); dstFeature[classfieldname[i]].SetValue<ValueType>(target->GetMeasurementVector(count)[i]);
} }
dstFeature["ID_point"].SetValue<int>(id);
if (updateMode) if (updateMode)
{ {
outLayer.SetFeature(dstFeature); outLayer.SetFeature(dstFeature);
...@@ -332,6 +348,7 @@ class CbDimensionalityReductionVector : public Application ...@@ -332,6 +348,7 @@ class CbDimensionalityReductionVector : public Application
{ {
outLayer.CreateFeature(dstFeature); outLayer.CreateFeature(dstFeature);
} }
id++;
} }
if(outLayer.ogr().TestCapability("Transactions")) if(outLayer.ogr().TestCapability("Transactions"))
......
...@@ -86,8 +86,7 @@ private: ...@@ -86,8 +86,7 @@ private:
/** Network attributes */ /** Network attributes */
std::vector<AutoencoderType> m_net; std::vector<AutoencoderType> m_net;
typename InputListSampleType::Pointer m_ValidationListSample; // This list can optionnaly be used during training to prevent overfitting.
itk::Array<unsigned int> m_NumberOfHiddenNeurons; itk::Array<unsigned int> m_NumberOfHiddenNeurons;
/** Training parameters */ /** Training parameters */
...@@ -97,6 +96,9 @@ private: ...@@ -97,6 +96,9 @@ private:
itk::Array<double> m_Noise; // probability for an input to be set to 0 (denosing autoencoder) itk::Array<double> m_Noise; // probability for an input to be set to 0 (denosing autoencoder)
itk::Array<double> m_Rho; // Sparsity parameter itk::Array<double> m_Rho; // Sparsity parameter
itk::Array<double> m_Beta; // Sparsity regularization parameter itk::Array<double> m_Beta; // Sparsity regularization parameter
bool m_WriteLearningCurve; // Flag for writting the learning curve into a txt file
}; };
} // end namespace otb } // end namespace otb
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment