This commit applies `plier-tf` into `moco-tf`.
Signed-off-by: Hyun Sik Yoon <hyunsik.yoon@samsung.com>
target_link_libraries(moco_tf_frontend PRIVATE moco_log)
target_link_libraries(moco_tf_frontend PRIVATE pepper_strcast)
target_link_libraries(moco_tf_frontend PRIVATE locomotiv)
+target_link_libraries(moco_tf_frontend PRIVATE plier_tf)
if(NOT ENABLE_TEST)
return()
target_link_libraries(moco_tf_frontend_test moco_log)
target_link_libraries(moco_tf_frontend_test moco_tf_frontend)
target_link_libraries(moco_tf_frontend_test stdex)
+target_link_libraries(moco_tf_frontend_test plier_tf)
add_test(moco_tf_frontend_test moco_tf_frontend_test)
require("moco-log")
require("pepper-strcast")
require("locomotiv")
+require("plier-tf")
#include "BiasAddCanonicalizer.h"
-#include "Convert.h"
#include "Knob.h"
#include "Dialect/TFDialect.h"
#include <moco/tf/Names.h>
#include <moco/Log.h>
+#include <plier/tf/Convert.h>
namespace
{
+using plier::tf::DataLayout;
bool canonicalize_biasadd(loco::Graph *graph, moco::tf::TFBiasAdd *node)
{
INFO(l) << "TFNodeCanonicalize TFBiasAdd begin";
// tensorflow data_format: one of NHWC or NCHW.
- auto data_layout = moco::tf::as_DataLayout(node->data_layout());
+ auto data_layout = plier::tf::as_data_layout(node->data_layout());
// creating loco nodes
auto bias_enc = graph->nodes()->create<loco::BiasEncode>();
auto bias_add = graph->nodes()->create<loco::TensorBiasAdd>();
{
- if (data_layout == moco::tf::DataLayout::NHWC)
+ if (data_layout == DataLayout::NHWC)
{
INFO(l) << "TFNodeCanonicalize TFBiasAdd axis 3";
bias_add->axis(3);
}
- else if (data_layout == moco::tf::DataLayout::NCHW)
+ else if (data_layout == DataLayout::NCHW)
{
INFO(l) << "TFNodeCanonicalize TFBiasAdd axis 1";
bias_add->axis(1); // Channel
#include "ConstCanonicalizer.h"
-#include "Convert.h"
#include "Knob.h"
#include "Dialect/TFDialect.h"
#include "Dialect/TFNodeImpl.h"
#include <moco/Log.h>
+#include <plier/tf/Convert.h>
#include <stdex/Memory.h>
namespace
{
+using plier::tf::DataLayout;
-void set_feature_enc(loco::FeatureEncode *feature_enc, moco::tf::DataLayout data_layout)
+void set_feature_enc(loco::FeatureEncode *feature_enc, DataLayout data_layout)
{
auto enc = stdex::make_unique<loco::PermutingEncoder<loco::Domain::Feature>>();
- if (data_layout == moco::tf::DataLayout::NHWC)
+ if (data_layout == DataLayout::NHWC)
{
enc->perm()->axis(loco::FeatureAxis::Count) = 0;
enc->perm()->axis(loco::FeatureAxis::Height) = 1;
enc->perm()->axis(loco::FeatureAxis::Width) = 2;
enc->perm()->axis(loco::FeatureAxis::Depth) = 3;
}
- else if (data_layout == moco::tf::DataLayout::NCHW)
+ else if (data_layout == DataLayout::NCHW)
{
enc->perm()->axis(loco::FeatureAxis::Count) = 0;
enc->perm()->axis(loco::FeatureAxis::Depth) = 1;
feature_enc->encoder(std::move(enc));
}
-void set_filter_enc(loco::FilterEncode *filter_enc, moco::tf::DataLayout data_layout)
+void set_filter_enc(loco::FilterEncode *filter_enc, DataLayout data_layout)
{
auto enc = stdex::make_unique<loco::PermutingEncoder<loco::Domain::Filter>>();
filter_enc->encoder(std::move(enc));
}
-void set_feature_dec(loco::FeatureDecode *feature_dec, moco::tf::DataLayout data_layout)
+void set_feature_dec(loco::FeatureDecode *feature_dec, DataLayout data_layout)
{
auto dec = stdex::make_unique<loco::PermutingDecoder<loco::Domain::Feature>>();
- if (data_layout == moco::tf::DataLayout::NHWC)
+ if (data_layout == DataLayout::NHWC)
{
dec->perm()->axis(loco::FeatureAxis::Count) = 0;
dec->perm()->axis(loco::FeatureAxis::Height) = 1;
dec->perm()->axis(loco::FeatureAxis::Width) = 2;
dec->perm()->axis(loco::FeatureAxis::Depth) = 3;
}
- else if (data_layout == moco::tf::DataLayout::NCHW)
+ else if (data_layout == DataLayout::NCHW)
{
dec->perm()->axis(loco::FeatureAxis::Count) = 0;
dec->perm()->axis(loco::FeatureAxis::Depth) = 1;
* TFConv2D is disconnected from other nodes
*/
- auto data_layout = moco::tf::as_DataLayout(node->data_layout());
+ auto data_layout = plier::tf::as_data_layout(node->data_layout());
auto feature_enc = graph->nodes()->create<loco::FeatureEncode>();
auto filter_enc = graph->nodes()->create<loco::FilterEncode>();
#include <stdex/Memory.h>
+#include <cassert>
+
namespace
{
#include "Dialect/TFNodeDecl.h"
-#include "Convert.h"
-
#include <loco/IR/Stride.h>
#include <loco/IR/Pad.h>
#include <string>
+#include <vector>
namespace moco
{
#include "TestHelper.h"
#include <loco.h>
+#include <plier/tf/TestHelper.h>
#include <gtest/gtest.h>
signature.add_output(moco::tf::TensorName("output/identity", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(basic_pbtxtdata, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(basic_pbtxtdata, graph_def));
std::unique_ptr<loco::Graph> graph = importer.import(signature, graph_def);
loco::Graph::InputContext *inputs = graph->inputs();
#include <loco/IR/PermutingCodec.h>
#include <stdex/Memory.h>
+#include <plier/tf/Convert.h>
#include <cassert>
#include <stdexcept>
{
// note: even though "data_format" is not entered when a model is written,
// TF seems to generate "data_format" field into a pb file
- if (!has_attrs(node, {"T", "data_format", "ksize", "padding", "strides"}))
+ if (!plier::tf::has_attrs(node, {"T", "data_format", "ksize", "padding", "strides"}))
return false;
if (node.input_size() != 1)
void AvgPoolGraphBuilder::build(const tensorflow::NodeDef &node, GraphBuilderContext *context) const
{
+ using plier::tf::DataLayout;
+
assert(context != nullptr);
loco::Graph *graph = context->graph();
avgPool2d_node->convention(loco::AvgPool2D::Convention::Valid);
// tensorflow data_format, e.g., NHWC, NCHW, etc.
- auto data_layout = get_data_layout(node, "data_format");
+ auto data_layout = plier::tf::get_data_layout(node, "data_format");
if (!(data_layout == DataLayout::NHWC || data_layout == DataLayout::NCHW))
{
throw std::runtime_error("Not supported data layout at AvgPoolGraphBuilder");
// to loco attr: not defined, TBD, window, annot, stride
// tf ksize -> loco window
- auto tf_ksize = get_list_attr(node, "ksize");
+ auto tf_ksize = plier::tf::get_list_attr(node, "ksize");
auto window = avgPool2d_node->window();
if (data_layout == DataLayout::NHWC)
assert(false);
// tf strides -> loco stride
- auto tf_strides = get_list_attr(node, "strides");
+ auto tf_strides = plier::tf::get_list_attr(node, "strides");
auto stride = avgPool2d_node->stride();
if (data_layout == DataLayout::NHWC)
assert(false);
// tf paddings -> PaddingData annotation
- auto tf_padding = moco::str_toupper(get_string_attr(node, "padding"));
+ auto tf_padding = moco::str_toupper(plier::tf::get_string_attr(node, "padding"));
auto padding_data = stdex::make_unique<PaddingData>(tf_padding);
avgPool2d_node->annot(std::move(padding_data));
}
#include <loco.h>
#include <loco/IR/TensorShape.h>
#include <loco/IR/FeatureShape.h>
+#include <plier/tf/TestHelper.h>
#include <gtest/gtest.h>
signature.add_output(moco::tf::TensorName("avgpool", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(avgpool_01_pbtxtdata, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(avgpool_01_pbtxtdata, graph_def));
std::unique_ptr<loco::Graph> graph = importer.import(signature, graph_def);
// what to test:
#include "BiasAdd.h"
-#include "Convert.h"
#include "GraphBuilder.h"
#include "GraphBuilderContext.h"
#include "Knob.h"
#include <loco.h>
#include <loco/IR/PermutingCodec.h>
#include <stdex/Memory.h>
+#include <plier/tf/Convert.h>
#include <tensorflow/core/framework/graph.pb.h>
// note: even though "data_format" is not entered when a model is written,
// TF seems to generate "data_format" field into a pb file
- if (!has_attrs(node, {"T", "data_format"}))
+ if (!plier::tf::has_attrs(node, {"T", "data_format"}))
return false;
// TODO add type check
UpdateQueue *updates = context->updates();
// tensorflow data_format: one of NHWC or NCHW.
- auto data_layout = get_data_layout(node, "data_format");
+ auto data_layout = plier::tf::get_data_layout(node, "data_format");
// creating loco nodes
auto bias_enc = graph->nodes()->create<loco::BiasEncode>();
auto bias_add = graph->nodes()->create<loco::BiasAdd<loco::Domain::Tensor>>();
{
+ using plier::tf::DataLayout;
+
if (data_layout == DataLayout::NHWC)
{
bias_add->axis(3);
UpdateQueue *updates = context->updates();
// tensorflow data_format: one of NHWC or NCHW.
- auto data_layout = get_string_attr(node, "data_format");
+ auto data_layout = plier::tf::get_string_attr(node, "data_format");
auto tf_bias_add = graph->nodes()->create<moco::tf::TFBiasAdd>();
tf_bias_add->data_layout(data_layout);
#include "IR/TFBiasAdd.h"
#include <loco.h>
+#include <plier/tf/TestHelper.h>
#include <gtest/gtest.h>
signature.add_output(moco::tf::TensorName("out", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(bias_add_01_pbtxtdata, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(bias_add_01_pbtxtdata, graph_def));
// Test "BiasAddGraphBuilderImpl<ImportTarget::TensorFlow>"
{
signature.add_output(moco::tf::TensorName("out", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(bias_add_NCHW_pbtxtdata, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(bias_add_NCHW_pbtxtdata, graph_def));
std::unique_ptr<loco::Graph> graph = importer.import(signature, graph_def);
// Test "BiasAddGraphBuilderImpl<ImportTarget::TensorFlow>"
* limitations under the License.
*/
-#include "Convert.h"
#include "GraphBuilder.h"
#include "GraphBuilderContext.h"
#include <loco.h>
#include <stdex/Memory.h>
+#include <plier/tf/Convert.h>
#include <tensorflow/core/framework/graph.pb.h>
// Concat node SHOULD have 3 or more inputs, that is 2 + axis
const int num_inputs = node.input_size() - 1;
assert(num_inputs >= 2);
- assert(num_inputs == get_int_attr(node, "N"));
- return (num_inputs >= 2) && (num_inputs == get_int_attr(node, "N"));
+ assert(num_inputs == plier::tf::get_int_attr(node, "N"));
+ return (num_inputs >= 2) && (num_inputs == plier::tf::get_int_attr(node, "N"));
}
void ConcatV2GraphBuilder::build(const tensorflow::NodeDef &node,
std::string axis_name = node.input(num_inputs);
const tensorflow::NodeDef *tfnode = nodedef->node(axis_name);
// assume data type is int32
- assert(get_datatype_attr(*tfnode, "dtype") == tensorflow::DataType::DT_INT32);
- const auto &tensor = get_tensor_attr(*tfnode, "value");
+ assert(plier::tf::get_datatype_attr(*tfnode, "dtype") == tensorflow::DataType::DT_INT32);
+ const auto &tensor = plier::tf::get_tensor_attr(*tfnode, "value");
assert(tensor.int_val_size() == 1);
auto axis_value_read = tensor.int_val(0);
#include "Importer.h"
#include <loco.h>
+#include <plier/tf/TestHelper.h>
#include <gtest/gtest.h>
signature.add_output(output);
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(concat_01_pbtxtdata, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(concat_01_pbtxtdata, graph_def));
std::unique_ptr<loco::Graph> graph = importer.import(signature, graph_def);
// what to test:
signature.add_output(output);
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(concat_02_pbtxtdata, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(concat_02_pbtxtdata, graph_def));
std::unique_ptr<loco::Graph> graph = importer.import(signature, graph_def);
// what to test: Concat has 3 inputs --> Importer creates 2 TensorConcat
signature.add_output(moco::tf::TensorName("Concat", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(concat_03_pbtxtdata, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(concat_03_pbtxtdata, graph_def));
std::unique_ptr<loco::Graph> graph = importer.import(signature, graph_def);
// what to test: minus axis value validation
#include "Const.h"
-#include "Convert.h"
#include "GraphBuilder.h"
#include "GraphBuilderContext.h"
#include "Knob.h"
#include <moco/tf/Names.h>
#include <loco.h>
+#include <plier/tf/Convert.h>
#include <tensorflow/core/framework/graph.pb.h>
bool ConstGraphBuilderBase::validate(const tensorflow::NodeDef &node) const
{
- return has_attrs(node, {"dtype", "value"});
+ return plier::tf::has_attrs(node, {"dtype", "value"});
}
void ConstGraphBuilder::build(const tensorflow::NodeDef &node, GraphBuilderContext *context) const
auto const_node = graph->nodes()->create<loco::ConstGen>();
// set dtype
- auto dtype = as_loco_datatype(get_datatype_attr(node, "dtype"));
+ auto dtype = plier::tf::as_loco_datatype(plier::tf::get_datatype_attr(node, "dtype"));
const_node->dtype(dtype);
// import shape and value
- const auto &input_tensor = get_tensor_attr(node, "value");
+ const auto &input_tensor = plier::tf::get_tensor_attr(node, "value");
const auto &input_shape = input_tensor.tensor_shape();
const auto &input_dims = input_shape.dim();
assert(input_shape.dim_size() <= 6);
auto const_node = graph->nodes()->create<moco::tf::TFConst>();
// set dtype
- auto dtype = as_loco_datatype(get_datatype_attr(node, "dtype"));
+ auto dtype = plier::tf::as_loco_datatype(plier::tf::get_datatype_attr(node, "dtype"));
const_node->dtype(dtype);
// import shape and value
- const auto &input_tensor = get_tensor_attr(node, "value");
+ const auto &input_tensor = plier::tf::get_tensor_attr(node, "value");
const auto &input_shape = input_tensor.tensor_shape();
const auto &input_dims = input_shape.dim();
assert(input_shape.dim_size() <= 6);
#include "IR/TFConst.h"
#include <loco.h>
+#include <plier/tf/TestHelper.h>
#include <gtest/gtest.h>
signature.add_output(moco::tf::TensorName("const/float", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(const_float_01_pbtxtdata, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(const_float_01_pbtxtdata, graph_def));
// Test "tf.GraphDef -> loco.TF" importer
{
signature.add_output(moco::tf::TensorName("const/float", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(const_float_02_pbtxtdata, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(const_float_02_pbtxtdata, graph_def));
// Test "tf.GraphDef -> loco.TF" importer
{
signature.add_output(moco::tf::TensorName("const/float", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(const_float_03_pbtxtdata, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(const_float_03_pbtxtdata, graph_def));
// Test "tf.GraphDef -> loco.TF" importer
{
signature.add_output(moco::tf::TensorName("const/float", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(const_float_04_pbtxtdata, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(const_float_04_pbtxtdata, graph_def));
// Test "tf.GraphDef -> loco.TF" importer
{
signature.add_output(moco::tf::TensorName("const/int", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(const_int32_04_pbtxtdata, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(const_int32_04_pbtxtdata, graph_def));
// TODO Re-enable this
#if 0
#include <loco.h>
#include <loco/IR/PermutingCodec.h>
#include <stdex/Memory.h>
+#include <plier/tf/Convert.h>
#include <tensorflow/core/framework/graph.pb.h>
// note: even though "data_format" is not entered when a model is written,
// TF seems to generate "data_format" field into a pb file
- return has_attrs(node, {"T", "data_format", "dilations", "padding", "strides"});
+ return plier::tf::has_attrs(node, {"T", "data_format", "dilations", "padding", "strides"});
}
void Conv2DGraphBuilder::build(const tensorflow::NodeDef &node, GraphBuilderContext *context) const
void Conv2DGraphBuilderImpl<ImportTarget::Canonical>::build(const tensorflow::NodeDef &node,
GraphBuilderContext *context) const
{
+ using plier::tf::DataLayout;
+
loco::Graph *graph = context->graph();
SymbolTable *tensor_names = context->tensor_names();
UpdateQueue *updates = context->updates();
std::string conv2d_name = node.name();
// tensorflow data_format, e.g., NHWC, NCHW, etc.
- auto data_layout = get_data_layout(node, "data_format");
+ auto data_layout = plier::tf::get_data_layout(node, "data_format");
auto feature_enc = graph->nodes()->create<loco::FeatureEncode>();
{
// to loco attr: not defined, TBD, TBD, TBD, stride
// tf strides -> loco stride
- auto tf_strides = get_list_attr(node, "strides");
+ auto tf_strides = plier::tf::get_list_attr(node, "strides");
auto stride = conv2d->stride();
if (data_layout == DataLayout::NHWC)
}
// tf paddings -> PaddingData annotation
- auto tf_padding = moco::str_toupper(get_string_attr(node, "padding"));
+ auto tf_padding = moco::str_toupper(plier::tf::get_string_attr(node, "padding"));
auto padding_data = stdex::make_unique<PaddingData>(tf_padding);
conv2d->annot(std::move(padding_data));
}
auto conv2d = graph->nodes()->create<TFConv2D>();
// read attributes
- auto data_layout = get_string_attr(node, "data_format");
+ auto data_layout = plier::tf::get_string_attr(node, "data_format");
if (!(data_layout == "NHWC" || data_layout == "NCHW"))
{
throw std::runtime_error("Not yet supported");
}
conv2d->data_layout(data_layout);
- auto tf_strides = get_list_attr(node, "strides");
- auto strides = as_int64_list(tf_strides);
+ auto tf_strides = plier::tf::get_list_attr(node, "strides");
+ auto strides = plier::tf::as_int64_list(tf_strides);
conv2d->strides(strides);
- auto padding = moco::str_toupper(get_string_attr(node, "padding"));
+ auto padding = moco::str_toupper(plier::tf::get_string_attr(node, "padding"));
assert(padding == "VALID" || padding == "SAME");
conv2d->padding(padding);
#include <loco.h>
#include <loco/IR/TensorShape.h>
#include <loco/IR/FeatureShape.h>
+#include <plier/tf/TestHelper.h>
#include <gtest/gtest.h>
signature.add_output(moco::tf::TensorName("conv2d", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(conv2d_01_pbtxtdata, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(conv2d_01_pbtxtdata, graph_def));
// Test loco.TF Importer
{
signature.add_output(moco::tf::TensorName("InceptionV3/InceptionV3/Conv2d_1a_3x3/Conv2D", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(conv2d_inception_pbtxtdata, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(conv2d_inception_pbtxtdata, graph_def));
std::unique_ptr<loco::Graph> graph = importer.import(signature, graph_def);
// Test loco.TF Importer
#include "IR/TFFusedBatchNorm.h"
-#include "Convert.h"
#include "GraphBuilder.h"
#include "GraphBuilderContext.h"
#include <loco.h>
#include <stdex/Memory.h>
+#include <plier/tf/Convert.h>
#include <tensorflow/core/framework/graph.pb.h>
{
assert(node.input_size() == 5);
- return has_attrs(node, {"epsilon"});
+ return plier::tf::has_attrs(node, {"epsilon"});
}
void FusedBatchNormGraphBuilder::build(const tensorflow::NodeDef &node,
SymbolTable *tensor_names = context->tensor_names();
UpdateQueue *updates = context->updates();
- float epsilon = get_float_attr(node, "epsilon");
+ float epsilon = plier::tf::get_float_attr(node, "epsilon");
// creating TF dialect FusedBatchNorm node
auto tf_fbn = graph->nodes()->create<TFFusedBatchNorm>();
#include "IR/TFFusedBatchNorm.h"
#include <loco.h>
+#include <plier/tf/TestHelper.h>
#include <gtest/gtest.h>
signature.add_output(moco::tf::TensorName("FBN_01", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(fbn_basic_pbtxt, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(fbn_basic_pbtxt, graph_def));
std::unique_ptr<loco::Graph> graph = importer.import(signature, graph_def);
// what to test:
* limitations under the License.
*/
-#include "Convert.h"
#include "GraphBuilder.h"
#include "GraphBuilderContext.h"
#include <loco.h>
#include <loco/IR/PermutingCodec.h>
#include <stdex/Memory.h>
+#include <plier/tf/Convert.h>
#include <tensorflow/core/framework/graph.pb.h>
{
// note: even though "data_format" is not entered when a model is written,
// TF seems to generate "data_format" field into a pb file
- return has_attrs(node, {"T", "data_format", "ksize", "padding", "strides"});
+ return plier::tf::has_attrs(node, {"T", "data_format", "ksize", "padding", "strides"});
}
void MaxPoolGraphBuilder::build(const tensorflow::NodeDef &node, GraphBuilderContext *context) const
{
+ using plier::tf::DataLayout;
+
assert(context != nullptr);
assert(node.input_size() == 1);
::std::string maxpool2d_name = node.name();
// tensorflow data_format, e.g., NHWC, NCHW, etc.
- auto data_layout = get_data_layout(node, "data_format");
+ auto data_layout = plier::tf::get_data_layout(node, "data_format");
// FeatureEncode
{
// to loco attr: not defined, TBD, window, TBD, stride
// tf ksize -> loco window
- auto tf_ksize = get_list_attr(node, "ksize");
+ auto tf_ksize = plier::tf::get_list_attr(node, "ksize");
auto window = maxpool2d_node->window();
if (data_layout == DataLayout::NHWC)
}
// tf strides -> loco stride
- auto tf_strides = get_list_attr(node, "strides");
+ auto tf_strides = plier::tf::get_list_attr(node, "strides");
auto stride = maxpool2d_node->stride();
if (data_layout == DataLayout::NHWC)
}
// tf paddings -> PaddingData annotation
- auto tf_padding = get_string_attr(node, "padding");
+ auto tf_padding = plier::tf::get_string_attr(node, "padding");
auto padding_data = stdex::make_unique<PaddingData>(tf_padding);
maxpool2d_node->annot(std::move(padding_data));
}
#include <loco.h>
#include <loco/IR/TensorShape.h>
#include <loco/IR/FeatureShape.h>
+#include <plier/tf/TestHelper.h>
#include <gtest/gtest.h>
signature.add_output(moco::tf::TensorName("maxpool", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(maxpool_01_pbtxtdata, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(maxpool_01_pbtxtdata, graph_def));
std::unique_ptr<loco::Graph> graph = importer.import(signature, graph_def);
// what to test:
signature.add_output(moco::tf::TensorName("maxpool", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(maxpool_01_pbtxtdata, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(maxpool_01_pbtxtdata, graph_def));
std::unique_ptr<loco::Graph> graph = importer.import(signature, graph_def);
// what to test: Encoder and Decoder dimension order
* limitations under the License.
*/
-#include "Convert.h"
#include "GraphBuilder.h"
#include "GraphBuilderContext.h"
#include "CompilerArgs.h"
#include <moco/tf/Names.h>
+#include <plier/tf/Convert.h>
#include <tensorflow/core/framework/graph.pb.h>
bool PlaceholderGraphBuilder::validate(const tensorflow::NodeDef &node) const
{
- return has_attrs(node, {"dtype", "shape"});
+ return plier::tf::has_attrs(node, {"dtype", "shape"});
}
void PlaceholderGraphBuilder::build(const tensorflow::NodeDef &node,
loco::Graph *graph = context->graph();
SymbolTable *tensor_names = context->tensor_names();
- loco::DataType dtype = as_loco_datatype(get_datatype_attr(node, "dtype"));
- const auto &shape = get_shape_attr(node, "shape");
+ loco::DataType dtype = plier::tf::as_loco_datatype(plier::tf::get_datatype_attr(node, "dtype"));
+ const auto &shape = plier::tf::get_shape_attr(node, "shape");
// TODO handle for unknown rank
assert(!shape.unknown_rank());
int64_t num_dims = shape.dim_size();
#include <loco/IR/TensorShape.h>
#include <loco/IR/FeatureShape.h>
#include <nncc/core/ADT/tensor/Shape.h>
+#include <plier/tf/TestHelper.h>
#include <gtest/gtest.h>
signature.add_output(moco::tf::TensorName("output", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(known_batch_pbtxt, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(known_batch_pbtxt, graph_def));
std::unique_ptr<loco::Graph> graph = importer.import(signature, graph_def);
// get loco::Pull
signature.add_output(moco::tf::TensorName("output", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(known_batch_pbtxt, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(known_batch_pbtxt, graph_def));
ASSERT_ANY_THROW(importer.import(signature, graph_def));
moco::tf::CompilerArgs::get()->clear();
signature.add_output(moco::tf::TensorName("output", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(unknown_batch_pbtxt, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(unknown_batch_pbtxt, graph_def));
std::unique_ptr<loco::Graph> graph = importer.import(signature, graph_def);
// get loco::Pull
signature.add_output(moco::tf::TensorName("output", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(unknown_batch_pbtxt, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(unknown_batch_pbtxt, graph_def));
ASSERT_ANY_THROW(importer.import(signature, graph_def));
moco::tf::CompilerArgs::get()->clear();
* limitations under the License.
*/
-#include "Convert.h"
#include "GraphBuilder.h"
#include "GraphBuilderContext.h"
#include "Importer.h"
#include <loco.h>
+#include <plier/tf/TestHelper.h>
#include <gtest/gtest.h>
signature.add_output(moco::tf::TensorName("ReLU", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(relu_01_pbtxtdata, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(relu_01_pbtxtdata, graph_def));
std::unique_ptr<loco::Graph> graph = importer.import(signature, graph_def);
// what to test:
#include "Importer.h"
#include <loco.h>
+#include <plier/tf/TestHelper.h>
#include <gtest/gtest.h>
signature.add_output(moco::tf::TensorName("ReLU6", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(relu6_01_pbtxtdata, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(relu6_01_pbtxtdata, graph_def));
std::unique_ptr<loco::Graph> graph = importer.import(signature, graph_def);
// what to test:
namespace test
{
-bool parse_graphdef(char const *pbtxt, tensorflow::GraphDef &graphdef)
-{
- imemstream mempb(pbtxt, std::strlen(pbtxt));
- google::protobuf::io::IstreamInputStream iis(&mempb);
- return google::protobuf::TextFormat::Parse(&iis, &graphdef);
-}
-
void setup_output_node(loco::Graph *graph, loco::Node *last_node)
{
// add push as output
namespace test
{
-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))
- {
- }
-};
-
-bool parse_graphdef(char const *pbtxt, tensorflow::GraphDef &graphdef);
-
template <typename T> T *find_first_node_bytype(loco::Graph *g)
{
T *first_node = nullptr;
#include <loco.h>
#include <locop/FormattedGraph.h>
#include <moco/Log.h>
+#include <plier/tf/TestHelper.h>
#include <gtest/gtest.h>
signature.add_output(moco::tf::TensorName("relu", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(case01, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(case01, graph_def));
auto graph = importer.import(signature, graph_def);
// Convert graph to hold only Canonical dialect
#include "FixPaddingTransform.h"
-#include "Convert.h"
#include "Annotations/PaddingData.h"
#include "Annotations/PadData.h"
#include "Annotations/ShapeInferenceData.h"
#include <loco.h>
#include <moco/Log.h>
#include <stdex/Memory.h>
+#include <plier/tf/Convert.h>
#include <cassert>
#include <sstream>
}
auto stride_data = stdex::make_unique<StrideData>();
auto strides = node->strides();
- auto data_layout = as_DataLayout(node->data_layout());
- if (data_layout == DataLayout::NHWC)
+ auto data_layout = plier::tf::as_data_layout(node->data_layout());
+ if (data_layout == plier::tf::DataLayout::NHWC)
{
stride_data->stride()->vertical(strides[1]);
stride_data->stride()->horizontal(strides[2]);
}
- else if (data_layout == DataLayout::NCHW)
+ else if (data_layout == plier::tf::DataLayout::NCHW)
{
stride_data->stride()->vertical(strides[2]);
stride_data->stride()->horizontal(strides[3]);
#include "IR/TFConv2D.h"
#include "IR/TFMul.h"
-#include "Convert.h"
-
#include <loco.h>
#include <moco/Log.h>
#include <moco/tf/NodeShape.h>
#include "IR/TFConst.h"
#include "IR/TFMul.h"
-#include "Convert.h"
-
#include "IR/TFFusedBatchNorm.h"
#include <loco.h>
#include <locop/FormattedGraph.h>
#include <moco/Log.h>
#include <stdex/Memory.h>
+#include <plier/tf/TestHelper.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
signature.add_output(moco::tf::TensorName("FBN_01", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(fbn_basic_pbtxt, graph_def));
+ EXPECT_TRUE(plier::tf::parse_graphdef(fbn_basic_pbtxt, graph_def));
auto graph = importer.import(signature, graph_def);
INFO(l) << "Before ResolveFusedBatchNorm";