Matthew Bentham | f61c270 | 2019-04-23 16:43:27 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include <armnn/Tensor.hpp> |
| 9 | |
| 10 | #include "../ConversionUtils.hpp" |
| 11 | |
| 12 | namespace armnn_driver |
| 13 | { |
| 14 | |
| 15 | inline armnn::TensorShape FlattenFullyConnectedInput(const armnn::TensorShape &inputShape, |
| 16 | const armnn::TensorShape &weightsShape) |
| 17 | { |
| 18 | if (inputShape.GetNumDimensions() > 2U) |
| 19 | { |
Matthew Bentham | e9aa469 | 2019-04-24 14:36:20 +0100 | [diff] [blame] | 20 | unsigned int totalInputElements = inputShape.GetNumElements(); |
| 21 | unsigned int inputSize = weightsShape[1]; |
Matthew Bentham | f61c270 | 2019-04-23 16:43:27 +0100 | [diff] [blame] | 22 | |
Matthew Bentham | e9aa469 | 2019-04-24 14:36:20 +0100 | [diff] [blame] | 23 | unsigned int batchSize = totalInputElements / inputSize; |
Matthew Bentham | f61c270 | 2019-04-23 16:43:27 +0100 | [diff] [blame] | 24 | |
Matthew Bentham | e9aa469 | 2019-04-24 14:36:20 +0100 | [diff] [blame] | 25 | if(totalInputElements % batchSize != 0) |
Matthew Bentham | f61c270 | 2019-04-23 16:43:27 +0100 | [diff] [blame] | 26 | { |
| 27 | throw std::runtime_error("Failed to deduce tensor shape"); |
| 28 | } |
| 29 | |
Matthew Bentham | e9aa469 | 2019-04-24 14:36:20 +0100 | [diff] [blame] | 30 | return armnn::TensorShape({batchSize, inputSize}); |
Matthew Bentham | f61c270 | 2019-04-23 16:43:27 +0100 | [diff] [blame] | 31 | } |
| 32 | else |
| 33 | { |
| 34 | return inputShape; |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | } |