diff options
author | Xusong Wang <xusongw@google.com> | 2019-05-30 18:23:33 -0700 |
---|---|---|
committer | Xusong Wang <xusongw@google.com> | 2019-05-31 09:56:14 -0700 |
commit | 7fdc3e2d0c1bed514780c1c69e15db063eb64670 (patch) | |
tree | 805f9baeb36a7159647cf7f4950010f3d9fc5351 | |
parent | c8747bb09bd63bf7d4e01bd4625de05cd83bb6f8 (diff) | |
download | ml-7fdc3e2d0c1bed514780c1c69e15db063eb64670.tar.gz |
Use rounding in requantize.
This is to avoid a systematic bias of ops using requantize.
Fixes: 134078526
Test: NeuralNetworksTest_static
Change-Id: I3f64f5b2d5778bfe613707cfa252f67e87dce9c5
-rw-r--r-- | nn/common/OperationsUtils.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/nn/common/OperationsUtils.cpp b/nn/common/OperationsUtils.cpp index 99c11780c..e128afbb7 100644 --- a/nn/common/OperationsUtils.cpp +++ b/nn/common/OperationsUtils.cpp @@ -340,7 +340,7 @@ uint8_t requantize(uint8_t value, const Shape& oldShape, const Shape& newShape) double doubleRet = doubleValue / newShape.scale + newShape.offset; if (doubleRet < 0) return 0; if (doubleRet > 255) return 255; - return static_cast<uint8_t>(doubleRet); + return static_cast<uint8_t>(std::round(doubleRet)); } bool floorPrepare(const Shape& input, Shape* output) { |