36 const std::vector<float>& output = mapbox::util::get<std::vector<float>>(this->
GetOutputs()[0]);
39 constexpr
unsigned int gridSize = 7;
40 constexpr
unsigned int numClasses = 20;
41 constexpr
unsigned int numScales = 2;
43 const float* outputPtr = output.data();
46 vector<vector<vector<float>>> classProbabilities(gridSize, vector<vector<float>>(gridSize,
47 vector<float>(numClasses)));
48 for (
unsigned int y = 0; y < gridSize; ++y)
50 for (
unsigned int x = 0; x < gridSize; ++x)
52 for (
unsigned int c = 0; c < numClasses; ++c)
54 classProbabilities[y][x][c] = *outputPtr++;
60 vector<vector<vector<float>>> scales(gridSize, vector<vector<float>>(gridSize, vector<float>(numScales)));
61 for (
unsigned int y = 0; y < gridSize; ++y)
63 for (
unsigned int x = 0; x < gridSize; ++x)
65 for (
unsigned int s = 0; s < numScales; ++s)
67 scales[y][x][s] = *outputPtr++;
73 constexpr
float imageWidthAsFloat =
static_cast<float>(
YoloImageWidth);
74 constexpr
float imageHeightAsFloat =
static_cast<float>(
YoloImageHeight);
76 vector<vector<vector<vector<float>>>> boxes(gridSize, vector<vector<vector<float>>>
77 (gridSize, vector<vector<float>>(numScales, vector<float>(4))));
78 for (
unsigned int y = 0; y < gridSize; ++y)
80 for (
unsigned int x = 0; x < gridSize; ++x)
82 for (
unsigned int s = 0; s < numScales; ++s)
84 float bx = *outputPtr++;
85 float by = *outputPtr++;
86 float bw = *outputPtr++;
87 float bh = *outputPtr++;
89 boxes[y][x][s][0] = ((bx +
static_cast<float>(x)) / 7.0f) * imageWidthAsFloat;
90 boxes[y][x][s][1] = ((by +
static_cast<float>(y)) / 7.0f) * imageHeightAsFloat;
91 boxes[y][x][s][2] = bw * bw *
static_cast<float>(imageWidthAsFloat);
92 boxes[y][x][s][3] = bh * bh *
static_cast<float>(imageHeightAsFloat);
98 std::vector<YoloDetectedObject> detectedObjects;
99 detectedObjects.reserve(gridSize * gridSize * numScales * numClasses);
101 for (
unsigned int y = 0; y < gridSize; ++y)
103 for (
unsigned int x = 0; x < gridSize; ++x)
105 for (
unsigned int s = 0; s < numScales; ++s)
107 for (
unsigned int c = 0; c < numClasses; ++c)
110 const float confidence = classProbabilities[y][x][c] * scales[y][x][s];
114 box.
m_X = boxes[y][x][s][0];
115 box.
m_Y = boxes[y][x][s][1];
116 box.
m_W = boxes[y][x][s][2];
117 box.
m_H = boxes[y][x][s][3];
119 detectedObjects.emplace_back(c, box, confidence);
126 std::sort(detectedObjects.begin(), detectedObjects.end(),
135 auto outputIt = detectedObjects.begin();
136 auto outputEnd = detectedObjects.end();
140 if (outputIt == outputEnd)
143 return TestCaseResult::Abort;
147 if (detectedObject.
m_Class != expectedDetection.m_Class)
150 " is incorrect: Expected (" << expectedDetection.m_Class <<
")" <<
151 " but predicted (" << detectedObject.
m_Class <<
")";
152 return TestCaseResult::Failed;
163 return TestCaseResult::Failed;
169 return TestCaseResult::Ok;
constexpr unsigned int YoloImageHeight
#define ARMNN_LOG(severity)
void IgnoreUnused(Ts &&...)
const std::vector< armnnUtils::TContainer > & GetOutputs() const
unsigned int GetTestCaseId() const
#define ARMNN_ASSERT(COND)
constexpr size_t YoloOutputSize
constexpr unsigned int YoloImageWidth
bool within_percentage_tolerance(float a, float b, float tolerancePercent=1.0f)
Compare two floats and return true if their values are within a specified tolerance of each other...