Stay organized with collections
Save and categorize content based on your preferences.
tensorflow::ops::FakeQuantWithMinMaxArgs
#include <array_ops.h>
Fake-quantize the 'inputs' tensor, type float to 'outputs' tensor of same shape and type.
Summary
Quantization is called fake since the output is still in floating point. The API converts inputs into values within the range [min and max] and returns as output.
Attributes
[min; max]
define the clamping range for the inputs
data.
inputs
values are quantized into the quantization range ( [0; 2^num_bits - 1]
when narrow_range
is false and [1; 2^num_bits - 1]
when it is true) and then de-quantized and output as floats in [min; max]
interval.
num_bits
is the bitwidth of the quantization; between 2 and 16, inclusive.
Before quantization, min
and max
values are adjusted with the following logic. It is suggested to have min <= 0 <= max
. If 0
is not in the range of values, the behavior can be unexpected:
- If
0 < min < max
: min_adj = 0
and max_adj = max - min
.
- If
min < max < 0
: min_adj = min - max
and max_adj = 0
.
- If
min <= 0 <= max
: scale = (max - min) / (2^num_bits - 1)
, min_adj = scale * round(min / scale)
and max_adj = max + min_adj - min
.
Examples
inp = tf.constant ([10.03, -10.23, 3])
out = tf.quantization.fake_quant_with_min_max_args(inp, min=-5, max=5,
num_bits=16)
print(out)
# Output:
# tf.Tensor([ 4.9999237 -5.0000763 3.0000763], shape=(3,), dtype=float32)
Raises:
- InvalidArgumentError:
- If num_bits are outside of range [2, 16].
- If min >= max.
- ValueError: If
inputs
are of any other type than float32.
Args:
Returns:
Public attributes
Public functions
node
::tensorflow::Node * node() const
operator::tensorflow::Input() const
operator::tensorflow::Output
operator::tensorflow::Output() const
Public static functions
NarrowRange
Attrs NarrowRange(
bool x
)
NumBits
Attrs NumBits(
int64 x
)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[],[],null,["# tensorflow::ops::FakeQuantWithMinMaxArgs Class Reference\n\ntensorflow::ops::FakeQuantWithMinMaxArgs\n========================================\n\n`#include \u003carray_ops.h\u003e`\n\nFake-quantize the 'inputs' tensor, type float to 'outputs' tensor of same shape and type.\n\nSummary\n-------\n\nQuantization is called fake since the output is still in floating point. The API converts inputs into values within the range \\[min and max\\] and returns as output.\n\nAttributes\n\n\n- `[min; max]` define the clamping range for the `inputs` data.\n- `inputs` values are quantized into the quantization range ( `[0; 2^num_bits - 1]` when `narrow_range` is false and `[1; 2^num_bits - 1]` when it is true) and then de-quantized and output as floats in `[min; max]` interval.\n- `num_bits` is the bitwidth of the quantization; between 2 and 16, inclusive.\n\n\u003cbr /\u003e\n\nBefore quantization, `min` and `max` values are adjusted with the following logic. It is suggested to have `min \u003c= 0 \u003c= max`. If `0` is not in the range of values, the behavior can be unexpected:\n\n\n- If `0 \u003c min \u003c max`: `min_adj = 0` and `max_adj = max - min`.\n- If `min \u003c max \u003c 0`: `min_adj = min - max` and `max_adj = 0`.\n- If `min \u003c= 0 \u003c= max`: `scale = (max - min) / (2^num_bits - 1)`, `min_adj = scale * round(min / scale)` and `max_adj = max + min_adj - min`.\n\n\u003cbr /\u003e\n\nExamples\n\n\n```text\n\n```\n\n\u003cbr /\u003e\n\n\n```gdscript\ninp = tf.constant ([10.03, -10.23, 3])\nout = tf.quantization.fake_quant_with_min_max_args(inp, min=-5, max=5,\n num_bits=16)\nprint(out)\n```\n\n\u003cbr /\u003e\n\n\n```carbon\n# Output:\n# tf.Tensor([ 4.9999237 -5.0000763 3.0000763], shape=(3,), dtype=float32)\n```\n\n\u003cbr /\u003e\n\nRaises:\n\n- InvalidArgumentError:\n - If num_bits are outside of range \\[2, 16\\].\n - If min \\\u003e= max.\n- ValueError: If `inputs` are of any other type than float32.\n\n\u003cbr /\u003e\n\nArgs:\n\n- scope: A [Scope](/versions/r2.14/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object\n\n\u003cbr /\u003e\n\nReturns:\n\n- [Output](/versions/r2.14/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output): The outputs tensor.\n\n\u003cbr /\u003e\n\n| ### Constructors and Destructors ||\n|---|---|\n| [FakeQuantWithMinMaxArgs](#classtensorflow_1_1ops_1_1_fake_quant_with_min_max_args_1a85e03d1dc3cd4bc32cd221b7b9cf6d9a)`(const ::`[tensorflow::Scope](/versions/r2.14/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.14/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` inputs)` ||\n| [FakeQuantWithMinMaxArgs](#classtensorflow_1_1ops_1_1_fake_quant_with_min_max_args_1a5a50c94e0d72103df198cd3f00bed13d)`(const ::`[tensorflow::Scope](/versions/r2.14/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, ::`[tensorflow::Input](/versions/r2.14/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` inputs, const `[FakeQuantWithMinMaxArgs::Attrs](/versions/r2.14/api_docs/cc/struct/tensorflow/ops/fake-quant-with-min-max-args/attrs#structtensorflow_1_1ops_1_1_fake_quant_with_min_max_args_1_1_attrs)` & attrs)` ||\n\n| ### Public attributes ||\n|----------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|\n| [operation](#classtensorflow_1_1ops_1_1_fake_quant_with_min_max_args_1a74ebb70c787d9ab49c7e4f6a25a1caba) | [Operation](/versions/r2.14/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation) |\n| [outputs](#classtensorflow_1_1ops_1_1_fake_quant_with_min_max_args_1a9f9cb032ade7705f0b4a03b0ab94cb0c) | `::`[tensorflow::Output](/versions/r2.14/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output) |\n\n| ### Public functions ||\n|----------------------------------------------------------------------------------------------------------------------------------------|------------------------|\n| [node](#classtensorflow_1_1ops_1_1_fake_quant_with_min_max_args_1adf0a81f8d2e49f0bf4eb5859fac39168)`() const ` | `::tensorflow::Node *` |\n| [operator::tensorflow::Input](#classtensorflow_1_1ops_1_1_fake_quant_with_min_max_args_1a51cf8e44b3b26ce30a5016a440b99c69)`() const ` | |\n| [operator::tensorflow::Output](#classtensorflow_1_1ops_1_1_fake_quant_with_min_max_args_1a614548643c093eefd86990ce72baece3)`() const ` | |\n\n| ### Public static functions ||\n|----------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Max](#classtensorflow_1_1ops_1_1_fake_quant_with_min_max_args_1a5e82983f6429be0078510aea65c1593b)`(float x)` | [Attrs](/versions/r2.14/api_docs/cc/struct/tensorflow/ops/fake-quant-with-min-max-args/attrs#structtensorflow_1_1ops_1_1_fake_quant_with_min_max_args_1_1_attrs) |\n| [Min](#classtensorflow_1_1ops_1_1_fake_quant_with_min_max_args_1a3fd5bd826632651830791d26c59fb56f)`(float x)` | [Attrs](/versions/r2.14/api_docs/cc/struct/tensorflow/ops/fake-quant-with-min-max-args/attrs#structtensorflow_1_1ops_1_1_fake_quant_with_min_max_args_1_1_attrs) |\n| [NarrowRange](#classtensorflow_1_1ops_1_1_fake_quant_with_min_max_args_1a9af5fd9211a71acf844cf8d911fde2ac)`(bool x)` | [Attrs](/versions/r2.14/api_docs/cc/struct/tensorflow/ops/fake-quant-with-min-max-args/attrs#structtensorflow_1_1ops_1_1_fake_quant_with_min_max_args_1_1_attrs) |\n| [NumBits](#classtensorflow_1_1ops_1_1_fake_quant_with_min_max_args_1a80f557e9c790845a7e5c910bae0ef5fd)`(int64 x)` | [Attrs](/versions/r2.14/api_docs/cc/struct/tensorflow/ops/fake-quant-with-min-max-args/attrs#structtensorflow_1_1ops_1_1_fake_quant_with_min_max_args_1_1_attrs) |\n\n| ### Structs ||\n|-----------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [tensorflow::ops::FakeQuantWithMinMaxArgs::Attrs](/versions/r2.14/api_docs/cc/struct/tensorflow/ops/fake-quant-with-min-max-args/attrs) | Optional attribute setters for [FakeQuantWithMinMaxArgs](/versions/r2.14/api_docs/cc/class/tensorflow/ops/fake-quant-with-min-max-args#classtensorflow_1_1ops_1_1_fake_quant_with_min_max_args). |\n\nPublic attributes\n-----------------\n\n### operation\n\n```text\nOperation operation\n``` \n\n### outputs\n\n```text\n::tensorflow::Output outputs\n``` \n\nPublic functions\n----------------\n\n### FakeQuantWithMinMaxArgs\n\n```gdscript\n FakeQuantWithMinMaxArgs(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input inputs\n)\n``` \n\n### FakeQuantWithMinMaxArgs\n\n```gdscript\n FakeQuantWithMinMaxArgs(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input inputs,\n const FakeQuantWithMinMaxArgs::Attrs & attrs\n)\n``` \n\n### node\n\n```gdscript\n::tensorflow::Node * node() const \n``` \n\n### operator::tensorflow::Input\n\n```gdscript\n operator::tensorflow::Input() const \n``` \n\n### operator::tensorflow::Output\n\n```gdscript\n operator::tensorflow::Output() const \n``` \n\nPublic static functions\n-----------------------\n\n### Max\n\n```text\nAttrs Max(\n float x\n)\n``` \n\n### Min\n\n```text\nAttrs Min(\n float x\n)\n``` \n\n### NarrowRange\n\n```text\nAttrs NarrowRange(\n bool x\n)\n``` \n\n### NumBits\n\n```text\nAttrs NumBits(\n int64 x\n)\n```"]]