(v) How to use the Mnist database in a disorderly way
Today, I spent a whole day checking all kinds of information and finally figuring out how to use the Mnist database. Haha, MNIST, is not high-end foreign flavor on the grade? Don't you know what it is?
Mnist is a supposedly well-known handwritten digital database, which is said to be handwritten figures of American middle school students, and most of the truth is written quite ugly ... Anyway, fortunately can understand is which number. The topic now is to use the CNN (convolutional neural network) to identify the number of this database. I think CNN really does not understand, but first figure out how to read into the database bar, otherwise there is no real theory can not be drilled. The average person will use MATLAB to do the neural network of East, and I was a general person. Of course, non-ordinary people may use the high-end platform such as Python, anyway, I will not ... First on the search engine, whether it is Baidu or Google, search "MNIST" the first out of the affirmation is http://yann.lecun.com/exdb/mnist/ Yes, it is! This page has four compressed package links, download it down, Junior! Then don't be too busy turning off the page, because the data you read later depends on the description of the page. Here is an example of one of the packages t10k-images_idx3, which describes how to use this database. This is from verysource.com above download source code, likes one! and praise one! The% matlab_read_t10k-images_idx3.m% is used to read the T10k-images.idx3-ubyte files in the mnist dataset and convert them into BMP format picture output. % Usage: Run program, will pop up select test picture Data File t10k-labels.idx1-ubyte Path dialog box and% Select Save test Picture Path dialog box, select Path after the program automatically run, the progress bar will show processing progress. The% picture is saved in testimage_00001.bmp~testimage_10000.bmp format in the specified path, 10,000 files occupy 39M of space. % The entire program takes a few minutes to run. % written by [email protected] iprai% 2009-2-22clear all;clc;% Read training picture data file [Filename,pathname] = Uigetfile (' *. * ', ' Select test picture data File T10k-images.idx3-ubyte '); Trainfile = FullFile (pathname,filename); fid = fopen (trainfile, ' R '); %fopen () is the most core function, the import file, ' R ' represents the read-In a = Fread (fid,16, ' uint8 '); % here is to note that the first 16 bits of the package are descriptive information, from the page mentioned aboveYou can see what the specific person means. So a variable extracts this information and records it to facilitate the subsequent creation of a matrix and other actions. Magicnum = ((A (1) *256+a (2)) *256+a (3)) *256+a (4); imagenum = ((A (5) *256+a (6)) *256+a (7)) *256+a (8); Imagerow = ((A (9) *256+ A ()) *256+a (one)) *256+a (a), Imagecol = ((A (d) *256+a (+)) *256+a (16);% from the page mentioned above can understand the four sentences if (*256+a 2051) | | (imagenum~=10000)) error (' Not MNIST t10k-images.idx3-ubyte file! '); fclose (FID); return; end% Exclusion Select the wrong file. Savedirectory = Uigetdir (', ' Select test picture path: '); h_w = Waitbar (0, ' Please wait, process in >> '); for i=1:imagenum b = fread (Fid,imagerow*imagecol, ' uint8 '); %fread () is also one of the core functions, B records the data string of a graph. Note that this is still a string, is not see any clues. c = Reshape (B,[imagerow imagecol]); % highlights came, reshape re-form the matrix, and finally turned the string over. Well-known picture is The matrix, here reshape out of the gray matrix is the handwritten number of the matrix. d = C '; % transpose, because the number of C is sideways ... e = 255-d; % according to the gray scale theory, 0 is black, 255 is white, in order to make white bottom black word added e e = uint8 (e); &Nbsp; savepath = fullfile (savedirectory,[' Testimage_ ' num2str (i, ' d ') '. bmp]); Imwrite (E,savepath, ' bmp '); % finally write the picture waitbar (I/imagenum) with Imwrite, Endfclose (FID), close (H_w); in the chosen path, There's a whole bunch of pictures of mnist handwritten numbers. If you want to get one, use Imread () to get it! With this, believe my small topic soon has fallen, hey. So, fifth, probably, that's it ...
(v) How to use the Mnist database in a disorderly way