MCPcopy Create free account
hub / github.com/alibaba/MNN / BuildQuantOrDequantNode

Method BuildQuantOrDequantNode

tools/converter/source/tensorflow/TFGraphResolver.cpp:157–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155}
156
157std::unique_ptr<TFNode> TFGraphResolver::BuildQuantOrDequantNode(
158 const std::string& name,
159 const std::string& op,
160 const int& nbit,
161 const std::vector<float>& scales,
162 const float& zero_point, const float& clamp_min, const float& clamp_max,
163 const MNN::Compression::LayerQuantizeParams_QuantMethod& method) {
164 std::unique_ptr<NodeDef> node_def(new NodeDef);
165 *(node_def->mutable_name()) = name;
166 *(node_def->mutable_op()) = op;
167 (*node_def->mutable_attr())["nbit"].set_i(nbit);
168 auto* list = (*node_def->mutable_attr())["scale"].mutable_list();
169 for (int i = 0; i < scales.size(); ++i) {
170 if (op == "CustomQuantize") {
171 list->mutable_f()->Add(1.f / scales[i]);
172 } else {
173 list->mutable_f()->Add(scales[i]);
174 }
175 }
176 (*node_def->mutable_attr())["zero_point"].set_f(zero_point);
177 (*node_def->mutable_attr())["clamp_min"].set_f(clamp_min);
178 (*node_def->mutable_attr())["clamp_max"].set_f(clamp_max);
179 (*node_def->mutable_attr())["method"].set_i(int(method));
180 std::unique_ptr<TFNode> quant_node(new TFNode);
181 quant_node->name = name;
182 quant_node->op = op;
183 quant_node->node_def = node_def.get();
184
185 main_graph()->allocated_nodes_.push_back(std::move(node_def));
186 return std::move(quant_node);
187}
188
189void TFGraphResolver::ResolveQuantization(
190 TFGraph* graph,

Callers

nothing calls this directly

Calls 11

mutable_listMethod · 0.80
mutable_nameMethod · 0.45
mutable_opMethod · 0.45
set_iMethod · 0.45
mutable_attrMethod · 0.45
sizeMethod · 0.45
AddMethod · 0.45
mutable_fMethod · 0.45
set_fMethod · 0.45
getMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected