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

neuronType switched to tanh/Linear, some cout removed

parent af9aeea9
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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();
......
......@@ -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"))
......
......@@ -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>
......
......@@ -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);
......
......@@ -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;
......
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