Your computer can also read the world (i)--10 minutes to run the convolutional Neural Network (WINDOWS+CPU)

Source: Internet
Author: User

Study, the use of convolutional neural network has been a long time, the period has been based on the Caffe framework of the Jiayanqing great God to study other people's model, or in the boring time in the same way as the fortune-telling, eyes micro-closed, bobbing, the mouth occasionally leaking a few syllables, a long time DIY out of a think of a lot of models, Then run for a while, of course, the result is very bleak (otherwise I will directly send papers, which have so busy to write blog ...) , from this process, I deeply realized the "walnuts posterity" the correctness of this sentence, although Jiada this predecessor is not much older than me. Today I heard that Jiada announced the latest Caffe framework that can be trained and tested on mobile devices, and thought I knew that something might soon be out of date, and also considering the fact that I always wanted to open a blog loader, so I took the recent study and thought to write it, To be able to write that I insisted on writing a relatively humble CNN framework, because Caishuxueqian, my hope is only to allow non-computer professional students can learn to use this framework, and then perhaps can write a very simple frame of their own, I learn while writing, you look at the side spit groove on the line.

The first article in this series is mainly to introduce the great framework from the application level, and some other tutorials, I introduced this kind of application does not need Linux, do not need the GPU (this will be slower, but the first to run up and then consider how to optimize it, it is important that this will be cheaper), Only need Windows system and CPU, is the real 10 minutes to run the convolutional neural network, I just contact Caffe, in the configuration environment and hardware problems wasted too much time, hope to record, you will not have to detours.

CNN Basics: Https://zhuanlan.zhihu.com/p/22038289?refer=intelligentunit (There should also be some basic knowledge of neural network algorithms, such as Feedforward transfer, BP algorithm, etc. It is also recommended to consolidate this link, the following article will assume that you have a more comprehensive and solid understanding of CNN)

Required system Environment: WINDOWS7 SP1 and above system, Win7 SP1 the following will not have any error I do not know, yes, is a 64-bit system Oh ~

Other environments: Visual Studio 2013,cygwin 2.871 (other versions should also be available, primarily for simulating a very simple Linux environment on a Windows system, because the application will only use some very basic commands, so the earlier version does not matter)

Windows Edition Caffe framework: Https://github.com/Microsoft/caffe

First of all, you need to download the Windows version of the Caffe framework to the local, anywhere down to the line, and then arbitrarily unzip to any of the lines, after I unzip, the Caffe framework is the root directory is H:\caffe-master\caffe-master. After the decompression, we can obviously find that the framework is still an unfinished "raw meat" is not directly used, so we need to use VS2013 to compile it, but before this, there is a step, because we are a small poor force, we do not have tens of thousands of GPU, But Jiada's local tyrants lab has an endless GPU, so the default is the GPU schema framework, which we need to modify, The way to do this is to modify the CommonSettings.props.example file in the Windows folder in the root directory, specifically by:

First, rename the file to Commonsettings.props;

Second, the documents in the

<CpuOnlyBuild>false</CpuOnlyBuild>
<UseCuDNN>true</UseCuDNN>

Switch

<CpuOnlyBuild>true</CpuOnlyBuild>
<UseCuDNN>false</UseCuDNN>

As to what is in this cudnn, then will mention, now do not know ~

Third, save the file.

After changing the framework to CPU mode, you can double-click the Caffe.sln file in the Windows folder and then in VS2013, tap the top-most build, rebuild the solution, and be aware that It's a good idea to change the debug mode to release before doing this, like this.

After a period of compilation, the VS2013 on the lower end of the display will show the success of the information, the framework is compiled, and the resulting executable file Caffe.exe location in the root directory of Build\x64\release, At the same time, there will be a lot of dependencies and a variety of libraries, here you do not care, today's mission will be mainly in contact with Caffe.exe.

After compiling the framework, it can be said to be ready, only the data set and network model, in the first attempt, csdn of the Great God of the use of Yann LeCun the Great God (I used to say into Yang le village god) proposed LENET-5 network model for the Mnist dataset learning is very suitable.

Mnist DataSet is a handwritten digital database, so it is conceivable that the purpose of this training is to let your computer learn to "read the numbers."

Where does the mnist data set get? Caffe frame already for you think of this, so in H:\caffe-master\caffe-master\data\mnist the get_ mnist.sh script is used to help you download this data set, in theory, the operation of this script requires Linux environment support, but we now use the Windows environment, how to do? It's simple, remember what you said before, Cygwin? Yes, just use it! The installation and configuration of the Cygwin can be seen in this http://www.cygwin.cn/site/install/.

Now, you have installed the Cygwin, and has already opened its double-click, just need to enter in this black box, and then return, will automatically download the Mnist data set for you (note, if not FQ is no way to download, recommend I have been using the Psiphon3, the name of a search can be found, You know that).

(Ignoring my Computer name is Celia, using the lab machine, too lazy to change ...) )

At this time, you will find that the Data\mnist folder appears in the

, which means that the Mnist dataset has been successfully downloaded.

So is it possible to use this data set directly? The answer is no. Why is it? As this step, our dataset is just a binary file that needs to be converted to a Lmdb file to be recognized by the Caffe framework, so there is a conversion process, and for Windows users, this conversion is so annoying that I haven't tried it myself. But since I have been using this framework in the Ubuntu system before, we can use the following two methods:

First, in the Ubuntu system, the CD into the root of the Caffe framework, and then only through a simple line of command:

./examples/mnist/create_mnist.sh

Can complete the conversion of the data, then because we do not want to use Ubuntu here, so I recommend the second method.

Second, to find resources online ... The Lmdb file of the Mnist dataset is easy to find on the web, and here I share a copy with my web disk, Http://pan.baidu.com/s/1o86O7Xo.

Assuming you downloaded it from my web disk, now just unzip the downloaded file and put the extracted Mnist_train_lmdb and Mnist_test_lmdb folder into Examples/mnist.

As for the LENET-5 model we used, sharp-eyed's classmates should have found it already in the Examples/mnist folder.

Now that we have the framework, with the data set and with the model, we're almost done. Next, just enter the following in the CMD command line interface that comes with Windows:

Then press ENTER, you are done, just in the black box to keep jumping the text in the process of quietly waiting ... This training time is mainly about the configuration of your computer, which is the state of the training when it is completed:

As you can see, the final rate of correctness has reached a staggering 99.09%, and the loss has dropped to 0.026495. The weights generated after training are also saved in the Lenet_iter_10000.caffemodel in the Mnist folder. At this point, we can test the test set by training a good model. The code required for the test is as follows:

Finally, we can see that the accuracy of the model on the test set has reached an alarming level.

In this way, we can say that your computer succeeded in the birth of a neural network, and your computer has also successfully learned to "know the numbers."

Above, this is what I want to say this time, the above mentioned many different command line, then these command line represents what meaning, the command line refers to the various files what is the meaning of the caffe.exe, what is the use of it? How to modify on the basis of LENET-5 network model, in order to get DIY model? I'll analyze it in detail in the second blog in this series.

Your computer can also read the world (i)--10 minutes to run the convolutional Neural Network (WINDOWS+CPU)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.