9 #include <boost/numeric/conversion/cast.hpp> 10 #include <boost/assert.hpp> 18 x = (x >> 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | (x << 24);
22 : m_BinaryDirectory(binaryFileDirectory)
23 , m_ScaleValues(scaleValues)
30 unsigned int label = 0;
32 std::string imagePath = m_BinaryDirectory + std::string(
"t10k-images.idx3-ubyte");
33 std::string labelPath = m_BinaryDirectory + std::string(
"t10k-labels.idx1-ubyte");
35 std::ifstream imageStream(imagePath, std::ios::binary);
36 std::ifstream labelStream(labelPath, std::ios::binary);
38 if (!imageStream.is_open())
40 ARMNN_LOG(fatal) <<
"Failed to load " << imagePath;
43 if (!labelStream.is_open())
45 ARMNN_LOG(fatal) <<
"Failed to load " << imagePath;
49 unsigned int magic, num, row, col;
52 imageStream.read(reinterpret_cast<char*>(&magic),
sizeof(magic));
53 if (magic != 0x03080000)
55 ARMNN_LOG(fatal) <<
"Failed to read " << imagePath;
58 labelStream.read(reinterpret_cast<char*>(&magic),
sizeof(magic));
59 if (magic != 0x01080000)
61 ARMNN_LOG(fatal) <<
"Failed to read " << labelPath;
67 labelStream.read(reinterpret_cast<char*>(&num),
sizeof(num));
68 imageStream.read(reinterpret_cast<char*>(&num),
sizeof(num));
70 imageStream.read(reinterpret_cast<char*>(&row),
sizeof(row));
72 imageStream.read(reinterpret_cast<char*>(&col),
sizeof(col));
77 imageStream.read(reinterpret_cast<char*>(&I[0]), g_kMnistImageByteSize);
78 labelStream.seekg(testCaseId, std::ios_base::cur);
79 labelStream.read(reinterpret_cast<char*>(&label), 1);
81 if (!imageStream.good())
83 ARMNN_LOG(fatal) <<
"Failed to read " << imagePath;
86 if (!labelStream.good())
88 ARMNN_LOG(fatal) <<
"Failed to read " << labelPath;
92 std::vector<float> inputImageData;
93 inputImageData.resize(g_kMnistImageByteSize);
95 for (
unsigned int i = 0; i < col * row; ++i)
101 inputImageData[i] /= 255.0f;
105 return std::make_unique<TTestCaseData>(label, std::move(inputImageData));
std::unique_ptr< TTestCaseData > GetTestCaseData(unsigned int testCaseId)
void EndianSwap(unsigned int &x)
MnistDatabase(const std::string &binaryFileDirectory, bool scaleValues=false)
#define ARMNN_LOG(severity)
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
constexpr int g_kMnistImageByteSize