Commit 80f9d699 authored by Cédric Traizet's avatar Cédric Traizet
Browse files

debugging the vector reduction app

No related merge requests found
Showing with 41 additions and 13 deletions
+41 -13
...@@ -222,7 +222,7 @@ private: ...@@ -222,7 +222,7 @@ private:
} }
// Rescale vector image // Rescale vector image
m_Rescaler->SetScale(stddevMeasurementVector*5); m_Rescaler->SetScale(stddevMeasurementVector*3);
m_Rescaler->SetShift(meanMeasurementVector); m_Rescaler->SetShift(meanMeasurementVector);
m_Rescaler->SetInput(inImage); m_Rescaler->SetInput(inImage);
......
...@@ -103,6 +103,8 @@ private: ...@@ -103,6 +103,8 @@ private:
} }
input->PushBack(mv); input->PushBack(mv);
} }
std::cout << GetParameterStringList("feat")[0] << std::endl;
std::cout << input->GetMeasurementVector(0) << std::endl;
MeasurementType meanMeasurementVector; MeasurementType meanMeasurementVector;
MeasurementType stddevMeasurementVector; MeasurementType stddevMeasurementVector;
......
...@@ -57,7 +57,7 @@ class CbDimensionalityReductionVector : public Application ...@@ -57,7 +57,7 @@ class CbDimensionalityReductionVector : public Application
/** Filters typedef */ /** Filters typedef */
typedef double ValueType; typedef float ValueType;
typedef itk::VariableLengthVector<ValueType> InputSampleType; typedef itk::VariableLengthVector<ValueType> InputSampleType;
typedef itk::Statistics::ListSample<InputSampleType> ListSampleType; typedef itk::Statistics::ListSample<InputSampleType> ListSampleType;
typedef MachineLearningModel<itk::VariableLengthVector<ValueType>, itk::VariableLengthVector<ValueType>> DimensionalityReductionModelType; typedef MachineLearningModel<itk::VariableLengthVector<ValueType>, itk::VariableLengthVector<ValueType>> DimensionalityReductionModelType;
...@@ -136,6 +136,7 @@ class CbDimensionalityReductionVector : public Application ...@@ -136,6 +136,7 @@ class CbDimensionalityReductionVector : public Application
if ( HasValue("in") ) if ( HasValue("in") )
{ {
std::string shapefile = GetParameterString("in"); std::string shapefile = GetParameterString("in");
otb::ogr::DataSource::Pointer ogrDS; otb::ogr::DataSource::Pointer ogrDS;
OGRSpatialReference oSRS(""); OGRSpatialReference oSRS("");
...@@ -153,21 +154,32 @@ class CbDimensionalityReductionVector : public Application ...@@ -153,21 +154,32 @@ class CbDimensionalityReductionVector : public Application
key.erase( std::remove_if(key.begin(),key.end(),IsNotAlphaNum), key.end()); key.erase( std::remove_if(key.begin(),key.end(),IsNotAlphaNum), key.end());
std::transform(key.begin(), key.end(), key.begin(), tolower); std::transform(key.begin(), key.end(), key.begin(), tolower);
OGRFieldType fieldType = layerDefn.GetFieldDefn(iField)->GetType(); OGRFieldType fieldType = layerDefn.GetFieldDefn(iField)->GetType();
/*if(fieldType == OFTInteger || ogr::version_proxy::IsOFTInteger64(fieldType) || fieldType == OFTReal)
if(fieldType == OFTInteger || ogr::version_proxy::IsOFTInteger64(fieldType) || fieldType == OFTReal) {*/
{
std::string tmpKey="feat."+key; std::string tmpKey="feat."+key;
AddChoice(tmpKey,item); AddChoice(tmpKey,item);
} //}
} }
} }
} }
void DoExecute() ITK_OVERRIDE void DoExecute() ITK_OVERRIDE
{ {
clock_t tic = clock(); clock_t tic = clock();
std::cout << GetChoiceKeys("feat")[0] << std::endl;
std::cout << GetChoiceKeys("feat")[1] << std::endl;
std::cout << GetChoiceKeys("feat")[2] << std::endl;
std::cout << GetChoiceKeys("feat")[3] << std::endl;
std::cout << GetChoiceKeys("feat")[4] << std::endl;
std::cout << GetChoiceKeys("feat")[5] << std::endl;
std::cout << GetChoiceKeys("feat")[6] << std::endl;
std::cout << GetChoiceKeys("feat")[7] << std::endl;
std::cout << GetChoiceKeys("feat")[8] << std::endl;
std::string shapefile = GetParameterString("in"); std::string shapefile = GetParameterString("in");
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);
...@@ -177,18 +189,31 @@ class CbDimensionalityReductionVector : public Application ...@@ -177,18 +189,31 @@ class CbDimensionalityReductionVector : public Application
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();
std::cout << (*it)[GetSelectedItems("feat")[0]].GetValue<double>() << std::endl;
for( ; it!=itEnd ; ++it) for( ; it!=itEnd ; ++it)
{ {
MeasurementType mv; MeasurementType mv;
mv.SetSize(nbFeatures); mv.SetSize(nbFeatures);
for(int idx=0; idx < nbFeatures; ++idx) for(int idx=0; idx < nbFeatures; ++idx)
{ {
mv[idx] = (*it)[GetSelectedItems("feat")[idx]].GetValue<double>(); mv[idx] = static_cast<float>( (*it)[GetSelectedItems("feat")[idx]].GetValue<double>() );
} }
input->PushBack(mv); input->PushBack(mv);
} }
std::cout << GetSelectedItems("feat")[0] << std::endl;
std::cout << input->GetMeasurementVector(0) << std::endl;
/** Statistics for shift/scale */ /** Statistics for shift/scale */
MeasurementType meanMeasurementVector; MeasurementType meanMeasurementVector;
...@@ -242,8 +267,9 @@ class CbDimensionalityReductionVector : public Application ...@@ -242,8 +267,9 @@ class CbDimensionalityReductionVector : public Application
ListSampleType::Pointer listSample = trainingShiftScaleFilter->GetOutput(); ListSampleType::Pointer listSample = trainingShiftScaleFilter->GetOutput();
ListSampleType::Pointer target = m_Model->PredictBatch(listSample); ListSampleType::Pointer target = m_Model->PredictBatch(listSample);
target = input;
std::cout << target->GetMeasurementVector(0) << std::endl;
std::cout << input->GetMeasurementVector(0) << std::endl;
/** Create/Update Output Shape file */ /** Create/Update Output Shape file */
std::cout << GetParameterStringList("featout").size() << std::endl; std::cout << GetParameterStringList("featout").size() << std::endl;
...@@ -350,7 +376,7 @@ class CbDimensionalityReductionVector : public Application ...@@ -350,7 +376,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<double>(target->GetMeasurementVector(count)[i]);
} }
if (updateMode) if (updateMode)
{ {
......
...@@ -189,7 +189,7 @@ ImageDimensionalityReductionFilter<TInputImage, TOutputImage, TMaskImage> ...@@ -189,7 +189,7 @@ ImageDimensionalityReductionFilter<TInputImage, TOutputImage, TMaskImage>
// This call is threadsafe // This call is threadsafe
labels = m_Model->PredictBatch(samples); labels = m_Model->PredictBatch(samples);
labels = samples;
// Set the output values // Set the output values
typename TargetListSampleType::ConstIterator labIt = labels->Begin(); typename TargetListSampleType::ConstIterator labIt = labels->Begin();
......
Supports Markdown
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