tensorflow:: ops:: Dequantize
#include <array_ops.h>まとめ
[min_range、max_range]は、入力データの範囲を指定するスカラー浮動小数点数です。「mode」属性は、浮動小数点値を量子化された値に変換するために使用する計算方法を正確に制御します。
「MIN_COMBINED」モードでは、テンソルの各値は以下の処理を受けます。
if T == qint8: in[i] += (range(T) + 1)/ 2.0 out[i] = min_range + (in[i]* (max_range - min_range) / range(T))
range(T) = numeric_limits ::max() - numeric_limits ::min() MIN_COMBINEDモードの例
入力がQuantizedRelu6の場合、出力タイプはquint8(範囲0~255)ですが、 QuantizedRelu6の可能な範囲は0~6です。したがって、min_rangeとmax_rangeの値は0.0と6.0になります。quint8に対するDequantizeでは、各値を取得し、float型にキャストして、6/255を乗算します。quantizedtypeがqint8の場合、キャスト前に各値に128が加算されることに注意してください。
モードが「MIN_FIRST」の場合は、この方法が使用されます。
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(input) - lowest_quantized; result = range_min + ((input - numeric_limits ::min()) * range_scale)
スケーリングモードの例
SCALEDモードはQuantizeAndDequantize{V2|V3}で使用される量子化アプローチと一致します。
モードがSCALEDの場合、出力タイプの全範囲を使用せず、対称性のために可能な限り低い値を省略することを選択します (たとえば、符号付き 8 ビット量子化の場合、出力範囲は -127 ~ 127 であり、-128 ~ 127 ではありません)。そのため、0.0 は 0 にマッピングされます。
まず、テンソルの値の範囲を求めます。使用する範囲は常に0を中心としているので、mは次のようになります。
m = max(abs(input_min), abs(input_max))
入力テンソルの範囲は[-m, m]です。
次に、固定小数点量子化バケット[min_fixed, max_fixed]を選択します。T が符号付きの場合、これは
num_bits = sizeof(T) * 8
[min_fixed, max_fixed] =
[-(1 << (num_bits - 1) - 1), (1 << (num_bits - 1)) - 1]それ以外の場合、Tが符号なしであれば、固定小数点範囲は
[min_fixed, max_fixed] = [0, (1 << num_bits) - 1]
これからスケーリング係数sを計算します。
s = (2 * m) / (max_fixed - min_fixed)
これで、テンソルの要素を逆量子化できます。
result = input * s
議論:
- スコープ:スコープオブジェクト
- min_range: 入力に対して生成される可能性のある最小スカラー値。
- max_range: 入力に対して生成可能な最大スカラー値。
返品:
-
Output:出力テンソル。
コンストラクターとデストラクタ | |
|---|---|
Dequantize (const :: tensorflow::Scope & scope, :: tensorflow::Input input, :: tensorflow::Input min_range, :: tensorflow::Input max_range) | |
Dequantize (const :: tensorflow::Scope & scope, :: tensorflow::Input input, :: tensorflow::Input min_range, :: tensorflow::Input max_range, const Dequantize::Attrs & attrs) |
公開属性 | |
|---|---|
operation | |
output | |
公的機能 | |
|---|---|
node () const | ::tensorflow::Node * |
operator::tensorflow::Input () const | |
operator::tensorflow::Output () const | |
パブリック静的関数 | |
|---|---|
Mode (StringPiece x) | |
構造 | |
|---|---|
| tensorflow:: ops:: Dequantize:: Attrs | Dequantizeのオプション属性設定子。 |
公開属性
手術
Operation operation
出力
::tensorflow::Output output
公的機能
逆量子化
Dequantize( const ::tensorflow::Scope & scope, ::tensorflow::Input input, ::tensorflow::Input min_range, ::tensorflow::Input max_range )
逆量子化
Dequantize( const ::tensorflow::Scope & scope, ::tensorflow::Input input, ::tensorflow::Input min_range, ::tensorflow::Input max_range, const Dequantize::Attrs & attrs )
ノード
::tensorflow::Node * node() const
operator::tensorflow::Input
operator::tensorflow::Input() const
operator::tensorflow::Output
operator::tensorflow::Output() const
パブリック静的関数
モード
Attrs Mode( StringPiece x )