텐서플로우:: 작전:: 역양자화

#include <array_ops.h>

'입력' 텐서를 float Tensor역양자화합니다 .

요약

[min_range, max_range]는 '입력' 데이터의 범위를 지정하는 스칼라 부동 소수점입니다. 'mode' 속성은 float 값을 양자화된 값으로 변환하는 데 사용되는 계산을 정확하게 제어합니다.

'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() range(T) = numeric_limits ::max() - numeric_limits ::min() 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의 역양자화는 각 값을 가져와 부동 소수점으로 변환하고 6/255를 곱합니다. 양자화 유형이 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비트 양자화의 경우 -128~127이 아니라 -127~127입니다). 0.0이 0에 매핑되도록 합니다.

먼저 텐서에서 값의 범위를 찾습니다. 우리가 사용하는 범위는 항상 0을 중심으로 하므로

  m = max(abs(input_min), abs(input_max))
과 같은 m을 찾습니다.

그러면 입력 텐서 범위는 [-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: 입력에 대해 생성될 수 있는 최대 스칼라 값입니다.

보고:

생성자와 소멸자

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)

구조체

텐서플로우:: ops:: 역양자화:: 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() const 

연산자::텐서플로우::출력

 operator::tensorflow::Output() const 

공개 정적 함수

방법

Attrs Mode(
  StringPiece x
)