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

GraphBuilder for FakeQuantWithMinMaxVars node. More...

#include <FakeQuantWithMinMaxVars.h>

Collaboration diagram for moco::FakeQuantWithMinMaxVarsGraphBuilder:

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 FakeQuantWithMinMaxVars node.

Definition at line 28 of file FakeQuantWithMinMaxVars.h.

Member Function Documentation

◆ build()

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

Implements moco::GraphBuilder.

Definition at line 83 of file FakeQuantWithMinMaxVars.cpp.

85{
86 assert(context != nullptr);
87
88 loco::Graph *graph = context->graph();
89 SymbolTable *tensor_names = context->tensor_names();
90 UpdateQueue *updates = context->updates();
91
92 auto fakequant_node = graph->nodes()->create<TFFakeQuantWithMinMaxVars>();
93 fakequant_node->name(node.name());
94
95 // read optional attributes
96 if (has_attr(node, "num_bits"))
97 {
98 auto num_bits = get_int_attr(node, "num_bits");
99 fakequant_node->num_bits(num_bits);
100 }
101 if (has_attr(node, "narrow_range"))
102 {
103 auto narrow_range = get_bool_attr(node, "narrow_range");
104 fakequant_node->narrow_range(narrow_range);
105 }
106
107 // save the name for graph link updates
108 TensorName output_name(node.name(), 0);
109 tensor_names->enroll(output_name, fakequant_node);
110
111 std::vector<TensorName> input_names;
112 input_names.push_back(TensorName(node.input(0))); // inputs
113 input_names.push_back(TensorName(node.input(1))); // min
114 input_names.push_back(TensorName(node.input(2))); // max
115
116 // Record ifm inputs to featureEncode_node
117 auto tffakequant_update =
118 std::make_unique<TFFakeQuantWithMinMaxVarsGraphUpdate>(fakequant_node, input_names);
119
120 updates->enroll(std::move(tffakequant_update));
121}
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.
bool has_attr(const tensorflow::NodeDef &node, const std::string &attr_name)
Definition Convert.cpp:30
bool get_bool_attr(const tensorflow::NodeDef &node, const std::string &attr_name)
Definition Convert.cpp:103
int64_t get_int_attr(const tensorflow::NodeDef &node, const std::string &attr_name)
Definition Convert.cpp:87
NodeName name(void) const
Definition TFNodeDecl.h:50

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

◆ validate()

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

Implements moco::GraphBuilder.

Definition at line 74 of file FakeQuantWithMinMaxVars.cpp.

75{
76 if (node.input_size() != 3)
77 return false;
78
79 // attrs "narrow_range", "num_bits" are optional
80 return true;
81}

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