49 FILE *imageFile, *labelFile;
81 if (predictedNum!=lbl) errCount++;
83 printf(
"\n Prediction: %d Actual: %d ",predictedNum, lbl);
107 FILE *imageFile, *labelFile;
139 if (predictedNum!=lbl) errCount++;
141 printf(
"\n Prediction: %d Actual: %d ",predictedNum, lbl);
161 int main(
int argc,
const char * argv[]) {
164 time_t startTime = time(NULL);
168 printf(
" MNIST-1LNN: a simple 1-layer neural network processing the MNIST handwriting images\n");
180 time_t endTime = time(NULL);
181 double executionTime = difftime(endTime, startTime);
182 printf(
"\n DONE! Total execution time: %.1f sec\n\n",executionTime);
void displayProgress(int imgCount, int errCount, int y, int x)
Outputs image recognition progress and error count.
Cell cell[NUMBER_OF_OUTPUT_CELLS]
Data structure containing defined number of integer values (the output vector contains values for 0-9...
#define MNIST_TRAINING_SET_IMAGE_FILE_NAME
MNIST image training file in the data folder.
Utitlies for displaying processing details in the terminal.
Vector getTargetOutput(int targetIndex)
Returns an output vector with targetIndex set to 1, all others to 0.
FILE * openMNISTImageFile(char *fileName)
Read MNIST IMAGE file header.
int main(int argc, const char *argv[])
void displayLoadingProgressTesting(int imgCount, int y, int x)
Outputs reading progress while processing MNIST testing images.
#define MNIST_TESTING_SET_LABEL_FILE_NAME
MNIST label testing file in the data folder.
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.
void trainLayer(Layer *l)
void testCell(Cell *c, MNIST_Image *img, int target)
Performs the testing of the trained network.
FILE * openMNISTLabelFile(char *fileName)
Read MNIST label file header.
MNIST_Label getLabel(FILE *labelFile)
Returns the next label in given MNIST label file.
#define MNIST_TRAINING_SET_LABEL_FILE_NAME
MNIST label training file in the data folder.
#define MNIST_MAX_TESTING_IMAGES
number of images+labels in the TEST file/s
void locateCursor(const int row, const int col)
Set cursor position to given coordinates in the terminal window.
#define NUMBER_OF_OUTPUT_CELLS
use 10 output cells to model 10 digits (0-9)
Machine learning functionality for a 1-layer neural network.
void clearScreen()
Clear terminal screen by printing an escape sequence.
The single (output) layer of this network (a layer is number cells)
void displayImageFrame(int row, int col)
Outputs a 28x28 text frame at a defined screen position.
#define MNIST_TESTING_SET_IMAGE_FILE_NAME
MNIST image testing file in the data folder.
int val[NUMBER_OF_OUTPUT_CELLS]
void displayImage(MNIST_Image *img, int row, int col)
Outputs a 28x28 MNIST image as charachters ("."s and "X"s)
void trainCell(Cell *c, MNIST_Image *img, int target)
Performs the training algorithm.
void initLayer(Layer *l)
Initialize layer by setting all weights to random values [0-1].
Utitlies for handling the MNIST files.
MNIST_Image getImage(FILE *imageFile)
Returns the next image in given MNIST image file.
int getLayerPrediction(Layer *l)
Returns the index of the cell with the hightest output.
Data block defining a MNIST image.
#define MNIST_MAX_TRAINING_IMAGES
number of images+labels in the TRAIN file/s