U
- data type for output
output@Operator(group="quantization") public final class Dequantize<U extends TNumber> extends RawOp implements Operand<U>
In 'MIN_COMBINED' mode, each value of the tensor will undergo the following:
if T == qint8: in[i] += (range(T) + 1)/ 2.0 out[i] = min_range + (in[i]* (max_range - min_range) / range(T))
here range(T) = numeric_limits<T>::max() - numeric_limits<T>::min()
MIN_COMBINED Mode Example
If the input comes from a QuantizedRelu6, the output type is quint8 (range of 0-255) but the possible range of QuantizedRelu6 is 0-6. The min_range and max_range values are therefore 0.0 and 6.0. Dequantize on quint8 will take each value, cast to float, and multiply by 6 / 255. Note that if quantizedtype is qint8, the operation will additionally add each value by 128 prior to casting.
If the mode is 'MIN_FIRST', then this approach is used:
num_discrete_values = 1 << (# of bits in T) range_adjust = num_discrete_values / (num_discrete_values - 1) range = (range_max - range_min) * range_adjust range_scale = range / num_discrete_values const double offset_input = static_cast<double>(input) - lowest_quantized; result = range_min + ((input - numeric_limits<T>::min()) * range_scale)
If the mode is SCALED
, dequantization is performed by multiplying each
input value by a scaling_factor. (Thus an input of 0 always maps to 0.0).
The scaling_factor is determined from min_range
, max_range
, and
narrow_range
in a way that is compatible with QuantizeAndDequantize{V2|V3}
and QuantizeV2
, using the following algorithm:
const int min_expected_T = std::numeric_limits<T>::min() + (narrow_range ? 1 : 0); const int max_expected_T = std::numeric_limits<T>::max(); const float max_expected_T = std::numeric_limits<float>::max(); const float scale_factor = (std::numeric_limits<T>::min() == 0) ? (max_range / max_expected_T) : std::max(min_range / min_expected_T, max_range / max_expected_T);
Modifier and Type | Class and Description |
---|---|
static class |
Dequantize.Inputs |
static class |
Dequantize.Options
Optional attributes for
Dequantize |
Modifier and Type | Field and Description |
---|---|
static String |
OP_NAME
The name of this op, as known by TensorFlow core engine
|
Constructor and Description |
---|
Dequantize(Operation operation) |
Modifier and Type | Method and Description |
---|---|
Output<U> |
asOutput()
Returns the symbolic handle of the tensor.
|
static Dequantize.Options |
axis(Long axis)
Sets the axis option.
|
static <U extends TNumber> |
create(Scope scope,
Operand<? extends TNumber> input,
Operand<TFloat32> minRange,
Operand<TFloat32> maxRange,
Class<U> dtype,
Dequantize.Options... options)
Factory method to create a class wrapping a new Dequantize operation.
|
static Dequantize<TFloat32> |
create(Scope scope,
Operand<? extends TNumber> input,
Operand<TFloat32> minRange,
Operand<TFloat32> maxRange,
Dequantize.Options[] options)
Factory method to create a class wrapping a new Dequantize operation, with the default output types.
|
static Dequantize.Options |
mode(String mode)
Sets the mode option.
|
static Dequantize.Options |
narrowRange(Boolean narrowRange)
Sets the narrowRange option.
|
Output<U> |
output()
Gets output.
|
public static final String OP_NAME
public Dequantize(Operation operation)
@Endpoint(describeByClass=true) public static <U extends TNumber> Dequantize<U> create(Scope scope, Operand<? extends TNumber> input, Operand<TFloat32> minRange, Operand<TFloat32> maxRange, Class<U> dtype, Dequantize.Options... options)
U
- data type for Dequantize
output and operandsscope
- current scopeinput
- The input valueminRange
- The minimum scalar value possibly produced for the input.maxRange
- The maximum scalar value possibly produced for the input.dtype
- Type of the output tensor. Currently Dequantize supports float and bfloat16.
If 'dtype' is 'bfloat16', it only supports 'MIN_COMBINED' mode.options
- carries optional attribute values@Endpoint(describeByClass=true) public static Dequantize<TFloat32> create(Scope scope, Operand<? extends TNumber> input, Operand<TFloat32> minRange, Operand<TFloat32> maxRange, Dequantize.Options[] options)
scope
- current scopeinput
- The input valueminRange
- The minimum scalar value possibly produced for the input.maxRange
- The maximum scalar value possibly produced for the input.options
- carries optional attribute valuespublic static Dequantize.Options mode(String mode)
mode
- the mode optionpublic static Dequantize.Options narrowRange(Boolean narrowRange)
narrowRange
- the narrowRange optionpublic static Dequantize.Options axis(Long axis)
axis
- the axis optionpublic Output<U> asOutput()
Operand
Inputs to TensorFlow operations are outputs of another TensorFlow operation. This method is used to obtain a symbolic handle that represents the computation of the input.
asOutput
in interface Operand<U extends TNumber>
OperationBuilder.addInput(Output)
Copyright © 2015–2022. All rights reserved.