| 72 | {} |
| 73 | |
| 74 | std::unique_ptr<MobileNetSsdTestCaseData> MobileNetSsdDatabase::GetTestCaseData(unsigned int testCaseId) |
| 75 | { |
| 76 | const unsigned int safeTestCaseId = |
| 77 | testCaseId % armnn::numeric_cast<unsigned int>(g_PerTestCaseInput.size()); |
| 78 | const ObjectDetectionInput& testCaseInput = g_PerTestCaseInput[safeTestCaseId]; |
| 79 | |
| 80 | // Load test case input |
| 81 | const std::string imagePath = m_ImageDir + testCaseInput.first; |
| 82 | std::vector<uint8_t> imageData; |
| 83 | try |
| 84 | { |
| 85 | InferenceTestImage image(imagePath.c_str()); |
| 86 | |
| 87 | // Resize image (if needed) |
| 88 | const unsigned int width = image.GetWidth(); |
| 89 | const unsigned int height = image.GetHeight(); |
| 90 | if (width != k_MobileNetSsdImageWidth || height != k_MobileNetSsdImageHeight) |
| 91 | { |
| 92 | image.Resize(k_MobileNetSsdImageWidth, k_MobileNetSsdImageHeight, CHECK_LOCATION()); |
| 93 | } |
| 94 | |
| 95 | // Get image data as a vector of floats |
| 96 | std::vector<float> floatImageData = GetImageDataAsNormalizedFloats(ImageChannelLayout::Rgb, image); |
| 97 | imageData = armnnUtils::QuantizedVector<uint8_t>(floatImageData, m_Scale, m_Offset); |
| 98 | } |
| 99 | catch (const InferenceTestImageException& e) |
| 100 | { |
| 101 | ARMNN_LOG(fatal) << "Failed to load image for test case " << testCaseId << ". Error: " << e.what(); |
| 102 | return nullptr; |
| 103 | } |
| 104 | |
| 105 | std::vector<float> numDetections = { static_cast<float>(testCaseInput.second.size()) }; |
| 106 | |
| 107 | std::vector<float> detectionBoxes; |
| 108 | std::vector<float> detectionClasses; |
| 109 | std::vector<float> detectionScores; |
| 110 | |
| 111 | for (DetectedObject expectedObject : testCaseInput.second) |
| 112 | { |
| 113 | detectionBoxes.push_back(expectedObject.m_BoundingBox.m_YMin); |
| 114 | detectionBoxes.push_back(expectedObject.m_BoundingBox.m_XMin); |
| 115 | detectionBoxes.push_back(expectedObject.m_BoundingBox.m_YMax); |
| 116 | detectionBoxes.push_back(expectedObject.m_BoundingBox.m_XMax); |
| 117 | |
| 118 | detectionClasses.push_back(expectedObject.m_Class); |
| 119 | |
| 120 | detectionScores.push_back(expectedObject.m_Confidence); |
| 121 | } |
| 122 | |
| 123 | // Prepare test case expected output |
| 124 | std::vector<std::vector<float>> expectedOutputs; |
| 125 | expectedOutputs.reserve(4); |
| 126 | expectedOutputs.push_back(detectionBoxes); |
| 127 | expectedOutputs.push_back(detectionClasses); |
| 128 | expectedOutputs.push_back(detectionScores); |
| 129 | expectedOutputs.push_back(numDetections); |
| 130 | |
| 131 | return std::make_unique<MobileNetSsdTestCaseData>(imageData, testCaseInput.second, expectedOutputs); |