28 unsigned int label = 0;
30 std::string imagePath = m_BinaryDirectory + std::string(
"t10k-images.idx3-ubyte");
31 std::string labelPath = m_BinaryDirectory + std::string(
"t10k-labels.idx1-ubyte");
33 std::ifstream imageStream(imagePath, std::ios::binary);
34 std::ifstream labelStream(labelPath, std::ios::binary);
36 if (!imageStream.is_open())
38 ARMNN_LOG(fatal) <<
"Failed to load " << imagePath;
41 if (!labelStream.is_open())
43 ARMNN_LOG(fatal) <<
"Failed to load " << imagePath;
47 unsigned int magic, num, row, col;
50 imageStream.read(reinterpret_cast<char*>(&magic),
sizeof(magic));
51 if (magic != 0x03080000)
53 ARMNN_LOG(fatal) <<
"Failed to read " << imagePath;
56 labelStream.read(reinterpret_cast<char*>(&magic),
sizeof(magic));
57 if (magic != 0x01080000)
59 ARMNN_LOG(fatal) <<
"Failed to read " << labelPath;
65 labelStream.read(reinterpret_cast<char*>(&num),
sizeof(num));
66 imageStream.read(reinterpret_cast<char*>(&num),
sizeof(num));
68 imageStream.read(reinterpret_cast<char*>(&row),
sizeof(row));
70 imageStream.read(reinterpret_cast<char*>(&col),
sizeof(col));
75 imageStream.read(reinterpret_cast<char*>(&I[0]), g_kMnistImageByteSize);
76 labelStream.seekg(testCaseId, std::ios_base::cur);
77 labelStream.read(reinterpret_cast<char*>(&label), 1);
79 if (!imageStream.good())
81 ARMNN_LOG(fatal) <<
"Failed to read " << imagePath;
84 if (!labelStream.good())
86 ARMNN_LOG(fatal) <<
"Failed to read " << labelPath;
90 std::vector<float> inputImageData;
91 inputImageData.resize(g_kMnistImageByteSize);
93 for (
unsigned int i = 0; i < col * row; ++i)
96 inputImageData[i] =
static_cast<float>(I[i]);
100 inputImageData[i] /= 255.0f;
104 return std::make_unique<TTestCaseData>(label, std::move(inputImageData));
void EndianSwap(unsigned int &x)
#define ARMNN_LOG(severity)
constexpr int g_kMnistImageByteSize