blob: a6f9ebdc42385763bafc124e042a42f9a9fa4644 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//
#include "NetworkQuantizerUtils.hpp"
#include <algorithm>
#include <cmath>
#include <stdint.h>
namespace armnn
{
ConstTensor CreateQuantizedConst(const ConstTensor& tensor, std::vector<uint8_t>& backing)
{
float scale = 0.0f;
int offset = 0;
// Reserve the backing memory
backing.resize(tensor.GetInfo().GetNumElements());
DataType type = tensor.GetInfo().GetDataType();
switch(type)
{
case DataType::Float32:
{
QuantizeConstant(static_cast<const float*>(tensor.GetMemoryArea()),
backing.data(),
backing.size(),
scale,
offset);
}
break;
default:
BOOST_ASSERT_MSG(false, "Can't quantize unsupported data type");
}
TensorInfo qInfo(tensor.GetInfo().GetShape(), DataType::QuantisedAsymm8, scale, offset);
return ConstTensor(qInfo, backing);
}
} // namespace armnn
|