tensor akışı:: işlem:: Nicelizev2

#include <array_ops.h>

Quantize the 'input' tensor of type float to 'output' tensor of type 'T'.

Özet

[min_range, max_range] are scalar floats that specify the range for the 'input' data. The 'mode' attribute controls exactly which calculations are used to convert the float values to their quantized equivalents. 'Round_mode' özelliği, kayan değer değerlerinin nicelenmiş eşdeğerlerine yuvarlanmasında hangi yuvarlama eşitlik bozma algoritmasının kullanılacağını kontrol eder.

In 'MIN_COMBINED' mode, each value of the tensor will undergo the following:

out[i] = (in[i] - min_range) * range(T) / (max_range - min_range)
if T == qint8: out[i] -= (range(T) + 1) / 2.0

burada range(T) = numeric_limits ::max() - numeric_limits ::min() range(T) = numeric_limits ::max() - numeric_limits ::min() range(T) = numeric_limits ::max() - numeric_limits ::min()

MIN_COMBINED Mod Örneği

Assume the input is type float and has a possible range of [0.0, 6.0] and the output type is quint8 ([0, 255]). The min_range and max_range values should be specified as 0.0 and 6.0. Quantizing from float to quint8 will multiply each value of the input by 255/6 and cast to quint8.

If the output type was qint8 ([-128, 127]), the operation will additionally subtract each value by 128 prior to casting, so that the range of values aligns with the range of qint8.

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 = num_discrete_values / range
quantized = round(input * range_scale) - round(range_min * range_scale) +
  numeric_limits::min()
quantized = max(quantized, numeric_limits::min())
quantized = min(quantized, numeric_limits::max())

The biggest difference between this and MIN_COMBINED is that the minimum range is rounded first, before it's subtracted from the rounded value. With MIN_COMBINED, a small bias is introduced where repeated iterations of quantizing and dequantizing will introduce a larger and larger error.

Ölçekli mod örneği

SCALED mode matches the quantization approach used in QuantizeAndDequantize{V2|V3} .

If the mode is SCALED , we do not use the full range of the output type, choosing to elide the lowest possible value for symmetry (eg, output range is -127 to 127, not -128 to 127 for signed 8 bit quantization), böylece 0.0 0 ile eşleşir.

Öncelikle tensörümüzde değer aralığını buluyoruz. The range we use is always centered on 0, so we find m such that

  m = max(abs(input_min), abs(input_max))

Bu durumda giriş tensör aralığımız [-m, m] olur.

Next, we choose our fixed-point quantization buckets, [min_fixed, max_fixed] . T imzalanırsa, bu

  num_bits = sizeof(T) * 8
  [min_fixed, max_fixed] =
      [-(1 << (num_bits - 1) - 1), (1 << (num_bits - 1)) - 1]

Otherwise, if T is unsigned, the fixed-point range is

  [min_fixed, max_fixed] = [0, (1 << num_bits) - 1]

Buradan ölçeklendirme faktörümüzü (s) hesaplıyoruz:

  s = (max_fixed - min_fixed) / (2 * m)

Artık tensörümüzün elemanlarını nicemleyebiliriz:

result = round(input * s)

One thing to watch out for is that the operator may choose to adjust the requested minimum and maximum values slightly during the quantization process, so you should always use the output ports as the range for further calculations. For example, if the requested minimum and maximum values are close to equal, they will be separated by a small epsilon value to prevent ill-formed quantized buffers from being created. Otherwise, you can end up with buffers where all the quantized values map to the same float value, which causes problems for operations that have to perform further calculations on them.

Argümanlar:

  • kapsam: Bir Kapsam nesnesi
  • min_range: The minimum scalar value possibly produced for the input.
  • max_range: The maximum scalar value possibly produced for the input.

İadeler:

  • Output çıkışı: Float girişinden üretilen nicelenmiş veriler.
  • Output çıkışı_min: Çıkış için kullanılan gerçek minimum skaler değer.
  • Output çıkışı_maks: Çıkış için kullanılan gerçek maksimum skaler değer.

Yapıcılar ve Yıkıcılar

QuantizeV2 (const :: tensorflow::Scope & scope, :: tensorflow::Input input, :: tensorflow::Input min_range, :: tensorflow::Input max_range, DataType T)
QuantizeV2 (const :: tensorflow::Scope & scope, :: tensorflow::Input input, :: tensorflow::Input min_range, :: tensorflow::Input max_range, DataType T, const QuantizeV2::Attrs & attrs)

Genel özellikler

operation
output
output_max
output_min

Genel statik işlevler

Mode (StringPiece x)
RoundMode (StringPiece x)

Yapılar

tensorflow:: ops:: QuantizeV2:: Öznitelikler

QuantizeV2 için isteğe bağlı öznitelik ayarlayıcılar.

Genel özellikler

operasyon

Operation operation

çıktı

::tensorflow::Output output

output_max

::tensorflow::Output output_max

output_min

::tensorflow::Output output_min

Kamu işlevleri

Nicelizev2

 QuantizeV2(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input input,
  ::tensorflow::Input min_range,
  ::tensorflow::Input max_range,
  DataType T
)

Nicelizev2

 QuantizeV2(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input input,
  ::tensorflow::Input min_range,
  ::tensorflow::Input max_range,
  DataType T,
  const QuantizeV2::Attrs & attrs
)

Genel statik işlevler

Mod

Attrs Mode(
  StringPiece x
)

YuvarlakMod

Attrs RoundMode(
  StringPiece x
)