ONE - On-device Neural Engine
Loading...
Searching...
No Matches
moco::MeanGraphBuilder Class Referencefinal

GraphBuilder for Mean node. More...

#include <Mean.h>

Collaboration diagram for moco::MeanGraphBuilder:

Public Member Functions

bool validate (const tensorflow::NodeDef &) const override
 
void build (const tensorflow::NodeDef &, GraphBuilderContext *) const override
 
- Public Member Functions inherited from moco::GraphBuilder
virtual ~GraphBuilder ()
 

Detailed Description

GraphBuilder for Mean node.

Definition at line 28 of file Mean.h.

Member Function Documentation

◆ build()

void moco::MeanGraphBuilder::build ( const tensorflow::NodeDef &  node,
GraphBuilderContext context 
) const
overridevirtual

Implements moco::GraphBuilder.

Definition at line 79 of file Mean.cpp.

80{
81 assert(context != nullptr);
82
83 loco::Graph *graph = context->graph();
84 SymbolTable *tensor_names = context->tensor_names();
85 UpdateQueue *updates = context->updates();
86
87 // creating TF dialect Mean node
88 auto tf_mean = graph->nodes()->create<TFMean>();
89 tf_mean->name(node.name());
90 tf_mean->keep_dims(plier::tf::get_bool_attr(node, "keep_dims"));
91
92 TensorName output_name(node.name(), 0);
93 tensor_names->enroll(output_name, tf_mean);
94
95 auto update = std::make_unique<MeanGraphUpdate>(tf_mean, TensorName(node.input(0)),
96 TensorName(node.input(1)));
97 updates->enroll(std::move(update));
98}
A neural network graph.
Definition Graph.h:161
Class to store and query loco::Node* with string name key.
void enroll(const TensorName &tensor_name, loco::Node *node)
Registers a name with corresponding loco::Node *.
Class to store GraphUpdate objects.
void enroll(std::unique_ptr< GraphUpdate > &&update)
Registers GraphUpdate objects.
FeatureShapeUpdater update(loco::FeatureShape &feature_shape)
bool get_bool_attr(const tensorflow::NodeDef &node, const std::string &attr_name)
Definition Convert.cpp:103
NodeName name(void) const
Definition TFNodeDecl.h:50

References moco::SymbolTable::enroll(), moco::UpdateQueue::enroll(), plier::tf::get_bool_attr(), moco::GraphBuilderContext::graph(), moco::TFNode::name(), moco::GraphBuilderContext::tensor_names(), moco::update(), and moco::GraphBuilderContext::updates().

◆ validate()

bool moco::MeanGraphBuilder::validate ( const tensorflow::NodeDef &  node) const
overridevirtual

Implements moco::GraphBuilder.

Definition at line 64 of file Mean.cpp.

65{
66 if (node.input_size() != 2)
67 return false;
68
69 if (!plier::tf::has_attrs(node, {"T", "Tidx", "keep_dims"}))
70 return false;
71
72 auto dtype = plier::tf::get_datatype_attr(node, "Tidx");
73 if (dtype != tensorflow::DataType::DT_INT32 && dtype != tensorflow::DataType::DT_INT64)
74 return false;
75
76 return true;
77}
bool has_attrs(const tensorflow::NodeDef &node, const std::vector< std::string > &attr_names)
Definition Convert.cpp:35
tensorflow::DataType get_datatype_attr(const tensorflow::NodeDef &node, const std::string &attr_name)
Definition Convert.cpp:43

References plier::tf::get_datatype_attr(), and plier::tf::has_attrs().


The documentation for this class was generated from the following files: