diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 418c9052bb06e8cf4c2dd2d557488037c9ca5bff..ef933451346da7e8bfb4513b6b22b7d8ab9f1580 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -41,7 +41,7 @@ pylint: allow_failure: true script: - sudo apt update && sudo apt install pylint -y - - pylint --disable=too-many-nested-blocks,too-many-locals,too-many-statements,too-few-public-methods,too-many-instance-attributes,too-many-arguments --ignored-modules=tensorflow --max-line-length=120 $OTBTF_SRC/python + - pylint --disable=too-many-nested-blocks,too-many-locals,too-many-statements,too-few-public-methods,too-many-instance-attributes,too-many-arguments --ignored-modules=tensorflow --max-line-length=120 --logging-format-style=new $OTBTF_SRC/python codespell: stage: Static Analysis @@ -54,7 +54,7 @@ cppcheck: allow_failure: true script: - sudo apt update && sudo apt install cppcheck -y - - cppcheck --enable=all --error-exitcode=1 $OTBTF_SRC/ + - cd $OTBTF_SRC/ && cppcheck --enable=all --error-exitcode=1 -I include/ --suppress=missingInclude --suppress=unusedFunction . ctest: stage: Test diff --git a/app/otbDensePolygonClassStatistics.cxx b/app/otbDensePolygonClassStatistics.cxx index 62f9eea9e87e8b11490360a7d2eeb59ab4371c64..fa7c2701db9bbe959ec2787f8e04c1fd6915cd3e 100644 --- a/app/otbDensePolygonClassStatistics.cxx +++ b/app/otbDensePolygonClassStatistics.cxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even @@ -9,18 +9,24 @@ PURPOSE. See the above copyright notices for more information. =========================================================================*/ -#include "otbWrapperApplication.h" +#include "itkFixedArray.h" +#include "itkObjectFactory.h" #include "otbWrapperApplicationFactory.h" +// Application engine +#include "otbStandardFilterWatcher.h" +#include "itkFixedArray.h" + +// Filters #include "otbStatisticsXMLFileWriter.h" #include "otbWrapperElevationParametersHandler.h" - #include "otbVectorDataToLabelImageFilter.h" #include "otbImageToNoDataMaskFilter.h" #include "otbStreamingStatisticsMapFromLabelImageFilter.h" #include "otbVectorDataIntoImageProjectionFilter.h" #include "otbImageToVectorImageCastFilter.h" +// OGR #include "otbOGR.h" namespace otb @@ -37,15 +43,14 @@ class DensePolygonClassStatistics : public Application { public: /** Standard class typedefs. */ - typedef DensePolygonClassStatistics Self; + typedef DensePolygonClassStatistics Self; typedef Application Superclass; typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; /** Standard macro */ itkNewMacro(Self); - - itkTypeMacro(DensePolygonClassStatistics, otb::Application); + itkTypeMacro(DensePolygonClassStatistics, Application); /** DataObjects typedef */ typedef UInt32ImageType LabelImageType; @@ -67,14 +72,7 @@ public: typedef otb::StatisticsXMLFileWriter<FloatVectorImageType::PixelType> StatWriterType; - -private: - DensePolygonClassStatistics() - { - - } - - void DoInit() override + void DoInit() { SetName("DensePolygonClassStatistics"); SetDescription("Computes statistics on a training polygon set."); @@ -88,7 +86,6 @@ private: " - number of samples per geometry\n"); SetDocLimitations("None"); SetDocAuthors("Remi Cresson"); - SetDocSeeAlso(" "); AddDocTag(Tags::Learning); @@ -115,67 +112,11 @@ private: SetDocExampleParameterValue("field", "label"); SetDocExampleParameterValue("out","polygonStat.xml"); - SetOfficialDocLink(); - } - - void DoUpdateParameters() override - { - if ( HasValue("vec") ) - { - std::string vectorFile = GetParameterString("vec"); - ogr::DataSource::Pointer ogrDS = - ogr::DataSource::New(vectorFile, ogr::DataSource::Modes::Read); - ogr::Layer layer = ogrDS->GetLayer(0); - ogr::Feature feature = layer.ogr().GetNextFeature(); - - ClearChoices("field"); - - for(int iField=0; iField<feature.ogr().GetFieldCount(); iField++) - { - std::string key, item = feature.ogr().GetFieldDefnRef(iField)->GetNameRef(); - key = item; - std::string::iterator end = std::remove_if(key.begin(),key.end(),IsNotAlphaNum); - std::transform(key.begin(), end, key.begin(), tolower); - - OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(iField)->GetType(); - - if(fieldType == OFTString || fieldType == OFTInteger || fieldType == OFTInteger64) - { - std::string tmpKey="field."+key.substr(0, end - key.begin()); - AddChoice(tmpKey,item); - } - } - } - - // Check that the extension of the output parameter is XML (mandatory for - // StatisticsXMLFileWriter) - // Check it here to trigger the error before polygons analysis - - if ( HasValue("out") ) - { - // Store filename extension - // Check that the right extension is given : expected .xml - const std::string extension = itksys::SystemTools::GetFilenameLastExtension(this->GetParameterString("out")); - - if (itksys::SystemTools::LowerCase(extension) != ".xml") - { - otbAppLogFATAL( << extension << " is a wrong extension for parameter \"out\": Expected .xml" ); - } - } } - void DoExecute() override + void DoExecute() { - // Filters - VectorDataReprojFilterType::Pointer m_VectorDataReprojectionFilter; - RasterizeFilterType::Pointer m_RasterizeFIDFilter; - RasterizeFilterType::Pointer m_RasterizeClassFilter; - NoDataMaskFilterType::Pointer m_NoDataFilter; - CastFilterType::Pointer m_NoDataCastFilter; - StatsFilterType::Pointer m_FIDStatsFilter; - StatsFilterType::Pointer m_ClassStatsFilter; - // Retrieve the field name std::vector<int> selectedCFieldIdx = GetSelectedItems("field"); @@ -254,14 +195,72 @@ private: fidMap.erase(intNoData); classMap.erase(intNoData); - StatWriterType::Pointer statWriter = StatWriterType::New(); - statWriter->SetFileName(this->GetParameterString("out")); - statWriter->AddInputMap<StatsFilterType::LabelPopulationMapType>("samplesPerClass",classMap); - statWriter->AddInputMap<StatsFilterType::LabelPopulationMapType>("samplesPerVector",fidMap); - statWriter->Update(); + m_StatWriter = StatWriterType::New(); + m_StatWriter->SetFileName(this->GetParameterString("out")); + m_StatWriter->AddInputMap<StatsFilterType::LabelPopulationMapType>("samplesPerClass", classMap); + m_StatWriter->AddInputMap<StatsFilterType::LabelPopulationMapType>("samplesPerVector", fidMap); + m_StatWriter->Update(); } - + + void DoUpdateParameters() + { + if (HasValue("vec")) + { + std::string vectorFile = GetParameterString("vec"); + ogr::DataSource::Pointer ogrDS = + ogr::DataSource::New(vectorFile, ogr::DataSource::Modes::Read); + ogr::Layer layer = ogrDS->GetLayer(0); + ogr::Feature feature = layer.ogr().GetNextFeature(); + + ClearChoices("field"); + + for(int iField=0; iField<feature.ogr().GetFieldCount(); iField++) + { + std::string key, item = feature.ogr().GetFieldDefnRef(iField)->GetNameRef(); + key = item; + std::string::iterator end = std::remove_if(key.begin(),key.end(),IsNotAlphaNum); + std::transform(key.begin(), end, key.begin(), tolower); + + OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(iField)->GetType(); + + if(fieldType == OFTString || fieldType == OFTInteger || fieldType == OFTInteger64) + { + std::string tmpKey="field."+key.substr(0, end - key.begin()); + AddChoice(tmpKey,item); + } + } + } + + // Check that the extension of the output parameter is XML (mandatory for + // StatisticsXMLFileWriter) + // Check it here to trigger the error before polygons analysis + + if (HasValue("out")) + { + // Store filename extension + // Check that the right extension is given : expected .xml + const std::string extension = itksys::SystemTools::GetFilenameLastExtension(this->GetParameterString("out")); + + if (itksys::SystemTools::LowerCase(extension) != ".xml") + { + otbAppLogFATAL( << extension << " is a wrong extension for parameter \"out\": Expected .xml" ); + } + } + } + + + +private: + // Filters + VectorDataReprojFilterType::Pointer m_VectorDataReprojectionFilter; + RasterizeFilterType::Pointer m_RasterizeFIDFilter; + RasterizeFilterType::Pointer m_RasterizeClassFilter; + NoDataMaskFilterType::Pointer m_NoDataFilter; + CastFilterType::Pointer m_NoDataCastFilter; + StatsFilterType::Pointer m_FIDStatsFilter; + StatsFilterType::Pointer m_ClassStatsFilter; + StatWriterType::Pointer m_StatWriter; }; diff --git a/app/otbImageClassifierFromDeepFeatures.cxx b/app/otbImageClassifierFromDeepFeatures.cxx index 98763559bfebbe710fd3e5a7a9e0b9214bc4f111..f3ffd2731307ecd0e0f7afdb5f6e78b9a4ac4163 100644 --- a/app/otbImageClassifierFromDeepFeatures.cxx +++ b/app/otbImageClassifierFromDeepFeatures.cxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even @@ -61,7 +61,6 @@ private: // Populate group ShareParameter(ss_key_group.str(), "tfmodel." + ss_key_group.str(), ss_desc_group.str()); - } @@ -107,10 +106,8 @@ private: ShareParameter("out" , "classif.out" , "Output image" , "Output image" ); ShareParameter("confmap" , "classif.confmap" , "Confidence map image", "Confidence map image"); ShareParameter("ram" , "classif.ram" , "Ram" , "Ram" ); - } - void DoUpdateParameters() { UpdateInternalParameters("classif"); @@ -122,12 +119,8 @@ private: GetInternalApplication("classif")->SetParameterInputImage("in", GetInternalApplication("tfmodel")->GetParameterOutputImage("out")); UpdateInternalParameters("classif"); ExecuteInternal("classif"); - } // DOExecute() - - void AfterExecuteAndWriteOutputs() - { - // Nothing to do } + }; } // namespace Wrapper } // namespace otb diff --git a/app/otbLabelImageSampleSelection.cxx b/app/otbLabelImageSampleSelection.cxx index 40591b9c42d648ec64ebfd90dfc7ccc5755e68ab..50396fa0ac4ded119bd31268327fea4032b15f2f 100644 --- a/app/otbLabelImageSampleSelection.cxx +++ b/app/otbLabelImageSampleSelection.cxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even @@ -35,7 +35,7 @@ class LabelImageSampleSelection : public Application { public: /** Standard class typedefs. */ - typedef LabelImageSampleSelection Self; + typedef LabelImageSampleSelection Self; typedef Application Superclass; typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; @@ -385,4 +385,4 @@ private: } // end namespace wrapper } // end namespace otb -OTB_APPLICATION_EXPORT( otb::Wrapper::LabelImageSampleSelection ) +OTB_APPLICATION_EXPORT(otb::Wrapper::LabelImageSampleSelection) diff --git a/app/otbPatchesExtraction.cxx b/app/otbPatchesExtraction.cxx index 1191486620699d49569793cd50b4ef109128f7be..7b0ce4565e687da42bdf9adb71cadd883acd56cc 100644 --- a/app/otbPatchesExtraction.cxx +++ b/app/otbPatchesExtraction.cxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even @@ -136,10 +136,6 @@ public: } } - void DoUpdateParameters() - { - } - void DoInit() { @@ -237,6 +233,12 @@ public: } } + + + void DoUpdateParameters() + { + } + private: std::vector<SourceBundle> m_Bundles; @@ -245,4 +247,4 @@ private: } // end namespace wrapper } // end namespace otb -OTB_APPLICATION_EXPORT( otb::Wrapper::PatchesExtraction ) +OTB_APPLICATION_EXPORT(otb::Wrapper::PatchesExtraction) diff --git a/app/otbPatchesSelection.cxx b/app/otbPatchesSelection.cxx index eb6a31a89cc456dae932b74cc798462cdec19737..5cbdc82a3e0b2d665d4d332d6cddee979d22e3bc 100644 --- a/app/otbPatchesSelection.cxx +++ b/app/otbPatchesSelection.cxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even @@ -68,7 +68,7 @@ class PatchesSelection : public Application { public: /** Standard class typedefs. */ - typedef PatchesSelection Self; + typedef PatchesSelection Self; typedef Application Superclass; typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; @@ -100,11 +100,6 @@ public: typedef itk::MaskImageFilter<UInt8ImageType, UInt8ImageType, UInt8ImageType> MaskImageFilterType; - void DoUpdateParameters() - { - } - - void DoInit() { @@ -167,22 +162,15 @@ public: { public: SampleBundle(){} - SampleBundle(unsigned int nClasses){ - dist = DistributionType(nClasses); - id = 0; + explicit SampleBundle(unsigned int nClasses): dist(DistributionType(nClasses)), id(0), black(true){ (void) point; - black = true; (void) index; } ~SampleBundle(){} - SampleBundle(const SampleBundle & other){ - dist = other.GetDistribution(); - id = other.GetSampleID(); - point = other.GetPosition(); - black = other.GetBlack(); - index = other.GetIndex(); - } + SampleBundle(const SampleBundle & other): dist(other.GetDistribution()), id(other.GetSampleID()), + point(other.GetPosition()), black(other.GetBlack()), index(other.GetIndex()) + {} DistributionType GetDistribution() const { @@ -539,7 +527,7 @@ public: PopulateVectorData(seed); } - void PopulateVectorData(std::vector<SampleBundle> & samples) + void PopulateVectorData(const std::vector<SampleBundle> & samples) { // Get data tree DataTreeType::Pointer treeTrain = m_OutVectorDataTrain->GetDataTree(); @@ -657,6 +645,11 @@ public: } + + void DoUpdateParameters() + { + } + private: RadiusType m_Radius; IsNoDataFilterType::Pointer m_NoDataFilter; diff --git a/app/otbTensorflowModelServe.cxx b/app/otbTensorflowModelServe.cxx index f381ea6628809407ba91e05146b229238414e694..af260a1ea18c4d8ee75c09f5864a4e0d61d939e3 100644 --- a/app/otbTensorflowModelServe.cxx +++ b/app/otbTensorflowModelServe.cxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even @@ -62,10 +62,6 @@ public: /** Typedefs for images */ typedef FloatVectorImageType::SizeType SizeType; - void DoUpdateParameters() - { - } - // // Store stuff related to one source // @@ -329,6 +325,11 @@ public: SetParameterOutputImage("out", m_TFFilter->GetOutput()); } } + + + void DoUpdateParameters() + { + } private: diff --git a/app/otbTensorflowModelTrain.cxx b/app/otbTensorflowModelTrain.cxx index ffb88e4c2e32b6d885a0ed882cc0b50a8dfe4320..e79019980537f873efc85cc8dd22e4bd05fce82e 100644 --- a/app/otbTensorflowModelTrain.cxx +++ b/app/otbTensorflowModelTrain.cxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even @@ -362,7 +362,7 @@ public: // // Get user placeholders // - TrainModelFilterType::DictType GetUserPlaceholders(const std::string key) + TrainModelFilterType::DictType GetUserPlaceholders(const std::string & key) { TrainModelFilterType::DictType dict; TrainModelFilterType::StringList expressions = GetParameterStringList(key); diff --git a/app/otbTrainClassifierFromDeepFeatures.cxx b/app/otbTrainClassifierFromDeepFeatures.cxx index ada83c51fdb8674a39e8099120e5f796cd6f8481..39ac41898a450159a4c50133883006c4466bcb51 100644 --- a/app/otbTrainClassifierFromDeepFeatures.cxx +++ b/app/otbTrainClassifierFromDeepFeatures.cxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even @@ -121,11 +121,6 @@ private: GetInternalApplication("train")->AddImageToParameterInputImageList("io.il", GetInternalApplication("tfmodel")->GetParameterOutputImage("out")); UpdateInternalParameters("train"); ExecuteInternal("train"); - } // DOExecute() - - void AfterExecuteAndWriteOutputs() - { - // Nothing to do } }; diff --git a/include/otbTensorflowCommon.cxx b/include/otbTensorflowCommon.cxx index 300f4b5a2653ab5863d147e0efb97033457c5d51..662c9d3e979c5e67ccf9effc4564c9d9fd5c6d0e 100644 --- a/include/otbTensorflowCommon.cxx +++ b/include/otbTensorflowCommon.cxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/include/otbTensorflowCommon.h b/include/otbTensorflowCommon.h index 512ff5d9b86d48c2db27a545ba716d41c6b88a5c..fbd7281035185c2acc3a56dac3850a23d76280df 100644 --- a/include/otbTensorflowCommon.h +++ b/include/otbTensorflowCommon.h @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/include/otbTensorflowCopyUtils.cxx b/include/otbTensorflowCopyUtils.cxx index 63f4a98cff1df0226fca87e43f7ba86fd6a1edf2..353d37f8b6bb6237d9aff6b567ea01ff336e9fa8 100644 --- a/include/otbTensorflowCopyUtils.cxx +++ b/include/otbTensorflowCopyUtils.cxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/include/otbTensorflowCopyUtils.h b/include/otbTensorflowCopyUtils.h index 91cddef555f2eadb89862e65dc82c989fc2444cc..c369febc017c5c475a742cde18b6abf924353d64 100644 --- a/include/otbTensorflowCopyUtils.h +++ b/include/otbTensorflowCopyUtils.h @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/include/otbTensorflowDataTypeBridge.cxx b/include/otbTensorflowDataTypeBridge.cxx index 0a9eded8239e39021609adea8e9291f3bb22f554..a510cb4ea5ecab0c1505e690d79922b2299ddc0d 100644 --- a/include/otbTensorflowDataTypeBridge.cxx +++ b/include/otbTensorflowDataTypeBridge.cxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/include/otbTensorflowDataTypeBridge.h b/include/otbTensorflowDataTypeBridge.h index bce9791fbe18744e1367c7cdf7d421a980981441..af6be18d335761b7261e6b8c7288cf9b07122bc8 100644 --- a/include/otbTensorflowDataTypeBridge.h +++ b/include/otbTensorflowDataTypeBridge.h @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/include/otbTensorflowGraphOperations.cxx b/include/otbTensorflowGraphOperations.cxx index 3a4a4402aff61f18e622e7dc659f194fc12a1b1a..18d6f08f7053734efef71c4763da61c614b50e5c 100644 --- a/include/otbTensorflowGraphOperations.cxx +++ b/include/otbTensorflowGraphOperations.cxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even @@ -109,11 +109,8 @@ void GetTensorAttributes(const tensorflow::protobuf::Map<std::string, tensorflow itkDebugMacro("Found: " << layername << " in the model"); - // Set default to DT_FLOAT - tensorflow::DataType ts_dt = tensorflow::DT_FLOAT; - // Default (input?) tensor type - ts_dt = tensor_info.dtype(); + tensorflow::DataType ts_dt = tensor_info.dtype(); dataTypes.push_back(ts_dt); // Get the tensor's shape diff --git a/include/otbTensorflowGraphOperations.h b/include/otbTensorflowGraphOperations.h index 61c92411cc1a5ad9103d4fa25af662190de09f1c..f731c8d899a787f51626afe95fd2cc5b406df8da 100644 --- a/include/otbTensorflowGraphOperations.h +++ b/include/otbTensorflowGraphOperations.h @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/include/otbTensorflowMultisourceModelBase.h b/include/otbTensorflowMultisourceModelBase.h index 693a150d68436d851c1f58b475a283d4350ae7ac..fe866733ebb70b4ad21d470352ccc68591b2e017 100644 --- a/include/otbTensorflowMultisourceModelBase.h +++ b/include/otbTensorflowMultisourceModelBase.h @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even @@ -131,7 +131,7 @@ public: itkGetMacro(OutputExpressionFields, SizeListType); /** User placeholders */ - void SetUserPlaceholders(DictType dict) {m_UserPlaceholders = dict;} + void SetUserPlaceholders(const DictType & dict) {m_UserPlaceholders = dict;} DictType GetUserPlaceholders() {return m_UserPlaceholders;} /** Target nodes names */ diff --git a/include/otbTensorflowMultisourceModelBase.hxx b/include/otbTensorflowMultisourceModelBase.hxx index fd3cefc7f08c3830e81493fae56237c9e70cf057..70cd94ced434f0d97f5e5fbdb6116bd694b75bce 100644 --- a/include/otbTensorflowMultisourceModelBase.hxx +++ b/include/otbTensorflowMultisourceModelBase.hxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even @@ -23,6 +23,8 @@ TensorflowMultisourceModelBase<TInputImage, TOutputImage> { Superclass::SetCoordinateTolerance(itk::NumericTraits<double>::max() ); Superclass::SetDirectionTolerance(itk::NumericTraits<double>::max() ); + + m_SavedModel = NULL; } template <class TInputImage, class TOutputImage> @@ -103,10 +105,7 @@ TensorflowMultisourceModelBase<TInputImage, TOutputImage> { // Add the user's placeholders - for (auto& dict: this->GetUserPlaceholders()) - { - inputs.push_back(dict); - } + std::copy(this->GetUserPlaceholders().begin(), this->GetUserPlaceholders().end(), std::back_inserter(inputs)); // Run the TF session here // The session will initialize the outputs @@ -115,20 +114,15 @@ TensorflowMultisourceModelBase<TInputImage, TOutputImage> // Decloud example: For TF1 model, it is specified by the user as "tower_0:s2_t". For TF2 model, it must be specified by the user as "s2_t" // Thus, for TF2, we must transform that to "serving_default_s2_t" DictType inputs_new; - for (auto& dict: inputs) - { - DictElementType element = {m_UserNameToLayerNameMapping[dict.first], dict.second}; - inputs_new.push_back(element); - } + std::transform(inputs.begin(), inputs.end(), std::back_inserter(inputs_new), + [this](DictElementType dict) -> DictElementType {return {this->m_UserNameToLayerNameMapping[dict.first], dict.second}; }); - StringList m_OutputTensors_new; - for (auto& name: m_OutputTensors) - { - m_OutputTensors_new.push_back(m_UserNameToLayerNameMapping[name]); - } + StringList outputTensors_new; + std::transform(m_OutputTensors.begin(), m_OutputTensors.end(), std::back_inserter(outputTensors_new), + [this](std::string name) -> std::string {return this->m_UserNameToLayerNameMapping[name]; }); // Run the session, evaluating our output tensors from the graph - auto status = this->GetSavedModel()->session.get()->Run(inputs_new, m_OutputTensors_new, m_TargetNodesNames, &outputs); + auto status = this->GetSavedModel()->session.get()->Run(inputs_new, outputTensors_new, m_TargetNodesNames, &outputs); if (!status.ok()) diff --git a/include/otbTensorflowMultisourceModelFilter.h b/include/otbTensorflowMultisourceModelFilter.h index 74200eb694ed75d45800f1eb87adcd9e4c9a0f95..0a0078cd7f4e7cc9242713eeb64635d982d13081 100644 --- a/include/otbTensorflowMultisourceModelFilter.h +++ b/include/otbTensorflowMultisourceModelFilter.h @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/include/otbTensorflowMultisourceModelFilter.hxx b/include/otbTensorflowMultisourceModelFilter.hxx index 22be795bc93231f0fa34761d038bc07669a2a2ca..b0db538627861578ff8c80dcb027b798e50dcb8e 100644 --- a/include/otbTensorflowMultisourceModelFilter.hxx +++ b/include/otbTensorflowMultisourceModelFilter.hxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/include/otbTensorflowMultisourceModelLearningBase.h b/include/otbTensorflowMultisourceModelLearningBase.h index 6e4c571dc305f0cb70a24990f3f64c0adbd25eca..0663f17a3f6367d5f5fe0ebbc76b1ca71d64957d 100644 --- a/include/otbTensorflowMultisourceModelLearningBase.h +++ b/include/otbTensorflowMultisourceModelLearningBase.h @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even @@ -100,7 +100,7 @@ protected: TensorflowMultisourceModelLearningBase(); virtual ~TensorflowMultisourceModelLearningBase() {}; - virtual void GenerateOutputInformation(void); + virtual void GenerateOutputInformation(void) override; virtual void GenerateInputRequestedRegion(); diff --git a/include/otbTensorflowMultisourceModelLearningBase.hxx b/include/otbTensorflowMultisourceModelLearningBase.hxx index 49ba00df91aa28a0ef597e6f4ef1b1b31ab6a7b3..28b2328b8b82c49896ed40a1edd18fba5cebd7a7 100644 --- a/include/otbTensorflowMultisourceModelLearningBase.hxx +++ b/include/otbTensorflowMultisourceModelLearningBase.hxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/include/otbTensorflowMultisourceModelTrain.h b/include/otbTensorflowMultisourceModelTrain.h index 58d02d25306c0729607dc802d9c21c0d18b9ffbe..8ec4c38c369d532a706746c9674197ad766f657b 100644 --- a/include/otbTensorflowMultisourceModelTrain.h +++ b/include/otbTensorflowMultisourceModelTrain.h @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/include/otbTensorflowMultisourceModelTrain.hxx b/include/otbTensorflowMultisourceModelTrain.hxx index 23bb4e57cc58af0b8c4ffa1a5652bddf2cfa3b75..272dd6390668bd233c5ec41b99ff2b088ef313c3 100644 --- a/include/otbTensorflowMultisourceModelTrain.hxx +++ b/include/otbTensorflowMultisourceModelTrain.hxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/include/otbTensorflowMultisourceModelValidate.h b/include/otbTensorflowMultisourceModelValidate.h index ce9fd45c32779cb9d5e056bfb98780854bd953b2..322f6a24e288db9d9acf202e72ffe04ff8d8a8d4 100644 --- a/include/otbTensorflowMultisourceModelValidate.h +++ b/include/otbTensorflowMultisourceModelValidate.h @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/include/otbTensorflowMultisourceModelValidate.hxx b/include/otbTensorflowMultisourceModelValidate.hxx index d264ebb18eb463f27ea24400fe20ab7aa24280a1..8ec685ba81c1ae51111a077e8170dd227be7241e 100644 --- a/include/otbTensorflowMultisourceModelValidate.hxx +++ b/include/otbTensorflowMultisourceModelValidate.hxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/include/otbTensorflowSampler.h b/include/otbTensorflowSampler.h index ffd6af614475eb0d55447ebd7ccc59e9311107ff..bd363bc8ee191ce7506ca012b68171f6d8bdc828 100644 --- a/include/otbTensorflowSampler.h +++ b/include/otbTensorflowSampler.h @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/include/otbTensorflowSampler.hxx b/include/otbTensorflowSampler.hxx index cdcbf1fe0097c355b4e2eec79ccabd8b1bfc0791..8c0ea7459ad5e1ac0060438e3c6a73b760fc535a 100644 --- a/include/otbTensorflowSampler.hxx +++ b/include/otbTensorflowSampler.hxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/include/otbTensorflowSamplingUtils.cxx b/include/otbTensorflowSamplingUtils.cxx index 5a68cdb2e0ac78568a2a54ef7b7e747c60a9b1f4..5cf88f6b171b61c9576b4ca68d855a0d6059d42f 100644 --- a/include/otbTensorflowSamplingUtils.cxx +++ b/include/otbTensorflowSamplingUtils.cxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/include/otbTensorflowSamplingUtils.h b/include/otbTensorflowSamplingUtils.h index ab808a257449ad9f810bd5051e2c54a5356b02d6..585f90132ea71509fe2a08ff8f56aa1eac2abb3f 100644 --- a/include/otbTensorflowSamplingUtils.h +++ b/include/otbTensorflowSamplingUtils.h @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even @@ -27,23 +27,17 @@ public: typedef typename TImage::PixelType ValueType; typedef vnl_vector<float> CountsType; - Distribution(unsigned int nClasses){ - m_NbOfClasses = nClasses; - m_Dist = CountsType(nClasses, 0); - + explicit Distribution(unsigned int nClasses): m_NbOfClasses(nClasses), m_Dist(CountsType(nClasses, 0)) + { } - Distribution(unsigned int nClasses, float fillValue){ - m_NbOfClasses = nClasses; - m_Dist = CountsType(nClasses, fillValue); - + Distribution(unsigned int nClasses, float fillValue): m_NbOfClasses(nClasses), m_Dist(CountsType(nClasses, fillValue)) + { } - Distribution(){ - m_NbOfClasses = 2; - m_Dist = CountsType(m_NbOfClasses, 0); + Distribution(): m_NbOfClasses(2), m_Dist(CountsType(m_NbOfClasses, 0)) + { } - Distribution(const Distribution & other){ - m_Dist = other.Get(); - m_NbOfClasses = m_Dist.size(); + Distribution(const Distribution & other): m_Dist(other.Get()), m_NbOfClasses(m_Dist.size()) + { } ~Distribution(){} diff --git a/include/otbTensorflowSource.h b/include/otbTensorflowSource.h index ddec24b50d40b3db32588e5cbbbef44d7257f7d0..1556997f9a20c02c1f5f9fd80f92c0fc38270657 100644 --- a/include/otbTensorflowSource.h +++ b/include/otbTensorflowSource.h @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even @@ -25,9 +25,9 @@ namespace otb { /* - * This is a simple helper to create images concatenation. + * This is a helper for images concatenation. * Images must have the same size. - * This is basically the common input type used in every OTB-TF applications. + * This is the common input type used in every OTB-TF applications. */ template<class TImage> class TensorflowSource @@ -60,7 +60,7 @@ public: // Get the source output FloatVectorImagePointerType Get(); - TensorflowSource(){}; + TensorflowSource(); virtual ~TensorflowSource (){}; private: diff --git a/include/otbTensorflowSource.hxx b/include/otbTensorflowSource.hxx index deb8abd2e56ec2d520656c43caddf02dee6f90a5..2ad575866fda4ba7baa9dc494c44bcc38b79f0cd 100644 --- a/include/otbTensorflowSource.hxx +++ b/include/otbTensorflowSource.hxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even @@ -17,12 +17,21 @@ namespace otb { +// +// Constructor +// +template <class TImage> +TensorflowSource<TImage> +::TensorflowSource() +{} + // // Prepare the big stack of images // template <class TImage> void -TensorflowSource<TImage>::Set(FloatVectorImageListType * inputList) +TensorflowSource<TImage> +::Set(FloatVectorImageListType * inputList) { // Create one stack for input images list m_Concatener = ListConcatenerFilterType::New(); diff --git a/include/otbTensorflowStreamerFilter.h b/include/otbTensorflowStreamerFilter.h index 6aba8656a1119f10968876304755f420f3768be7..4730d3691cd3bd64954091c3bfdbb5bb7422d870 100644 --- a/include/otbTensorflowStreamerFilter.h +++ b/include/otbTensorflowStreamerFilter.h @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/include/otbTensorflowStreamerFilter.hxx b/include/otbTensorflowStreamerFilter.hxx index b323047b0d90b791f4bdf7b23f66af25d7de92c3..59904a54f3df99048dfa383e22dad0ee7bef9784 100644 --- a/include/otbTensorflowStreamerFilter.hxx +++ b/include/otbTensorflowStreamerFilter.hxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/python/ckpt2savedmodel.py b/python/ckpt2savedmodel.py index 1892757e144fb6854df4356d9bd74af96f71374c..117203bafd89bcbfaa272952323434dac4046a8b 100755 --- a/python/ckpt2savedmodel.py +++ b/python/ckpt2savedmodel.py @@ -28,6 +28,7 @@ keras in Tensorflow 2). import argparse from tricks import ckpt_to_savedmodel + def main(): """ Main function @@ -48,5 +49,6 @@ def main(): savedmodel_path=params.model, clear_devices=params.clear_devices) + if __name__ == "__main__": main() diff --git a/test/otbTensorflowCopyUtilsTests.cxx b/test/otbTensorflowCopyUtilsTests.cxx index 249f16e6368c7ac87e82f8c81ebbb185cf064c13..5b9586460aa1e0cc51a115ea1a6031ebd3cf805e 100644 --- a/test/otbTensorflowCopyUtilsTests.cxx +++ b/test/otbTensorflowCopyUtilsTests.cxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even diff --git a/test/otbTensorflowTests.cxx b/test/otbTensorflowTests.cxx index c49891210bd8a989947ffd655d35850207555221..50e9a91a57b85feecccf44b49b5c3b57f7e69ec3 100644 --- a/test/otbTensorflowTests.cxx +++ b/test/otbTensorflowTests.cxx @@ -1,7 +1,7 @@ /*========================================================================= Copyright (c) 2018-2019 IRSTEA - Copyright (c) 2020-2020 INRAE + Copyright (c) 2020-2021 INRAE This software is distributed WITHOUT ANY WARRANTY; without even @@ -21,4 +21,3 @@ void RegisterTests() REGISTER_TEST(boolVecValueToTensorTest); } -