MNIST-1LNN  1.0
A simple 1-layer neural network to recognize handwritten single digit numbers from the MNIST image files.
mnist-stats.c
Go to the documentation of this file.
1 /**
2  * @file mnist-stats.c
3  * @brief Utitlies for displaying processing details in the terminal
4  * @author Matt Lind
5  * @date July 2015
6  */
7 
8 #include <string.h>
9 
10 #include "screen.h"
11 #include "mnist-utils.h"
12 #include "mnist-stats.h"
13 
14 
15 
16 
17 /**
18  * @details Outputs a 28x28 text frame at a defined screen position
19  */
20 
21 void displayImageFrame(int row, int col){
22 
23  if (col!=0 && row!=0) locateCursor(row, col);
24 
25  printf("------------------------------\n");
26 
27  for (int i=0; i<MNIST_IMG_HEIGHT; i++){
28  for (int o=0; o<col-1; o++) printf(" ");
29  printf("| |\n");
30  }
31 
32  for (int o=0; o<col-1; o++) printf(" ");
33  printf("------------------------------");
34 
35 }
36 
37 
38 
39 
40 /**
41  * @details Outputs a 28x28 MNIST image as charachters ("."s and "X"s)
42  */
43 
44 void displayImage(MNIST_Image *img, int row, int col){
45 
46  char imgStr[(MNIST_IMG_HEIGHT * MNIST_IMG_WIDTH)+((col+1)*MNIST_IMG_HEIGHT)+1];
47  strcpy(imgStr, "");
48 
49  for (int y=0; y<MNIST_IMG_HEIGHT; y++){
50 
51  for (int o=0; o<col-2; o++) strcat(imgStr," ");
52  strcat(imgStr,"|");
53 
54  for (int x=0; x<MNIST_IMG_WIDTH; x++){
55  strcat(imgStr, img->pixel[y*MNIST_IMG_HEIGHT+x] ? "X" : "." );
56  }
57  strcat(imgStr,"\n");
58  }
59 
60  if (col!=0 && row!=0) locateCursor(row, 0);
61  printf("%s",imgStr);
62 }
63 
64 
65 
66 
67 /**
68  * @details Outputs reading progress while processing MNIST training images
69  */
70 
71 void displayLoadingProgressTraining(int imgCount, int y, int x){
72 
73  float progress = (float)(imgCount+1)/(float)(MNIST_MAX_TRAINING_IMAGES)*100;
74 
75  if (x!=0 && y!=0) locateCursor(y, x);
76 
77  printf("1: TRAINING: Reading image No. %5d of %5d images [%d%%]",(imgCount+1),MNIST_MAX_TRAINING_IMAGES,(int)progress);
78 
79 }
80 
81 
82 
83 
84 /**
85  * @details Outputs reading progress while processing MNIST testing images
86  */
87 
88 void displayLoadingProgressTesting(int imgCount, int y, int x){
89 
90  float progress = (float)(imgCount+1)/(float)(MNIST_MAX_TESTING_IMAGES)*100;
91 
92  if (x!=0 && y!=0) locateCursor(y, x);
93 
94  printf("2: TESTING: Reading image No. %5d of %5d images [%d%%]\n ",(imgCount+1),MNIST_MAX_TESTING_IMAGES,(int)progress);
95 
96 }
97 
98 
99 
100 
101 /**
102  * @details Outputs image recognition progress and error count
103  */
104 
105 void displayProgress(int imgCount, int errCount, int y, int x){
106 
107  double successRate = 1 - ((double)errCount/(double)(imgCount+1));
108 
109  if (x!=0 && y!=0) locateCursor(y, x);
110 
111  printf("Result: Correct=%5d Incorrect=%5d Success-Rate=%5.2f%% \n",imgCount+1-errCount, errCount, successRate*100);
112 
113 
114 }
115 
void displayProgress(int imgCount, int errCount, int y, int x)
Outputs image recognition progress and error count.
Definition: mnist-stats.c:105
Utitlies for displaying processing details in the terminal.
uint8_t pixel[28 *28]
Definition: mnist-utils.h:41
void displayLoadingProgressTesting(int imgCount, int y, int x)
Outputs reading progress while processing MNIST testing images.
Definition: mnist-stats.c:88
Utitlies for advanced input and output to terminal screen.
void displayLoadingProgressTraining(int imgCount, int y, int x)
Outputs reading progress while processing MNIST training images.
Definition: mnist-stats.c:71
#define MNIST_MAX_TESTING_IMAGES
number of images+labels in the TEST file/s
Definition: mnist-utils.h:22
void locateCursor(const int row, const int col)
Set cursor position to given coordinates in the terminal window.
Definition: screen.c:57
#define MNIST_IMG_HEIGHT
image height in pixel
Definition: mnist-utils.h:24
#define MNIST_IMG_WIDTH
image width in pixel
Definition: mnist-utils.h:23
void displayImageFrame(int row, int col)
Outputs a 28x28 text frame at a defined screen position.
Definition: mnist-stats.c:21
void displayImage(MNIST_Image *img, int row, int col)
Outputs a 28x28 MNIST image as charachters ("."s and "X"s)
Definition: mnist-stats.c:44
Utitlies for handling the MNIST files.
Data block defining a MNIST image.
Definition: mnist-utils.h:40
#define MNIST_MAX_TRAINING_IMAGES
number of images+labels in the TRAIN file/s
Definition: mnist-utils.h:21