| 155 | } |
| 156 | |
| 157 | std::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 | |
| 189 | void TFGraphResolver::ResolveQuantization( |
| 190 | TFGraph* graph, |
nothing calls this directly
no test coverage detected