#include <layer_node.h>
#include <nntrainer_error.h>
#include <nntrainer_log.h>
-#include <node_exporter.h>
#include <parse_util.h>
#include <time_dist.h>
#include <util_func.h>
iter++) {
const auto &ln = *iter;
- IniSection s(ln->getName());
+ IniSection s = IniSection::FromExportable(ln->getName(), *ln);
s.setEntry("type", ln->getType());
- Exporter e;
- ln->exportTo(e, ExportMethods::METHOD_STRINGVECTOR);
-
- const auto key_val_pairs =
- e.getResult<ExportMethods::METHOD_STRINGVECTOR>();
-
- for (const auto &pair : *key_val_pairs) {
- s.setEntry(pair.first, pair.second);
- }
-
sections.push_back(s);
}
"permitted, path: "
<< file_path;
- IniSection model_section("model");
+ IniSection model_section = IniSection::FromExportable("model", *this);
model_section.setEntry("type", "NeuralNetwork");
- Exporter e;
- e.saveResult(model_props, ExportMethods::METHOD_STRINGVECTOR, this);
- e.saveResult(model_flex_props, ExportMethods::METHOD_STRINGVECTOR, this);
-
- const auto key_val_pairs = e.getResult<ExportMethods::METHOD_STRINGVECTOR>();
- for (const auto &pair : *key_val_pairs) {
- model_section.setEntry(pair.first, pair.second);
- }
-
IniWrapper wrapper("model_saver", {model_section});
wrapper.save_ini(file_path);
print(out, flags, layer_preset);
}
+void NeuralNetwork::exportTo(Exporter &exporter,
+ const ExportMethods &method) const {
+ exporter.saveResult(model_props, method, this);
+ exporter.saveResult(model_flex_props, method, this);
+}
+
void NeuralNetwork::print(std::ostream &out, unsigned int flags,
LayerNode::PrintPreset layerPrintPreset) {
if (flags & PRINT_INST_INFO) {
namespace nntrainer {
+class Exporter;
+enum class ExportMethods;
+
/**
* @brief Enumeration of Network Type
*/
*/
int getLayer(const char *name, NodeType *layer);
+ /**
+ * @brief this function helps exporting the layer in a predefined format,
+ * while workarounding issue caused by templated function type eraser
+ *
+ * @param exporter exporter that conatins exporting logic
+ * @param method enum value to identify how it should be exported to
+ */
+ void exportTo(Exporter &exporter, const ExportMethods &method) const;
+
/**
* @brief get input dimension of neural network
* @retval std::vector<TensorDim> input dimension
#include <iostream>
#include <map>
#include <string>
-
#include <vector>
+#include <node_exporter.h>
+
#ifndef __INI_WRAPPER_H__
#define __INI_WRAPPER_H__
*/
IniSection() : section_name(""), entry{} {};
+ /**
+ * @brief Construct a new Ini Section object which implements object::exportTo
+ *
+ * @tparam Exportable object with member object::exportTo
+ * @param section_name section name
+ * @param exportable exportable object
+ */
+ template <typename Exportable>
+ static IniSection FromExportable(const std::string §ion_name,
+ const Exportable &exportable) {
+ IniSection s(section_name);
+ Exporter e;
+ exportable.exportTo(e, ExportMethods::METHOD_STRINGVECTOR);
+ const auto key_val_pairs =
+ e.getResult<ExportMethods::METHOD_STRINGVECTOR>();
+
+ if (!key_val_pairs) {
+ throw std::invalid_argument("returend pairs are nullptr!");
+ }
+
+ for (const auto &pair : *key_val_pairs) {
+ s.setEntry(pair.first, pair.second);
+ }
+ return s;
+ }
+
/**
* @brief Default destructor for the Ini Section object
*