MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / GetLegacyQuantization

Function GetLegacyQuantization

tensorflow/lite/core/subgraph.cc:92–117  ·  view source on GitHub ↗

Gets the legacy TfLiteQuantizationParams from the current TfLiteQuantization.

Source from the content-addressed store, hash-verified

90
91// Gets the legacy TfLiteQuantizationParams from the current TfLiteQuantization.
92TfLiteQuantizationParams GetLegacyQuantization(
93 const TfLiteQuantization& quantization) {
94 TfLiteQuantizationParams legacy_quantization;
95 legacy_quantization.scale = 0;
96 legacy_quantization.zero_point = 0;
97
98 // If the quantization type isn't affine, return the empty
99 // legacy_quantization.
100 if (quantization.type != kTfLiteAffineQuantization) {
101 return legacy_quantization;
102 }
103
104 auto* affine_quantization =
105 reinterpret_cast<TfLiteAffineQuantization*>(quantization.params);
106 if (!affine_quantization || !affine_quantization->scale ||
107 !affine_quantization->zero_point ||
108 affine_quantization->scale->size != 1 ||
109 affine_quantization->zero_point->size != 1) {
110 return legacy_quantization;
111 }
112
113 // We know its per-layer quantization now.
114 legacy_quantization.scale = affine_quantization->scale->data[0];
115 legacy_quantization.zero_point = affine_quantization->zero_point->data[0];
116 return legacy_quantization;
117}
118
119} // namespace
120

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected