What we are doing in the image processing training. We are storing some form of data which is going to act as the knowledge or experience of the system.

  • In which form can the system store it's training data?

For example, with the hand written recognition, we can represent the digits as combinations of curves and straight lines. For every round of training the recognition system stores data. Is the data typically stored in a flat file (such as txt) or a database?

I have seen in Tesseract OCR that there is a text file that stores the x0,y0,x1,y1. They are the pixel points that represents the square on the training image that has the picture.

I need a efficient form of knowledge for Machine Learning, and would appreciate advice, context, or an explanation of the merits or downsides of different approaches.

I need a form of knowledge that stored in a system. human brain evaluate '7' as 'horizontal line and vertical left crossed line start from right of the horizontal line'. like that machine must have some conceptual data to represent their knowledge.

  • 1
    $\begingroup$ Welcome to AI! I took the liberty of editing the question for greater readibility—don't hesitate to let me know if I've misrepresented anything. It might be helpful if you indicated what language you're planning on working in, and possibly the system architecture you envision. (Data is data, but the way you store it may be influenced by these factors.) $\endgroup$
    – DukeZhou
    Aug 26, 2017 at 5:56

2 Answers 2


Your question depends heavily on the method you are using for machine learning. It sounds like you want to extract certain features like "curves and straight lines" from your images and use them as training data. This step of extraction is usually not considered part of the training process but part of pre-processing. During pre-precessing you read your image in, extract certain features or perform some transformation and store the new data as your actual training samples or use them for training right away without intermediate storage. Usually storing this information is a good idea if you want to use the image for training more than once and you want to skip the pre-processing step in future training cycles.

Comparing File Storage and Database Storage

How you store your processed data for training is relatively independent from the application of machine learning and the general principles for data storage apply. Storing the data in a flat file is usually very convenient as disk storage is readily available and the APIs for storing and reading files are part of your programming language and OS. A database adds additional complexity to your architecture but has of course it's benefits, especially if you want to make the training data available to other instances or different learning engines. If you are working with a really huge amount of data, a well structured database can help you organize your data better and provides helpful functions for handling this data efficiently.

Keep in mind that the actual training of your AI takes place initially and once completed, you can roll out your AI without all the training data. So you only need to handle training data for a limited time in your application lifecycle. The speed of training is usually not very important, because it happens once and not during the daily use of the AI. Therefore the speed of file access during training can be neglected.


In conclusion, for most applications, the simpler implementation using just flat files is good enough. If you want to store each sample in an individual file or pack them together on bigger batches and use some meta information to identify the individual samples in the file is more a matter of taste than real technical relevance.

Storing data after training

Judging from your question, you sound like you understand machine learning in general. Just to clarify one potential misunderstanding for beginners - you don't have to store any of the "learned" information as data after training, as each training step just adapts weights and biases in the neural network. The actual training data can be thrown away after successful training, if you don't need it for future training cycles.

Further Information / References

To finish my answer I want to recommend a current course from Stanford University about CNNs and visual recognition (Dated Spring 2017). It is a great source of information for implementing neural networks for image recognition.

  • $\begingroup$ asking again. if we input a image as a training input, then that is a direct knowledge of machine. may be my question is not clear $\endgroup$ Aug 29, 2017 at 5:01
  • $\begingroup$ I need a form of knowledge that stored in a system. human brain evaluate '7' as 'horizontal line and vertical left crossed line start from right of the horizontal line'. like that machine must have some conceptual data to represent their knowledge. $\endgroup$ Aug 29, 2017 at 5:05
  • $\begingroup$ With a NN, that is not necessarily the case. The added knowledge manifests itself as small adaptions in the weights and biases of the neurons. There is nothing like a lookup table for the knowledge. When using a CNN there are some "intermediate templates" for each class, which sounds like what you are looking for. Please take a look at the Stanford course I linked for more details. The templates get explained in detail starting in the 5th lecture. $\endgroup$
    – Demento
    Aug 29, 2017 at 5:46
  • $\begingroup$ perfect, I'm really considering this as wow fact. that the system will increase it's ability on day my day work. answer was very clear. thank you. $\endgroup$ Aug 29, 2017 at 6:04

I think Demento has answered it well, but probably below can add some more understanding to you.

[1] Usually the data stored for image processing relates to the Image Pixel Densities(as per the many courses i visited online), which can be very well maintained using a matrix of pixel density values, corresponding to the resolution of each image. Then it depends on the image's color spectrum (is it a colored or a gray scale); as per the case of hand written text recognition you don't really require the pixel values for a colored image.

Consider that if you have a colored image then you have to store the RGB values for each pixel, thus tripling the matrix size, and the training could be very well done with just the gray scale values, thus it would be better to convert all the images to gray scale in preprocessing step and also take care to convert the image to gray scale when you actually use the trained network to recognize an image (just a novice mistake!).

As per the storage for the required matrix form of the pixel density values, a flat file storage would suffice, but I would recommend libraries instead (if working in python or other alternatives), like pandas and numpy. For these libraries provide a robust solution for data management and retrieval.

For more details - https://docs.scipy.org/doc/numpy-dev/user/quickstart.html https://github.com/pandas-dev/pandas

[2] Now I would emphasize on why not to use any DataBase(DB) for the storage of such information. Firstly the integration of it would only result in an unnecessary overhead to your efforts of training the Network and also when you would want to recognize an image(which would always be a single matrix form of it's Image Pixel Densities), you would require the connection to the same DB and would also need to make an insertion to it first, for the script to be able to extract from there and make recognition(not recomended).

There is a fact we don't really concern ourselves with is the quality of the training image dataset, we do ignore the presence of noise in the dataset(would be minimum if using a preprocessed standard data set such MNIST http://yann.lecun.com/exdb/mnist/), but if creating one's own data set we have to consider noise and rectify accordingly in the preprocessing task itself.

With noise I mean loss or overlap of pixel density information which is usually adds a blurring effect to the images, and can seriously damage the training metrics. To overcome it, there are approaches to rectify the pixel values with a prior learning methods such as extracting data from obfuscated images, see link- https://arxiv.org/pdf/1609.00408.pdf.

With the above case you would require to make updates in the DB for very single record in the preprocessing task even before you start to train the Network, thus it can increase the total requests to the DB in multifolds and thus impeding the whole benefit of using it in the first place.

I suppose the above should give you fair idea, about the kind of data to store and the Data Storage to prefer accordingly. I worked out the Digit Classification using MNIST data set with obscuration using a NN Pipeline, to refer https://github.com/kchopra456/Digit-Classification-and-Image-Obfuscation-ANN.

  • $\begingroup$ thank you for your response, I really admit your justification for 'no storage'. let consider the image of '1'(digit). I have 3 images in size respectively 234kb,2mb,65kb. I trained my system with this data. now I am not really wish to store the 234+2048+65 of kb of data. instead of this a vector representation data that emphasize strecture of '1'. that data will be improved by the next trainning. $\endgroup$ Sep 5, 2017 at 6:49
  • $\begingroup$ like us. we know the structure of alphabets by the training of the view we seen in childhood. But we are not having the data about which color and which scale (in books). $\endgroup$ Sep 5, 2017 at 6:53
  • $\begingroup$ is it possible to store that kind of data. is there exists any data structure for that $\endgroup$ Sep 5, 2017 at 6:54
  • 1
    $\begingroup$ From my understanding till now, you want to train the network not by pixel densities as a direct classifier but rather using a figurative vector scale(some knowledge about how we draw that character on paper). I'm not sure about the feasibility of that, but i would like to point out something I feel that can get you in a bottleneck. You mention that you want to use the vector representation achieved after each learning iteration to modify the input data set for the next iteration! This might not be a good approach because the intermediate data set is guaranteed to have a lot of noise. $\endgroup$ Sep 5, 2017 at 8:15
  • $\begingroup$ Also about the varying sizes of images as Input Data Set, can be handled easily in preprocessing. You can easily compress the images to suitable size, because we don't really require high scale images for character classification; as not much detail is required in an image to represent a character. Go for gray scale images for about 400 pixel size and your network will work miracles!, even though you wan to test on a real world image that would be of much higher resolution; you can just take the image through the preprocessing task and then classify. $\endgroup$ Sep 5, 2017 at 8:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .