aboutsummaryrefslogtreecommitdiff
path: root/include/armnnTfParser/ITfParser.hpp
blob: 91e4cb39bfa2e2e677853ca489d9ae44e825a911 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//
#pragma once

#include "armnn/Types.hpp"
#include "armnn/Tensor.hpp"
#include "armnn/INetwork.hpp"

#include <map>
#include <memory>
#include <unordered_map>
#include <vector>

namespace armnnTfParser
{

using BindingPointInfo = armnn::BindingPointInfo;

class ITfParser;
using ITfParserPtr = std::unique_ptr<ITfParser, void(*)(ITfParser* parser)>;

/// Parses a directed acyclic graph from a tensorflow protobuf file.
class ITfParser
{
public:
    static ITfParser* CreateRaw();
    static ITfParserPtr Create();
    static void Destroy(ITfParser* parser);

    /// Create the network from a protobuf text file on the disk.
    armnn::INetworkPtr CreateNetworkFromTextFile(
        const char* graphFile,
        const std::map<std::string, armnn::TensorShape>& inputShapes,
        const std::vector<std::string>& requestedOutputs);

    /// Create the network from a protobuf binary file on the disk.
    armnn::INetworkPtr CreateNetworkFromBinaryFile(
        const char* graphFile,
        const std::map<std::string, armnn::TensorShape>& inputShapes,
        const std::vector<std::string>& requestedOutputs);

    /// Create the network directly from protobuf text in a string. Useful for debugging/testing.
    armnn::INetworkPtr CreateNetworkFromString(
        const char* protoText,
        const std::map<std::string, armnn::TensorShape>& inputShapes,
        const std::vector<std::string>& requestedOutputs);

    /// Retrieve binding info (layer id and tensor info) for the network input identified by the given layer name.
    BindingPointInfo GetNetworkInputBindingInfo(const std::string& name) const;

    /// Retrieve binding info (layer id and tensor info) for the network output identified by the given layer name.
    BindingPointInfo GetNetworkOutputBindingInfo(const std::string& name) const;

private:
    template <typename T>
    friend class ParsedConstTfOperation;
    friend class ParsedMatMulTfOperation;
    friend class ParsedMulTfOperation;
    friend class ParsedTfOperation;
    friend class SingleLayerParsedTfOperation;
    friend class DeferredSingleLayerParsedTfOperation;
    friend class ParsedIdentityTfOperation;

    template <template<typename> class OperatorType, typename T>
    friend struct MakeTfOperation;


    ITfParser();
    ~ITfParser();

    struct TfParserImpl;
    std::unique_ptr<TfParserImpl> pTfParserImpl;
};

}