MNIST-3LNN  1.0
A simple 3-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("------------------------------\n");
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 lbl, int cls, 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  printf(" Label:%d Classification:%d\n\n",lbl,cls);
64 
65 }
66 
67 
68 
69 
70 /**
71  * @details Outputs reading progress while processing MNIST training images
72  */
73 
74 void displayTrainingProgress(int imgCount, int errCount, int y, int x){
75 
76  double progress = (double)(imgCount+1)/(double)(MNIST_MAX_TRAINING_IMAGES)*100;
77 
78  if (x!=0 && y!=0) locateCursor(y, x);
79 
80  printf("1: TRAINING: Reading image No. %5d of %5d images [%3d%%] ",(imgCount+1),MNIST_MAX_TRAINING_IMAGES,(int)progress);
81 
82 
83  double accuracy = 1 - ((double)errCount/(double)(imgCount+1));
84 
85  printf("Result: Correct=%5d Incorrect=%5d Accuracy=%5.4f%% \n",imgCount+1-errCount, errCount, accuracy*100);
86 
87 }
88 
89 
90 
91 void displayTestingProgress(int imgCount, int errCount, int y, int x){
92 
93  double progress = (double)(imgCount+1)/(double)(MNIST_MAX_TESTING_IMAGES)*100;
94 
95  if (x!=0 && y!=0) locateCursor(y, x);
96 
97  printf("2: TESTING: Reading image No. %5d of %5d images [%3d%%] ",(imgCount+1),MNIST_MAX_TESTING_IMAGES,(int)progress);
98 
99 
100  double accuracy = 1 - ((double)errCount/(double)(imgCount+1));
101 
102  printf("Result: Correct=%5d Incorrect=%5d Accuracy=%5.4f%% \n",imgCount+1-errCount, errCount, accuracy*100);
103 
104 }
105 
106 
107 
108 
109 
void displayImage(MNIST_Image *img, int lbl, int cls, int row, int col)
Outputs a 28x28 MNIST image as charachters ("."s and "X"s)
Definition: mnist-stats.c:44
Utitlies for displaying processing details in the terminal.
uint8_t pixel[MNIST_IMG_WIDTH *MNIST_IMG_HEIGHT]
Definition: mnist-utils.h:41
void displayTrainingProgress(int imgCount, int errCount, int y, int x)
Outputs reading progress while processing MNIST training images.
Definition: mnist-stats.c:74
Utitlies for advanced input and output to terminal screen.
#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
Utitlies for handling the MNIST files.
void displayTestingProgress(int imgCount, int errCount, int y, int x)
Definition: mnist-stats.c:91
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