Adds a QuantizeAndDequantizeV2 or FakeQuantizeWithMinMaxVars op (and required input nodes) based on edge. The result is stored in convert_node.
| 534 | // (and required input nodes) based on edge. |
| 535 | // The result is stored in convert_node. |
| 536 | Status MakeQuantizeOp(Graph* graph, const string& name_prefix, |
| 537 | const string& quant_op_type, const EdgeToConvert& edge, |
| 538 | std::vector<Node*>* added_variables, |
| 539 | Node** convert_node) { |
| 540 | Node* input_min; |
| 541 | Node* input_max; |
| 542 | TF_RETURN_IF_ERROR(MakeInputMinMax(graph, name_prefix, edge, added_variables, |
| 543 | &input_min, &input_max)); |
| 544 | string quant_name = strings::StrCat(name_prefix, "/", quant_op_type); |
| 545 | if (quant_op_type == "QuantizeAndDequantizeV2") { |
| 546 | TF_RETURN_IF_ERROR(NodeBuilder(quant_name, quant_op_type) |
| 547 | .Input(edge.edge->src()) |
| 548 | .Input(input_min) |
| 549 | .Input(input_max) |
| 550 | .Attr("signed_input", edge.signed_input) |
| 551 | .Attr("num_bits", edge.num_bits) |
| 552 | .Attr("range_given", true) |
| 553 | .Finalize(graph, convert_node)); |
| 554 | } else if (quant_op_type == "FakeQuantWithMinMaxVars") { |
| 555 | TF_RETURN_IF_ERROR(NodeBuilder(quant_name, quant_op_type) |
| 556 | .Input(edge.edge->src()) |
| 557 | .Input(input_min) |
| 558 | .Input(input_max) |
| 559 | .Attr("num_bits", edge.num_bits) |
| 560 | .Finalize(graph, convert_node)); |
| 561 | } else { |
| 562 | return errors::InvalidArgument("Unknown quant op type: ", quant_op_type); |
| 563 | } |
| 564 | return Status::OK(); |
| 565 | } |
| 566 | |
| 567 | // Insert conversion op, connect it to the graph and remove the old edge. |
| 568 | Status ProcessTargetEdges(Graph* graph, const string& quant_op_type, |
no test coverage detected