diff --git a/app/cbDimensionalityReduction.cxx b/app/cbDimensionalityReduction.cxx index 106f609d48078a1e5cee94ed5276571dd589e61c..6a8ed36866d842a9ea28c30497e13301a9c18ecf 100644 --- a/app/cbDimensionalityReduction.cxx +++ b/app/cbDimensionalityReduction.cxx @@ -222,7 +222,7 @@ private: } // Rescale vector image - m_Rescaler->SetScale(stddevMeasurementVector); + m_Rescaler->SetScale(stddevMeasurementVector*5); m_Rescaler->SetShift(meanMeasurementVector); m_Rescaler->SetInput(inImage); diff --git a/app/cbDimensionalityReductionTrainer.cxx b/app/cbDimensionalityReductionTrainer.cxx index aee6fb3ed966fb657980b5063ef4b35efdaa5e4e..1b273650c99d1f5a1c18712e2ed1059e45236240 100644 --- a/app/cbDimensionalityReductionTrainer.cxx +++ b/app/cbDimensionalityReductionTrainer.cxx @@ -37,7 +37,7 @@ public: typedef Superclass::ListSampleType ListSampleType; typedef Superclass::SampleImageType SampleImageType; - typedef double ValueType; + typedef float ValueType; typedef itk::VariableLengthVector<ValueType> MeasurementType; typedef otb::StatisticsXMLFileReader<SampleType> StatisticsReader; @@ -126,7 +126,7 @@ private: ShiftScaleFilterType::Pointer trainingShiftScaleFilter = ShiftScaleFilterType::New(); trainingShiftScaleFilter->SetInput(input); trainingShiftScaleFilter->SetShifts(meanMeasurementVector); - trainingShiftScaleFilter->SetScales(stddevMeasurementVector); + trainingShiftScaleFilter->SetScales(stddevMeasurementVector*3); trainingShiftScaleFilter->Update(); ListSampleType::Pointer trainingListSample= trainingShiftScaleFilter->GetOutput(); diff --git a/app/cbDimensionalityReductionVector.cxx b/app/cbDimensionalityReductionVector.cxx index ce4e1fa1ca35437a92762a8bab2297faba3fe3b3..b598a0310a2120ab666138ca8ed190dab5497124 100644 --- a/app/cbDimensionalityReductionVector.cxx +++ b/app/cbDimensionalityReductionVector.cxx @@ -159,12 +159,7 @@ class CbDimensionalityReductionVector : public Application std::string tmpKey="feat."+key; AddChoice(tmpKey,item); } - /* - if(fieldType == OFTInteger || ogr::version_proxy::IsOFTInteger64(fieldType) || fieldType == OFTReal) - { - std::string tmpKey="featout."+key; - AddChoice(tmpKey,item); - }*/ + } } } @@ -192,8 +187,8 @@ class CbDimensionalityReductionVector : public Application mv[idx] = (*it)[GetSelectedItems("feat")[idx]].GetValue<double>(); } input->PushBack(mv); + } - /** Statistics for shift/scale */ MeasurementType meanMeasurementVector; @@ -218,7 +213,7 @@ class CbDimensionalityReductionVector : public Application ShiftScaleFilterType::Pointer trainingShiftScaleFilter = ShiftScaleFilterType::New(); trainingShiftScaleFilter->SetInput(input); trainingShiftScaleFilter->SetShifts(meanMeasurementVector); - trainingShiftScaleFilter->SetScales(stddevMeasurementVector); + trainingShiftScaleFilter->SetScales(stddevMeasurementVector*3); trainingShiftScaleFilter->Update(); otbAppLogINFO("mean used: " << meanMeasurementVector); otbAppLogINFO("standard deviation used: " << stddevMeasurementVector); @@ -246,8 +241,7 @@ class CbDimensionalityReductionVector : public Application /** Perform Dimensionality Reduction */ ListSampleType::Pointer listSample = trainingShiftScaleFilter->GetOutput(); - ListSampleType::Pointer target; - target = m_Model->PredictBatch(listSample); + ListSampleType::Pointer target = m_Model->PredictBatch(listSample); /** Create/Update Output Shape file */ @@ -276,8 +270,8 @@ class CbDimensionalityReductionVector : public Application OGRFeatureDefn &inLayerDefn = layer.GetLayerDefn(); for (int k=0 ; k<inLayerDefn.GetFieldCount()-nbBands ; k++) // we don't copy the original bands { - OGRFieldDefn fieldDefn(inLayerDefn.GetFieldDefn(k)); - newLayer.CreateField(fieldDefn); + OGRFieldDefn fieldDefn(inLayerDefn.GetFieldDefn(k)); + newLayer.CreateField(fieldDefn); } } else if (GetParameterString("mode")=="update") @@ -306,20 +300,7 @@ class CbDimensionalityReductionVector : public Application } - /* - else - { - // Update mode - updateMode = true; - otbAppLogINFO("Update input vector data."); - // fill temporary buffer for the transfer - otb::ogr::Layer inputLayer = layer; - layer = buffer->CopyLayer(inputLayer, std::string("Buffer")); - // close input data source - source->Clear(); - // Re-open input data source in update mode - output = otb::ogr::DataSource::New(shapefile, otb::ogr::DataSource::Modes::Update_LayerUpdate); - }*/ + otb::ogr::Layer outLayer = output->GetLayer(0); @@ -351,34 +332,26 @@ 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 unsigned int count=0; auto classfieldname = GetParameterStringList("featout"); it = layer.cbegin(); itEnd = layer.cend(); - int id=0; + for( ; it!=itEnd ; ++it, ++count) { ogr::Feature dstFeature(outLayer.GetLayerDefn()); - /* - if (GetParameterString("mode")=="overwrite") - {*/ - dstFeature.SetFrom( *it , TRUE); - dstFeature.SetFID(it->GetFID()); - //} + + dstFeature.SetFrom( *it , TRUE); + dstFeature.SetFID(it->GetFID()); + for (std::size_t i=0; i<classfieldname.size(); ++i){ dstFeature[classfieldname[i]].SetValue<ValueType>(target->GetMeasurementVector(count)[i]); } - //dstFeature["ID_point"].SetValue<int>(id); if (updateMode) { outLayer.SetFeature(dstFeature); @@ -387,7 +360,6 @@ class CbDimensionalityReductionVector : public Application { outLayer.CreateFeature(dstFeature); } - id++; } if(outLayer.ogr().TestCapability("Transactions")) diff --git a/include/DimensionalityReductionModelFactory.txx b/include/DimensionalityReductionModelFactory.txx index 23fcadddde79b3bbdf2973351f844523ca1b180d..183156c3e593bba276b39ee0d604c5497d39333c 100644 --- a/include/DimensionalityReductionModelFactory.txx +++ b/include/DimensionalityReductionModelFactory.txx @@ -36,12 +36,12 @@ namespace otb template <class TInputValue, class TTargetValue> // using AutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::Autoencoder<shark::TanhNeuron, shark::LinearNeuron>> ; -using AutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::Autoencoder<shark::TanhNeuron, shark::TanhNeuron>> ; +using AutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::Autoencoder<shark::TanhNeuron, shark::LinearNeuron>> ; template <class TInputValue, class TTargetValue> // using TiedAutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::TiedAutoencoder< shark::TanhNeuron, shark::LinearNeuron>> ; -using TiedAutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::TiedAutoencoder< shark::TanhNeuron, shark::TanhNeuron>> ; +using TiedAutoencoderModelFactory = AutoencoderModelFactoryBase<TInputValue, TTargetValue, shark::TiedAutoencoder< shark::TanhNeuron, shark::LinearNeuron>> ; template <class TInputValue, class TTargetValue> diff --git a/include/PCAModel.txx b/include/PCAModel.txx index e9ea1e2a2b94d3cc1331b65a2123f340087943f6..364dd8def35fa51373f3b0cf30e927622044d736 100644 --- a/include/PCAModel.txx +++ b/include/PCAModel.txx @@ -43,7 +43,6 @@ void PCAModel<TInputValue>::Train() shark::Data<shark::RealVector> inputSamples = shark::createDataFromRange( features ); m_pca.setData(inputSamples); m_pca.encoder(m_encoder, this->m_Dimension); - std::cout << m_encoder.matrix() << std::endl; m_pca.decoder(m_decoder, this->m_Dimension); } @@ -175,8 +174,6 @@ void PCAModel<TInputValue> //target[a]=1; //target.SetElement(a,p[a]); - - } //std::cout << p << std::endl; targets->SetMeasurementVector(id,target); diff --git a/include/cbLearningApplicationBaseDR.h b/include/cbLearningApplicationBaseDR.h index 6207527baadd28134925ab380ea80401ca3466c3..3b7557afbf355e12479be9c1e39a9df70e507bc4 100644 --- a/include/cbLearningApplicationBaseDR.h +++ b/include/cbLearningApplicationBaseDR.h @@ -103,11 +103,11 @@ public: #ifdef OTB_USE_SHARK // typedef shark::Autoencoder< shark::TanhNeuron, shark::LinearNeuron> AutoencoderType; - typedef shark::Autoencoder< shark::TanhNeuron, shark::TanhNeuron> AutoencoderType; + typedef shark::Autoencoder< shark::TanhNeuron, shark::LinearNeuron> AutoencoderType; typedef otb::AutoencoderModel<InputValueType, AutoencoderType> AutoencoderModelType; // typedef shark::TiedAutoencoder< shark::TanhNeuron, shark::LinearNeuron> TiedAutoencoderType; - typedef shark::TiedAutoencoder< shark::TanhNeuron, shark::TanhNeuron> TiedAutoencoderType; + typedef shark::TiedAutoencoder< shark::TanhNeuron, shark::LinearNeuron> TiedAutoencoderType; typedef otb::AutoencoderModel<InputValueType, TiedAutoencoderType> TiedAutoencoderModelType; typedef otb::PCAModel<InputValueType> PCAModelType;