Makes an input min and max constant if the range is given. Otherwise, makes min and max variables that are updated by an EMA.
| 500 | // Makes an input min and max constant if the range is given. Otherwise, makes |
| 501 | // min and max variables that are updated by an EMA. |
| 502 | Status MakeInputMinMax(Graph* graph, const string& name_prefix, |
| 503 | const EdgeToConvert& edge, |
| 504 | std::vector<Node*>* added_variables, Node** input_min, |
| 505 | Node** input_max) { |
| 506 | if (edge.range_given) { |
| 507 | // Make constant nodes for the input_min and input_max if the range is |
| 508 | // provided. |
| 509 | Tensor input_min_tensor(DT_FLOAT, TensorShape()); |
| 510 | input_min_tensor.flat<float>()(0) = edge.input_min; |
| 511 | TF_RETURN_IF_ERROR( |
| 512 | NodeBuilder(strings::StrCat(name_prefix, "/InputMin"), "Const") |
| 513 | .Attr("dtype", DT_FLOAT) |
| 514 | .Attr("value", input_min_tensor) |
| 515 | .Finalize(graph, input_min)); |
| 516 | Tensor input_max_tensor(DT_FLOAT, TensorShape()); |
| 517 | input_max_tensor.flat<float>()(0) = edge.input_max; |
| 518 | TF_RETURN_IF_ERROR( |
| 519 | NodeBuilder(strings::StrCat(name_prefix, "/InputMax"), "Const") |
| 520 | .Attr("dtype", DT_FLOAT) |
| 521 | .Attr("value", input_max_tensor) |
| 522 | .Finalize(graph, input_max)); |
| 523 | } else { |
| 524 | // If the range is not given, estimate the range with EMA variables. |
| 525 | TF_RETURN_IF_ERROR(MakeEMAMinMaxVars(graph, name_prefix, edge.edge->src(), |
| 526 | added_variables, input_min, |
| 527 | input_max)); |
| 528 | } |
| 529 | |
| 530 | return Status::OK(); |
| 531 | } |
| 532 | |
| 533 | // Adds a QuantizeAndDequantizeV2 or FakeQuantizeWithMinMaxVars op |
| 534 | // (and required input nodes) based on edge. |
no test coverage detected