aboutsummaryrefslogtreecommitdiff
path: root/tests/validation/reference/QuantizationLayer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/validation/reference/QuantizationLayer.cpp')
-rw-r--r--tests/validation/reference/QuantizationLayer.cpp50
1 files changed, 1 insertions, 49 deletions
diff --git a/tests/validation/reference/QuantizationLayer.cpp b/tests/validation/reference/QuantizationLayer.cpp
index 3d6c5bc13d..2f3348178c 100644
--- a/tests/validation/reference/QuantizationLayer.cpp
+++ b/tests/validation/reference/QuantizationLayer.cpp
@@ -33,55 +33,6 @@ namespace validation
{
namespace reference
{
-template <typename T, typename std::enable_if<is_floating_point<T>::value, int>::type>
-SimpleTensor<uint8_t> quantization_layer(const SimpleTensor<T> &src)
-{
- // Create reference
- SimpleTensor<uint8_t> dst{ src.shape(), DataType::U8 };
-
- const int width = src.shape().x();
- const int height = src.shape().y();
- const int depth = src.shape().z();
- const int stride_w = width * height * depth;
- const int num_batches = src.shape().total_size_upper(3);
-
- for(int k = 0; k < num_batches; ++k)
- {
- // Compute min and max of the 3D tensor
- float min = src[k * stride_w];
- float max = src[k * stride_w];
-
- // Look for min and max values
- for(int i = 1; i < stride_w; ++i)
- {
- float val = src[i + k * stride_w];
- min = std::min(min, val);
- max = std::max(max, val);
- }
-
- // Saturate the result in case min = max
- if(min == max)
- {
- min = 0.0f;
- max = 1.0f;
- }
-
- const float range = max - min;
-
- for(int i = 0; i < stride_w; ++i)
- {
- // map values to range [0.0, 1.0]
- float val = src[i + k * stride_w];
- const float normalized = (val - min) / range;
- dst[i + k * stride_w] = static_cast<uint8_t>(std::min(255.0f, normalized * 256.0f));
- }
- }
-
- return dst;
-}
-
-template SimpleTensor<uint8_t> quantization_layer(const SimpleTensor<float> &src);
-
template <typename T>
SimpleTensor<uint8_t> quantization_layer(const SimpleTensor<T> &src, const QuantizationInfo quantization_info)
{
@@ -98,6 +49,7 @@ SimpleTensor<uint8_t> quantization_layer(const SimpleTensor<T> &src, const Quant
}
return dst;
}
+
template SimpleTensor<uint8_t> quantization_layer(const SimpleTensor<half> &src, const QuantizationInfo quantization_info);
template SimpleTensor<uint8_t> quantization_layer(const SimpleTensor<float> &src, const QuantizationInfo quantization_info);
} // namespace reference