return std::move(graph);
}
+std::unique_ptr<loco::Graph> Frontend::load(const ModelSignature &signature, std::istream *stream,
+ FileType type) const
+{
+ tensorflow::GraphDef tf_graph_def;
+
+ load_tf(stream, type, tf_graph_def);
+
+ auto graph = loco::make_graph();
+
+ convert_graph(signature, tf_graph_def, graph.get());
+
+ return std::move(graph);
+}
+
} // namespace tf
} // namespace moco
#include <gtest/gtest.h>
+#include <cstring>
+
+#define STRING(content) #content
+
TEST(MocoTensotFlowFrontendTest, Dummy) { moco::tf::Frontend frontend; }
TEST(TensorFlowFrontend, load_model)
frontend.load(signature, "../../../test/tf/Placeholder_000.pb",
moco::tf::Frontend::FileType::Binary);
}
+
+namespace
+{
+
+struct membuf : std::streambuf
+{
+ membuf(char const *base, size_t size)
+ {
+ char *p(const_cast<char *>(base));
+ this->setg(p, p, p + size);
+ }
+};
+
+struct imemstream : virtual membuf, std::istream
+{
+ imemstream(char const *base, size_t size)
+ : membuf(base, size), std::istream(static_cast<std::streambuf *>(this))
+ {
+ }
+};
+
+// clang-format off
+const char *basic_pbtxtdata = STRING(
+node {
+ name: "Placeholder"
+ op: "Placeholder"
+ attr {
+ key: "dtype"
+ value {
+ type: DT_FLOAT
+ }
+ }
+ attr {
+ key: "shape"
+ value {
+ shape {
+ dim {
+ size: 1
+ }
+ dim {
+ size: 2
+ }
+ dim {
+ size: 1
+ }
+ dim {
+ size: 2
+ }
+ }
+ }
+ }
+}
+node {
+ name: "output/identity"
+ op: "Identity"
+ input: "Placeholder"
+ attr {
+ key: "T"
+ value {
+ type: DT_FLOAT
+ }
+ }
+}
+);
+// clang-format on
+
+} // namespace
+
+TEST(TensorFlowFrontend, load_model_withio)
+{
+ moco::tf::Frontend frontend;
+ moco::tf::ModelSignature signature;
+
+ imemstream mempb(basic_pbtxtdata, std::strlen(basic_pbtxtdata));
+
+ signature.add_input("Placeholder");
+ signature.add_output("output/identity");
+
+ frontend.load(signature, &mempb, moco::tf::Frontend::FileType::Text);
+}