ubuntu14.04+caffe+cuda7.5 Environment Building and training and testing of mnist data sets

Source: Internet
Author: User
Tags intel mkl gtx

Ubuntu14.04+caffe+cuda Environment Building and training and testing of mnist data sets

First, the installation of ubuntu14.04:

  Ubuntu installation is a very simple thing, here is a reference tutorial:

Http://jingyan.baidu.com/article/76a7e409bea83efc3b6e1507.html

Second, the installation of Cuda:

1, first download NVIDIA CUDA warehouse installation package (my is Ubuntu 14.04 64 bit, so download is ubuntu14.04 installation package, if you are 32 bit can see the specific address, the specific address is https:// Developer.nvidia.com/cuda-downloads)

wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1404/x86_64/ Cuda-repo-ubuntu1404_6.5-14_amd64.deb

After the download is complete, you can install it using the following command, noting that the file name is modified to Cuda-repo-ubuntu1404_6.5-14_amd64.deb:

sudo dpkg-i cuda-repo-<distro>_<version>_<architecture>.deb  

2, after the installation of the warehouse, you can update your local warehouse.

Finally, the installation of Cuda and the graphics driver (the installation of Cuda at the same time the graphics card driver is also installed, this is really convenient.) But the download time is a bit long. )

sudo apt-get install Cuda  

3. After installation you need to set environment variables:

$ export Path=/usr/local/cuda-6.5/bin:$PATH  $ export Ld_library_path=/usr/local/cuda-6.5/ LIB64:$LD _library_path

4. After Setup, you can also choose whether to install the sample code included with Cuda (<dir> indicates the location you want to install, you can replace <dir> with ~) and compile it:

$ cuda-install-samples-6.5.sh <dir>  
CD ~/nvidia_cuda-6.5_samples

Then go to the Bin directory and run Devicequery

CD ~/nvidia_cuda-6.5_samples/./devicequery

If the following graphics card information appears, the driver and the video card installation is successful:

./devicequery starting ...CUDA Device Query (Runtime API) version (CudartStaticlinking) Detected1CUDA capable device (s) device0: "GeForce GTX 670"CUDA Driver Version/Runtime Version 6.5/6.5CUDA Capability Major/minor version Number: 3.0Total amount ofGlobalmemory:4095 MBytes (4294246400bytes) ( 7) Multiprocessors, (192) CUDA cores/mp:1344CUDA cores GPU Clock rate: 1098 MHz (1.10GHz) Memory Clock Rate: 3105Mhz Memory Bus Width: 256-bit L2 Cache Size: 524288bytes Maximum Texture Dimension Size (x, y,z) 1d= (65536), 2d= (65536, 65536), 3d= (4096, 4096, 4096) Maximum layered 1D Texture Size, (num) layers 1d= (16384), 2048layers Maximum Layered 2D Texture Size, (num) layers 2d= (16384, 16384), 2048layers Total Amount ofconstantmemory:65536Bytes Total amount of shared memory per block: 49152bytes Total Numberof registers available per block:65536Warp Size: 32Maximum Numberof threads per multiprocessor:2048Maximum Numberof threads per block:1024MaxDimension size of a thread block (x, Y, z): (1024, 1024, 64)  MaxDimension size of a grid size (x, Y, z): (2147483647, 65535, 65535) Maximum Memory pitch: 2147483647bytes Texture Alignment: 512bytes ConcurrentCopyand kernel Execution:yes with 1Copyengine (s) Run TimeLimit on kernels:Yes Integrated GPU sharing Host Memory:No Support Host page-locked Memory Mapping:Yes Alignment Requirement forSurfaces:Yes Device has ECC support:Disabled Device supports Unified Addressing (UVA):Yes Device PCI Bus ID/PCI location Id:1/0Compute Mode: <Default(Multiple host threads can Use:: Cudasetdevice () with device simultaneously) >Devicequery, Cuda Driver = Cudart, cuda Driver Version = 6.5, cuda Runtime Version = 6.5, Numdevs = 1, Device0 = GeForce GTX 670Result= PASS

The specific installation process can be consulted in English.

Http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-linux/index.html

Third, installation OpenCV:

Try not to install it manually, and someone on GitHub has already written the full installation script: Https://github.com/jayrambhia/Install-OpenCV Download the script and go to install-opencv-master/ ubuntu/2.4 directory, add executable permissions to all shell scripts

chmod +x *.sh

Then install the latest version (currently 2.4.9)

sudo./opencv2_4_9.sh

The script automatically installs the dependencies, downloads the installation package, compiles and installs the OPENCV. The whole process is about half an hour.

Iv. Installing Additional Dependencies

sudo apt-get install build-essential libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev Libboost-all-dev Libhdf5-serial-dev Libgflags-dev Libgoogle-glog-dev Liblmdb-dev Protobuf-compiler

V. Download Caffe, about MKL:

  1. Download Caffe

http://download.csdn.net/download/jiangcunyeyu/8329829

After downloading, unzip the extract directly in your project path without installation.

2. About MKL

MKL is Intel's Charge math library, get is a very egg ache thing, if you have time, your own Baidu tutorial installation. MKL is not required, Openblas and Atlas can be substituted, and the two libraries are easy to install and use. own Baidu tutorial.

Vi. python-related packages required to install Caffe:

First install Pip and Python-dev (the system has Python environment by default, but we need to make Python-dev)

sudo apt-get install Python-dev python-pip

Then CD to Caffe where the path executes the following command installs the additional packages required to compile Caffe Python wrapper

 for  Do $req  Done

VII. Compiling CAFFE:

Go to the Caffe root directory and first copy the Makefile.config

CP Makefile.config.example Makefile.config

And then modify the content inside, the main parameters that need to be modified include

Cpu_only whether to use only CPU mode, no GPU not installed CUDA students can open this option Blas (using Intel MKL or Openblas) debug whether to use Debug mode, Open this option to debug the program in Eclipse or Nsight

Once setup is complete, start compiling

Make All-j4make testmake runtest

-J4 Note-j4 refers to the use of several threads at the same time to compile, can speed up, j after the number can be based on the number of CPU core to determine.

Compile Pycaffe:

And then basically install all the pull-out.

Viii. mnist Data Set training and testing:

1. Training:

Under the Caffe installation directory, get the mnist DataSet first:

CD data/mnistsh get_mnist. Sh

Generate mnist-train-lmdb/and mnist-test-lmdb/to convert data into Lmdb format (note that this is to be run from the Caffe root, or it will be an error, do not understand their own reading creat_mnist.sh):

examples/mnist/create_mnist. Sh

Training Network (IBID., run from Caffe Root):

SH examples/mnist/train_lenet.sh

(Theft map):

2. Test:

When all the data is well trained, the next step is to apply the model to the actual data:

If no GPU is used

./build/tools/caffe.bin Test-model=examples/mnist/lenet_train_test.prototxt-weights=examples/mnist/lenet_iter_ 10000.caffemodel

Test: Indicates a testing, not a training, of a well-trained model. Other parameters include train, time, Device_query. -model=xxx: Specifies the model Prototxt file, which is a text file that describes the network structure and data set information in detail. The results are as follows:

ubuntu14.04+caffe+cuda7.5 Environment Building and training and testing of mnist data sets

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.