ArmNN
 22.08
FullyConnectedTestImpl.hpp File Reference

Go to the source code of this file.

Functions

template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
LayerTestResult< T, 2 > FullyConnectedTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, bool biasEnabled, bool constantWeights)
 
LayerTestResult< float, 2 > FullyConnectedFloat32Test (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, bool biasEnabled, bool transposeWeights)
 
LayerTestResult< float, 2 > FullyConnectedLargeTest (armnn::IWorkloadFactory &workloadFactory, const armnn::IBackendInternal::IMemoryManagerSharedPtr &memoryManager, const armnn::ITensorHandleFactory &tensorHandleFactory, bool transposeWeights)
 

Function Documentation

◆ FullyConnectedFloat32Test()

LayerTestResult<float, 2> FullyConnectedFloat32Test ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
const armnn::ITensorHandleFactory tensorHandleFactory,
bool  biasEnabled,
bool  transposeWeights 
)

Definition at line 280 of file FullyConnectedTestImpl.cpp.

References armnn::Float32, LayerTestResult< T, n >::m_ExpectedData, and armnn::swap().

Referenced by TEST_SUITE().

286 {
287  unsigned int inputWidth = 1;
288  unsigned int inputHeight = 1;
289  unsigned int inputChannels = 5;
290  unsigned int inputNum = 2;
291 
292  unsigned int outputChannels = 3;
293  unsigned int outputNum = 2;
294 
295  // Define the tensor descriptors.
296  armnn::TensorInfo inputTensorInfo;
297  armnn::TensorInfo outputTensorInfo;
298  armnn::TensorInfo weightsDesc;
299  armnn::TensorInfo biasesDesc;
300 
301  unsigned int inputShape[] = { inputNum, inputChannels, inputHeight, inputWidth };
302  unsigned int outputShape[] = { outputNum, outputChannels };
303  unsigned int weightsShape[] = { inputChannels, outputChannels };
304 
305  if (transposeWeights)
306  {
307  std::swap(weightsShape[0], weightsShape[1]);
308  }
309 
310  unsigned int biasShape[] = { outputChannels };
311 
312  inputTensorInfo = armnn::TensorInfo(4, inputShape, armnn::DataType::Float32);
313  outputTensorInfo = armnn::TensorInfo(2, outputShape, armnn::DataType::Float32);
314  weightsDesc = armnn::TensorInfo(2, weightsShape, armnn::DataType::Float32);
315  biasesDesc = armnn::TensorInfo(1, biasShape, armnn::DataType::Float32);
316 
317  LayerTestResult<float, 2> result(outputTensorInfo);
318 
319  std::vector<float> input =
320  {
321  1.0f, 2.0f, 3.0f, 4.0f, 5.0f,
322  5.0f, 4.0f, 3.0f, 2.0f, 1.0f
323  };
324 
325  std::vector<float> weights =
326  {
327  .5f, 2.f, .5f,
328  .5f, 2.f, 1.f,
329  .5f, 2.f, 2.f,
330  .5f, 2.f, 3.f,
331  .5f, 2.f, 4.f
332  };
333 
334  if (transposeWeights)
335  {
336  weights =
337  {
338  .5f, .5f, .5f, .5f, .5f,
339  2.f, 2.f, 2.f, 2.f, 2.f,
340  .5f, 1.f, 2.f, 3.f, 4.f
341  };
342  }
343 
344  std::vector<float> biasValues({0.f, 0.f, 0.f});
345  if (biasEnabled)
346  {
347  biasValues = std::vector<float>({10.f, 20.f, 30.f});
348  }
349 
350  result = SimpleFullyConnectedTestImpl<float>(
351  workloadFactory,
352  memoryManager,
353  tensorHandleFactory,
354  inputTensorInfo, outputTensorInfo,
355  weightsDesc, biasesDesc,
356  weights, biasValues, input,
357  biasEnabled, transposeWeights, true
358  );
359 
360  std::vector<float> expectedOutput =
361  {
362  0.5f + 1.0f + 1.5f + 2.0f + 2.5f + biasValues[0],
363  2.0f + 4.0f + 6.0f + 8.0f + 10.f + biasValues[1],
364  0.5f + 2.0f + 6.0f + 12.f + 20.f + biasValues[2],
365 
366  2.5f + 2.0f + 1.5f + 1.0f + 0.5f + biasValues[0],
367  10.0f + 8.0f + 6.0f + 4.0f + 2.f + biasValues[1],
368  2.5f + 4.0f + 6.0f + 6.f + 4.f + biasValues[2]
369  };
370  result.m_ExpectedData = expectedOutput;
371 
372  return result;
373 }
void swap(OriginsDescriptor &first, OriginsDescriptor &second)

◆ FullyConnectedLargeTest()

LayerTestResult<float, 2> FullyConnectedLargeTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
const armnn::ITensorHandleFactory tensorHandleFactory,
bool  transposeWeights 
)

Definition at line 375 of file FullyConnectedTestImpl.cpp.

Referenced by TEST_SUITE().

380 {
381  return FullyConnectedLargeTestCommon<armnn::DataType::Float32>(workloadFactory,
382  memoryManager,
383  tensorHandleFactory,
384  transposeWeights);
385 }

◆ FullyConnectedTest()

LayerTestResult<T, 2> FullyConnectedTest ( armnn::IWorkloadFactory workloadFactory,
const armnn::IBackendInternal::IMemoryManagerSharedPtr memoryManager,
const armnn::ITensorHandleFactory tensorHandleFactory,
bool  biasEnabled,
bool  constantWeights 
)

Definition at line 97 of file FullyConnectedTestImpl.cpp.

References armnn::GetBiasTypeFromWeightsType(), LayerTestResult< T, n >::m_ExpectedData, and TensorInfo::SetQuantizationScale().

103 {
104  constexpr static unsigned int inputWidth = 3u;
105  constexpr static unsigned int inputHeight = 2u;
106  constexpr static unsigned int inputChannels = 1u;
107 
108  constexpr static unsigned int inputSize = inputWidth * inputHeight * inputChannels;
109 
110  constexpr static unsigned int outputChannels = 2u;
111 
112  armnn::TensorInfo inputTensorInfo({ 1, inputChannels, inputHeight, inputWidth }, ArmnnType);
113  inputTensorInfo.SetQuantizationScale(0.1f);
114  inputTensorInfo.SetQuantizationOffset(63);
115 
116  armnn::TensorInfo outputTensorInfo({ 1, outputChannels }, ArmnnType);
117  outputTensorInfo.SetQuantizationScale(5.f);
118  outputTensorInfo.SetQuantizationOffset(biasEnabled ? -50 : 10);
119 
120  armnn::TensorInfo weightsDesc({ outputChannels, inputSize }, ArmnnType);
121  weightsDesc.SetQuantizationScale(0.2f);
122  weightsDesc.SetQuantizationOffset(93);
123 
124  armnn::TensorInfo biasesDesc({ outputChannels }, GetBiasTypeFromWeightsType(weightsDesc.GetDataType()).value());
125  biasesDesc.SetQuantizationScale(inputTensorInfo.GetQuantizationScale() * weightsDesc.GetQuantizationScale());
126  biasesDesc.SetQuantizationOffset(0);
127 
128  LayerTestResult<T, 2> result(outputTensorInfo);
129 
130  std::vector<T> input = ConvertToDataType<ArmnnType>(
131  {
132  -1.2f, 6.1f, -3.5f,
133  18.8f, -5.5f, 2.9f
134  },
135  inputTensorInfo);
136 
137  std::vector<T> weights = ConvertToDataType<ArmnnType>(
138  {
139  -8.4f, 20.0f, -10.4f, -8, 16.4f, -11.8f,
140  23.4f, 10.4f, -14.0f, -3.8f, -11.8f, 11.4f
141  },
142  weightsDesc);
143 
144  std::vector<int32_t> bias = {9250, 67500};
145 
146  result = SimpleFullyConnectedTestImpl<T>(workloadFactory,
147  memoryManager,
148  tensorHandleFactory,
149  inputTensorInfo,
150  outputTensorInfo,
151  weightsDesc,
152  biasesDesc,
153  weights,
154  bias,
155  input,
156  biasEnabled,
157  true,
158  constantWeights);
159 
160  if (biasEnabled)
161  {
162  result.m_ExpectedData = ConvertToDataType<ArmnnType>({80.f, 1460.f}, outputTensorInfo);
163  }
164  else
165  {
166  result.m_ExpectedData = ConvertToDataType<ArmnnType>({-107.04f, 110.f}, outputTensorInfo);
167  }
168 
169  return result;
170 }
armnn::Optional< armnn::DataType > GetBiasTypeFromWeightsType(armnn::Optional< armnn::DataType > weightsType)
void SetQuantizationScale(float scale)
Definition: Tensor.cpp:473