/**
* @brief GraphBuilder for MaxPool node
*/
-class MaxPool2DGraphBuilder final : public GraphBuilder
+class MaxPoolGraphBuilder final : public GraphBuilder
{
public:
bool validate(const tensorflow::NodeDef &) const override;
void build(const tensorflow::NodeDef &, GraphBuilderContext *) const override;
};
-class MaxPool2DGraphUpdate final : public GraphUpdate
+class MaxPoolGraphUpdate final : public GraphUpdate
{
public:
- MaxPool2DGraphUpdate(loco::FeatureEncode *node, const TensorName &&name)
+ MaxPoolGraphUpdate(loco::FeatureEncode *node, const TensorName &&name)
: _encode_node(node), _input_name(name)
{
}
const TensorName _input_name;
};
-bool MaxPool2DGraphBuilder::validate(const tensorflow::NodeDef &node) const
+bool MaxPoolGraphBuilder::validate(const tensorflow::NodeDef &node) const
{
// 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"});
}
-void MaxPool2DGraphBuilder::build(const tensorflow::NodeDef &node,
- GraphBuilderContext *context) const
+void MaxPoolGraphBuilder::build(const tensorflow::NodeDef &node, GraphBuilderContext *context) const
{
assert(context != nullptr);
assert(node.input_size() == 1);
encode_node->encoder(std::move(enc));
}
- // MaxPool2D
+ // MaxPool
{
// let's convert attrs:
// TensorFlow attr : T, data_format, ksize, padding, strides
tensor_names->enroll(output_name, decode_node);
// Record ifm inputs to featureEncode_node
- auto update = stdex::make_unique<MaxPool2DGraphUpdate>(encode_node, TensorName(node.input(0)));
+ auto update = stdex::make_unique<MaxPoolGraphUpdate>(encode_node, TensorName(node.input(0)));
updates->enroll(std::move(update));
}
-void MaxPool2DGraphUpdate::input(const SymbolTable *tensor_names) const
+void MaxPoolGraphUpdate::input(const SymbolTable *tensor_names) const
{
loco::Node *input_node = tensor_names->node(_input_name);
_encode_node->input(input_node);
#include "GraphBuilderRegistry.h"
-REGISTER_OP_BUILDER(MaxPool, MaxPool2DGraphBuilder)
+REGISTER_OP_BUILDER(MaxPool, MaxPoolGraphBuilder)
// TODO Consider a case when TF MaxPool is for 3D.
// MaxPool works for 2D and other Dimensions, such as 3D
-// So, in future, some other GraphBuilder decide if MaxPool2DGraphBuilder is used or
+// So, in future, some other GraphBuilder decide if MaxPoolGraphBuilder is used or
// other GraphBuilder is used for TF MaxPool
namespace
{
// clang-format off
-const char *maxpool2d_01_pbtxtdata = STRING_CONTENT(
+const char *maxpool_01_pbtxtdata = STRING_CONTENT(
node {
name: "const/float"
op: "Const"
}
}
node {
- name: "maxpool2d"
+ name: "maxpool"
op: "MaxPool"
input: "const/float"
attr {
} // namespace
-TEST(TensorFlowImport, MaxPool2D_01)
+TEST(TensorFlowImport, MaxPool_01)
{
moco::tf::Importer importer;
moco::tf::ModelSignature signature;
- signature.add_output(moco::tf::TensorName("maxpool2d", 0));
+ signature.add_output(moco::tf::TensorName("maxpool", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(maxpool2d_01_pbtxtdata, graph_def));
+ EXPECT_TRUE(parse_graphdef(maxpool_01_pbtxtdata, graph_def));
std::unique_ptr<loco::Graph> graph = importer.import(signature, graph_def);
// what to test:
// - stride values should match
// - window values should match
- loco::MaxPool2D *maxpool_node =
+ loco::MaxPool2D *maxpool2d_node =
moco::tf::test::find_first_node_bytype<loco::MaxPool2D>(graph.get());
- ASSERT_NE(maxpool_node, nullptr);
+ ASSERT_NE(maxpool2d_node, nullptr);
- loco::Node *previous_node = maxpool_node->ifm();
- auto following_nodes = loco::succs(maxpool_node);
+ loco::Node *previous_node = maxpool2d_node->ifm();
+ auto following_nodes = loco::succs(maxpool2d_node);
ASSERT_EQ(following_nodes.size(), 1);
loco::Node *following_node = *following_nodes.begin();
ASSERT_NE(following_node, nullptr);
ASSERT_NE(dec_node, nullptr);
// attrs inside MaxPool2D
- auto maxpool2d = maxpool_node; // TODO remove this new variable
+ auto maxpool2d = maxpool2d_node; // TODO remove this new variable
// stride
ASSERT_EQ(maxpool2d->stride()->vertical(), 3);
ASSERT_EQ(maxpool2d->window()->horizontal(), 3);
}
-TEST(TensorFlowImport, MaxPool2D_02)
+TEST(TensorFlowImport, MaxPool_02)
{
moco::tf::Importer importer;
moco::tf::ModelSignature signature;
- signature.add_output(moco::tf::TensorName("maxpool2d", 0));
+ signature.add_output(moco::tf::TensorName("maxpool", 0));
tensorflow::GraphDef graph_def;
- EXPECT_TRUE(parse_graphdef(maxpool2d_01_pbtxtdata, graph_def));
+ EXPECT_TRUE(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
// - FeatureEncode encoder should encode Count-Height-Width-Depth order
// - FeatureDecode decoder should decode Count-Height-Width-Depth order
- loco::MaxPool2D *maxpool_node =
+ loco::MaxPool2D *maxpool2d_node =
moco::tf::test::find_first_node_bytype<loco::MaxPool2D>(graph.get());
- ASSERT_NE(maxpool_node, nullptr);
+ ASSERT_NE(maxpool2d_node, nullptr);
- loco::Node *previous_node = maxpool_node->ifm();
- auto following_nodes = loco::succs(maxpool_node);
+ loco::Node *previous_node = maxpool2d_node->ifm();
+ auto following_nodes = loco::succs(maxpool2d_node);
ASSERT_EQ(following_nodes.size(), 1);
loco::Node *following_node = *following_nodes.begin();
ASSERT_NE(following_node, nullptr);