aboutsummaryrefslogtreecommitdiff
path: root/include/armnnQuantizer/INetworkQuantizer.hpp
blob: 826b077f6e28577e4b06c0014fdee521af3e5e83 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#pragma once

#include <armnn/INetwork.hpp>
#include <armnn/Types.hpp>
#include <armnn/Tensor.hpp>

namespace armnn
{

struct QuantizerOptions
{
    QuantizerOptions() : QuantizerOptions(DataType::QuantisedAsymm8, false) {}

    QuantizerOptions(DataType activationFormat) : QuantizerOptions(activationFormat, false) {}

    QuantizerOptions(DataType activationFormat, bool preserveType)
    : m_ActivationFormat(activationFormat)
    , m_PreserveType(preserveType) {}

    DataType m_ActivationFormat;
    bool m_PreserveType;
};

using INetworkQuantizerPtr = std::unique_ptr<class INetworkQuantizer, void(*)(INetworkQuantizer* quantizer)>;

/// Quantizer class Quantizes a float32 InputNetwork
class INetworkQuantizer
{
public:
    /// Create Quantizer object and return raw pointer
    static INetworkQuantizer* CreateRaw(INetwork* inputNetwork, const QuantizerOptions& options = QuantizerOptions());

    /// Create Quantizer object wrapped in unique_ptr
    static INetworkQuantizerPtr Create(INetwork* inputNetwork, const QuantizerOptions& options = QuantizerOptions());

    /// Destroy Quantizer object
    static void Destroy(INetworkQuantizer* quantizer);

    /// Overrides the default quantization values for the input layer with the given id
    virtual void OverrideInputRange(LayerBindingId layerId, float min, float max) = 0;

    /// Refine input network with a set of refinement data for specified LayerBindingId
    virtual void Refine(const InputTensors& inputTensors) = 0;

    /// Extract final quantized network
    virtual INetworkPtr ExportNetwork() = 0;

protected:
    virtual ~INetworkQuantizer() {}
};

} //namespace armnn