MNIST-3LNN  1.0
A simple 3-layer neural network to recognize handwritten single digit numbers from the MNIST image files.
mnist-utils.h
Go to the documentation of this file.
1 /**
2  * @file mnist-utils.h
3  * @brief Utitlies for handling the MNIST files
4  * @see http://yann.lecun.com/exdb/mnist/
5  * @author Matt Lind
6  * @date July 2015
7  */
8 
9 #include <stdint.h>
10 #include <stdio.h>
11 
12 
13 #define MNIST_TRAINING_SET_IMAGE_FILE_NAME "data/train-images-idx3-ubyte" ///< MNIST image training file in the data folder
14 #define MNIST_TRAINING_SET_LABEL_FILE_NAME "data/train-labels-idx1-ubyte" ///< MNIST label training file in the data folder
15 
16 #define MNIST_TESTING_SET_IMAGE_FILE_NAME "data/t10k-images-idx3-ubyte" ///< MNIST image testing file in the data folder
17 #define MNIST_TESTING_SET_LABEL_FILE_NAME "data/t10k-labels-idx1-ubyte" ///< MNIST label testing file in the data folder
18 
19 
20 
21 #define MNIST_MAX_TRAINING_IMAGES 60000 ///< number of images+labels in the TRAIN file/s
22 #define MNIST_MAX_TESTING_IMAGES 10000 ///< number of images+labels in the TEST file/s
23 #define MNIST_IMG_WIDTH 28 ///< image width in pixel
24 #define MNIST_IMG_HEIGHT 28 ///< image height in pixel
25 
26 
27 
30 
31 typedef struct MNIST_Image MNIST_Image;
32 typedef uint8_t MNIST_Label;
33 
34 
35 
36 /**
37  * @brief Data block defining a MNIST image
38  * @see http://yann.lecun.com/exdb/mnist/ for details
39  */
40 struct MNIST_Image{
42 };
43 
44 
45 
46 
47 /**
48  * @brief Data block defining a MNIST image file header
49  * @attention The fields in this structure are not used.
50  * What matters is their byte size to move the file pointer
51  * to the first image.
52  * @see http://yann.lecun.com/exdb/mnist/ for details
53  */
54 
56  uint32_t magicNumber;
57  uint32_t maxImages;
58  uint32_t imgWidth;
59  uint32_t imgHeight;
60 };
61 
62 
63 
64 
65 /**
66  * @brief Data block defining a MNIST label file header
67  * @attention The fields in this structure are not used.
68  * What matters is their byte size to move the file pointer
69  * to the first label.
70  * @see http://yann.lecun.com/exdb/mnist/ for details
71  */
72 
74  uint32_t magicNumber;
75  uint32_t maxImages;
76 };
77 
78 
79 
80 
81 /**
82  * @brief Read MNIST IMAGE file header
83  * @see http://yann.lecun.com/exdb/mnist/ for definition details
84  */
85 
86 FILE *openMNISTImageFile(char *fileName);
87 
88 
89 
90 
91 /**
92  * @brief Read MNIST label file header
93  * @see http://yann.lecun.com/exdb/mnist/ for definition details
94  */
95 
96 FILE *openMNISTLabelFile(char *fileName);
97 
98 
99 
100 /**
101  * @brief Returns the next image in given MNIST image file
102  */
103 
104 MNIST_Image getImage(FILE *imageFile);
105 
106 
107 
108 
109 /**
110  * @brief Returns the next label in given MNIST label file
111  */
112 
113 MNIST_Label getLabel(FILE *labelFile);
114 
115 
116 
117 
118 
119 
120 
121 
122 
123 
124 
125 int getStandardDigitPixel(int num, int pixelId);
uint8_t pixel[MNIST_IMG_WIDTH *MNIST_IMG_HEIGHT]
Definition: mnist-utils.h:41
int getStandardDigitPixel(int num, int pixelId)
Definition: mnist-utils.c:178
FILE * openMNISTLabelFile(char *fileName)
Read MNIST label file header.
Definition: mnist-utils.c:117
#define MNIST_IMG_HEIGHT
image height in pixel
Definition: mnist-utils.h:24
Data block defining a MNIST image file header.
Definition: mnist-utils.h:55
Data block defining a MNIST label file header.
Definition: mnist-utils.h:73
#define MNIST_IMG_WIDTH
image width in pixel
Definition: mnist-utils.h:23
MNIST_Image getImage(FILE *imageFile)
Returns the next image in given MNIST image file.
Definition: mnist-utils.c:139
MNIST_Label getLabel(FILE *labelFile)
Returns the next label in given MNIST label file.
Definition: mnist-utils.c:159
FILE * openMNISTImageFile(char *fileName)
Read MNIST IMAGE file header.
Definition: mnist-utils.c:93
Data block defining a MNIST image.
Definition: mnist-utils.h:40
uint8_t MNIST_Label
Definition: mnist-utils.h:32