MCPcopy Create free account
hub / github.com/ROCm/AMDMIGraphX / read_nth_digit

Function read_nth_digit

examples/vision/cpp_mnist/mnist_inference.cpp:177–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

175}
176
177void read_nth_digit(const int n, std::vector<float>& digit)
178{
179 const std::string SYMBOLS = "@0#%=+*-. ";
180 std::ifstream file("../digits.txt");
181 const int DIGITS = 10;
182 const int HEIGHT = 28;
183 const int WIDTH = 28;
184
185 if(not file.is_open())
186 {
187 return;
188 }
189
190 for(int d = 0; d < DIGITS; ++d)
191 {
192 for(int i = 0; i < HEIGHT * WIDTH; ++i)
193 {
194 unsigned char temp = 0;
195 file.read(reinterpret_cast<char*>(&temp), sizeof(temp));
196 if(d == n)
197 {
198 float data = temp / 255.0;
199 digit.push_back(data);
200 std::cout << SYMBOLS[static_cast<int>(data * 10) % 11];
201 if((i + 1) % WIDTH == 0)
202 std::cout << std::endl;
203 }
204 }
205 }
206 std::cout << std::endl;
207}

Callers 1

mainFunction · 0.85

Calls 2

readMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected