aboutsummaryrefslogtreecommitdiff
path: root/1.0/FullyConnected.hpp
blob: 26d61e4c7e971faeb875a1c21ad203583ab7b17b (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
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#pragma once

#include <armnn/Tensor.hpp>

#include "../ConversionUtils.hpp"

namespace armnn_driver
{

inline armnn::TensorShape FlattenFullyConnectedInput(const armnn::TensorShape &inputShape,
                                                     const armnn::TensorShape &weightsShape)
{
    if (inputShape.GetNumDimensions() > 2U)
    {
        unsigned int totalInputElements = inputShape.GetNumElements();
        unsigned int inputSize = weightsShape[1];

        unsigned int batchSize = totalInputElements / inputSize;

        if(totalInputElements % batchSize != 0)
        {
            throw std::runtime_error("Failed to deduce tensor shape");
        }

        return armnn::TensorShape({batchSize, inputSize});
    }
    else
    {
        return inputShape;
    }
}

}