Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
otb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sébastien Peillet
otb
Commits
de38d430
Commit
de38d430
authored
7 years ago
by
Cédric Traizet
Browse files
Options
Downloads
Patches
Plain Diff
serialization work in progress
parent
02e37fb0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/SOMModel.h
+1
-0
1 addition, 0 deletions
include/SOMModel.h
include/SOMModel.txx
+91
-12
91 additions, 12 deletions
include/SOMModel.txx
with
92 additions
and
12 deletions
include/SOMModel.h
+
1
−
0
View file @
de38d430
...
...
@@ -36,6 +36,7 @@ public:
typedef
SOMMap
<
itk
::
VariableLengthVector
<
TInputValue
>
,
itk
::
Statistics
::
EuclideanDistanceMetric
<
itk
::
VariableLengthVector
<
TInputValue
>>
,
MapDimension
>
MapType
;
typedef
typename
MapType
::
SizeType
SizeType
;
typedef
typename
MapType
::
SpacingType
SpacingType
;
typedef
otb
::
SOM
<
InputListSampleType
,
MapType
>
EstimatorType
;
...
...
This diff is collapsed.
Click to expand it.
include/SOMModel.txx
+
91
−
12
View file @
de38d430
...
...
@@ -13,6 +13,9 @@
#include "itkImageRegionConstIterator.h"
#include <fstream>
#include "itkImage.h"
namespace otb
{
...
...
@@ -92,14 +95,18 @@ void SOMModel<TInputValue, MapDimension>::Save(const std::string & filename, con
std::ofstream ofs(filename+"2");
ofs << "SOM" << std::endl;
ofs << MapDimension << std::endl;
ofs << m_SOMMap->GetLargestPossibleRegion().GetSize() << std::endl;
SizeType size = m_SOMMap->GetLargestPossibleRegion().GetSize() ;
//ofs << m_SOMMap->GetLargestPossibleRegion().GetSize() << std::endl;
for (size_t i=0;i<MapDimension;i++){
ofs << size[i] << " " ;
}
ofs << std::endl;
ofs << inputIterator.Get().GetNumberOfElements() << std::endl;;
while(!inputIterator.IsAtEnd()){
InputSampleType vect = inputIterator.Get();
for (size_t i=0;i<vect.GetNumberOfElements();i++){
ofs << vect[i] << " " ;
}
ofs << std::endl;
++inputIterator;
}
...
...
@@ -110,6 +117,7 @@ void SOMModel<TInputValue, MapDimension>::Save(const std::string & filename, con
template <class TInputValue, unsigned int MapDimension>
void SOMModel<TInputValue, MapDimension>::Load(const std::string & filename, const std::string & name)
{
/*
auto reader = otb::ImageFileReader<MapType>::New();
reader->SetFileName(filename);
reader->Update();
...
...
@@ -117,30 +125,101 @@ void SOMModel<TInputValue, MapDimension>::Load(const std::string & filename, con
itkExceptionMacro(<< "Error opening " << filename.c_str() );
}
m_SOMMap = reader->GetOutput();
*/
// test text
std::ifstream ifs(filename+"2");
std::string model_type_str;
std::string dimension_str;
std::string size_str;
std::string number_of_elements_str;
SizeType size;
std::getline(ifs,model_type_str);
std::getline(ifs,dimension_str);
std::getline(ifs,size_str);
std::getline(ifs,number_of_elements_str);
if (model_type_str+dimension_str != "SOM"+std::to_string(MapDimension)){
itkExceptionMacro(<< "Error opening " << filename.c_str() );
}
std::cout << "bug-1?" << std::endl;
SizeType size;
itk::Point<double, MapDimension> origin;
SpacingType spacing;
itk::Index< MapDimension > index;
for (int i=0 ; i<MapDimension; i++)
{
std::getline(ifs,size_str , ' ');
size[i] = stof(size_str);
origin[i] = 0;
spacing[i]=0;
index[i]=0;
}
while (!ifs.eof())
{
std::string line;
std::getline(ifs, line);
std::getline(ifs,number_of_elements_str);
std::getline(ifs,number_of_elements_str);
std::cout << "bug0?" << number_of_elements_str << std::endl;
auto number_of_elements = stof(number_of_elements_str);
//typedef itk::Image< unsigned char, 3 > ImageType;
//typename MapType::Pointer image = MapType::New();
m_SOMMap = MapType::New();
typename MapType::RegionType region;
region.SetSize( size );
m_SOMMap->SetNumberOfComponentsPerPixel(number_of_elements);
region.SetIndex( index );
m_SOMMap->SetRegions( region );
m_SOMMap->Allocate();
std::cout << m_SOMMap << std::endl;
/*
std::cout << "bug1?" << number_of_elements << std::endl;
itk::ImageRegion<MapDimension> outputRegion;
std::cout << "bugoriggin?" << origin << std::endl;
m_SOMMap->SetNumberOfComponentsPerPixel(number_of_elements);
outputRegion.SetIndex(index);
std::cout << "setindex?" << index << std::endl;
outputRegion.SetSize(size);
std::cout << origin << size << std::endl;
m_SOMMap->SetLargestPossibleRegion(outputRegion);
std::cout << "setRegion" << origin << std::endl;
m_SOMMap->Allocate();
std::cout << "bug2?" << std::endl;
*/
itk::ImageRegionIterator<MapType> outputIterator(m_SOMMap,region);
std::string value;
size_t j=0;
while(!outputIterator.IsAtEnd()){
std::cout << j << std::endl;
std::getline(ifs,value, ' ');
itk::VariableLengthVector<float> vect(number_of_elements);
for (int i=0 ; i<number_of_elements; i++)
{
std::getline(ifs,value , ' ');
//std::cout << value << " ";
std::cout << stof(value) << " ";
vect[i]=std::stof(value);
}
std::cout << vect << std::endl;
outputIterator.Set(vect);
++outputIterator;
j++;
std::cout << j << "end" << std::endl;
//std::cout << value << std::endl;
//std::string line;
//std::getline(ifs, line);
}
std::cout << j << std::endl;
ifs.close();
std::cout << "model type " << model_type_str << std::endl;
std::cout << "dimension " << dimension_str << std::endl;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment