15 #include <doctest/doctest.h> 34 Connect(inputLayer, fullyConnectedLayer, inputTensorInfo, 0, 0);
35 Connect(weightsInputLayer, fullyConnectedLayer, weightsTensorInfo, 0, 1);
36 Connect(fullyConnectedLayer, outputLayer, outputTensorInfo, 0, 0);
56 Connect(inputLayer, fullyConnectedLayer, inputTensorInfo, 0, 0);
57 Connect(weightsInputLayer, fullyConnectedLayer, weightsTensorInfo, 0, 1);
58 Connect(biasLayer, fullyConnectedLayer, biasTensorInfo, 0, 2);
59 Connect(fullyConnectedLayer, outputLayer, outputTensorInfo, 0, 0);
79 Connect(inputLayer, fullyConnectedLayer, inputTensorInfo, 0, 0);
80 Connect(weightsLayer, fullyConnectedLayer, weightsTensorInfo, 0, 1);
81 Connect(biasLayer, fullyConnectedLayer, biasTensorInfo, 0, 2);
82 Connect(fullyConnectedLayer, outputLayer, outputTensorInfo, 0, 0);
87 template<armnn::DataType ArmnnType,
typename T = armnn::ResolveType<ArmnnType>>
88 void FullyConnectedWithDynamicWeightsEndToEnd(
const std::vector<armnn::BackendId>& backends)
90 using namespace armnn;
109 std::vector<T> inputData {
114 std::vector<T> weightsData {
115 -8.4f, 20.0f, -10.4f, -8, 16.4f, -11.8f,
116 23.4f, 10.4f, -14.0f, -3.8f, -11.8f, 11.4f
119 std::vector<T> floatExpectedOutputData {
122 std::vector<T> expectedOutputData = armnnUtils::QuantizedVector<T>(floatExpectedOutputData);
124 armnn::INetworkPtr network = CreateFullyConnectedNetworkNonConstWeights(inputTensorInfo,
131 std::map<int, std::vector<T>> inputTensorData = {{ 0, inputData }, {1, weightsData}};
132 std::map<int, std::vector<T>> expectedOutputTensorData = {{ 0, expectedOutputData }};
134 EndToEndLayerTestImpl<ArmnnType, ArmnnType>(move(network),
136 expectedOutputTensorData,
141 template<armnn::DataType ArmnnType,
typename T = armnn::ResolveType<ArmnnType>>
142 void FullyConnectedWithDynamicOrConstantInputsEndToEnd(
const std::vector<armnn::BackendId>& backends,
143 const bool transposeWeights,
144 const bool constantWeightsOrBias)
146 unsigned int inputWidth = 1;
147 unsigned int inputHeight = 1;
148 unsigned int inputChannels = 5;
149 unsigned int inputNum = 2;
151 unsigned int outputChannels = 3;
152 unsigned int outputNum = 2;
154 unsigned int inputShape[] = { inputNum, inputChannels, inputHeight, inputWidth };
155 unsigned int outputShape[] = { outputNum, outputChannels };
156 unsigned int weightsShape[] = { inputChannels, outputChannels };
158 if (transposeWeights)
160 std::swap(weightsShape[0], weightsShape[1]);
163 unsigned int biasShape[] = { outputChannels };
170 std::vector<float> input =
172 1.0f, 2.0f, 3.0f, 4.0f, 5.0f,
173 5.0f, 4.0f, 3.0f, 2.0f, 1.0f
176 std::vector<float> weights =
185 if (transposeWeights)
189 .5f, .5f, .5f, .5f, .5f,
190 2.f, 2.f, 2.f, 2.f, 2.f,
191 .5f, 1.f, 2.f, 3.f, 4.f
195 std::vector<float> biasValues = std::vector<float>({10.f, 20.f, 30.f});
197 std::vector<float> expectedOutput =
199 0.5f + 1.0f + 1.5f + 2.0f + 2.5f + biasValues[0],
200 2.0f + 4.0f + 6.0f + 8.0f + 10.f + biasValues[1],
201 0.5f + 2.0f + 6.0f + 12.f + 20.f + biasValues[2],
203 2.5f + 2.0f + 1.5f + 1.0f + 0.5f + biasValues[0],
204 10.0f + 8.0f + 6.0f + 4.0f + 2.f + biasValues[1],
205 2.5f + 4.0f + 6.0f + 6.f + 4.f + biasValues[2]
213 if (!constantWeightsOrBias)
216 ConstTensor biasConstantTensor(biasesDesc, biasValues.data());
218 armnn::INetworkPtr network = CreateFullyConnectedNetworkNonConstWeightsConstBias(inputTensorInfo,
226 std::map<int, std::vector<T>> inputTensorData = {{ 0, input }, {1, weights}};
227 std::map<int, std::vector<T>> expectedOutputTensorData = {{ 0, expectedOutput }};
229 EndToEndLayerTestImpl<ArmnnType, ArmnnType>(move(network),
231 expectedOutputTensorData,
238 ConstTensor weightsConstantTensor(weightsDesc, weights.data());
240 armnn::INetworkPtr network = CreateFullyConnectedNetworkConstWeightsNonConstBias(inputTensorInfo,
244 weightsConstantTensor,
248 std::map<int, std::vector<T>> inputTensorData = {{ 0, input }, {2, biasValues}};
249 std::map<int, std::vector<T>> expectedOutputTensorData = {{ 0, expectedOutput }};
251 EndToEndLayerTestImpl<ArmnnType, ArmnnType>(move(network),
253 expectedOutputTensorData,
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
void swap(OriginsDescriptor &first, OriginsDescriptor &second)
bool m_TransposeWeightMatrix
Enable/disable transpose weight matrix.
Copyright (c) 2021 ARM Limited and Contributors.
A FullyConnectedDescriptor for the FullyConnectedLayer.
bool m_BiasEnabled
Enable/disable bias.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
void SetQuantizationScale(float scale)
void SetQuantizationOffset(int32_t offset)
void Connect(armnn::IConnectableLayer *from, armnn::IConnectableLayer *to, const armnn::TensorInfo &tensorInfo, unsigned int fromIndex, unsigned int toIndex)
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
static INetworkPtr Create(NetworkOptions networkOptions={})
bool m_ConstantWeights
Enable/disable constant weights and biases.