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

Function TestRequantizeMany

tensorflow/core/kernels/quantization_utils_test.cc:34–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32namespace {
33
34void TestRequantizeMany(Eigen::ThreadPoolDevice* eigen_device, float input_min,
35 float input_max, float output_min, float output_max,
36 const std::vector<qint32>& values_quantized,
37 int tolerance = 1) {
38 const int values_count = values_quantized.size();
39 std::vector<quint8> expected_values;
40 expected_values.reserve(values_count);
41 for (int value_index = 0; value_index < values_count; ++value_index) {
42 expected_values.push_back(FloatToQuantized<quint8>(
43 QuantizedToFloat(values_quantized[value_index], input_min, input_max),
44 output_min, output_max));
45 }
46
47 Tensor i_tensor =
48 tensorflow::test::AsTensor(gtl::ArraySlice<qint32>(values_quantized));
49 Tensor o_tensor(DT_QUINT8, TensorShape{values_count});
50 auto output_values = o_tensor.flat<quint8>();
51
52 if (eigen_device == nullptr) {
53 auto input_array = i_tensor.flat<qint32>();
54 RequantizeManyInNewRange(input_array.data(), input_array.size(), input_min,
55 input_max, output_min, output_max,
56 output_values.data());
57 } else {
58 RequantizeManyInNewRangeUsingEigen<qint32, quint8>(
59 *eigen_device, i_tensor, input_min, input_max, output_min, output_max,
60 &o_tensor);
61 }
62
63 const string tolerance_str = strings::StrCat("+-", tolerance);
64 for (size_t value_index = 0; value_index < values_count; ++value_index) {
65 int e = expected_values[value_index];
66 int v = output_values(value_index);
67 ASSERT_TRUE(std::abs(e - v) <= tolerance)
68 << "actual=" << v << ", expected=" << e << tolerance_str
69 << ", values_quantized[" << value_index
70 << "]=" << values_quantized[value_index] << ", input_min=" << input_min
71 << ", input_max=" << input_max << ", output_min=" << output_min
72 << ", output_max=" << output_max << ", value_index=" << value_index;
73 }
74}
75
76void TestRequantizeMany8To32Bit(float input_min, float input_max,
77 float output_min, float output_max,

Callers 1

Calls 9

QuantizedToFloatFunction · 0.85
RequantizeManyInNewRangeFunction · 0.85
AsTensorFunction · 0.70
absClass · 0.70
StrCatFunction · 0.50
sizeMethod · 0.45
reserveMethod · 0.45
push_backMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected