After long-term verification, this blog installed caffe success, in order to facilitate everyone and themselves, recorded, to the later reference
1. Install dependent packages
2. Disable the original graphics driver Nouveau
3. Download cuda8.0
4, Installation cuda8.0
5, Installation Cudnn
6. Configure Environment variables
7, installation OpenCV
8, installation Caffe
9, install Pycaffe interface environment
The first step installs the dependency package
Install the dependent packages and tools needed for the next steps or the environment, and then enter:
1 sudoApt-getInstallLibprotobuf-dev Libleveldb-dev Libsnappy-dev Libhdf5-serial-dev protobuf-compiler2 3 sudoApt-getInstall--no-Install-recommends libboost-all-Dev4 5 sudoApt-getInstallLibopenblas-dev Liblapack-dev libatlas-base-Dev6 7 sudoApt-getInstallLibgflags-dev Libgoogle-glog-dev liblmdb-Dev8 9 sudoApt-getInstallgit cmake build-essential Libopencv-dev
There is a chance that the installation failure will cause problems with subsequent steps, to ensure that the installation succeeds, the authentication method is to rerun the command
Step two disable Nouveau
Each Ubuntu installed, will bring their own graphics card driver Nouveau, only after disabling the Nouveau can install Nvidia graphics card driver, the disabling method is in the/etc/modprobe.d/blacklist-nouveau.conf Add a disable command to the file, open with the command, you must use administrator privileges to write:
1 sudo gedit/etc/modprobe. d/blacklist-nouveau.conf
Open after found that the file does not have any content, in fact, this file is built by their own configuration file, write:
1 blacklist nouveau option nouveau modeset=0
After saving exit, to execute the command when the profile is disabled nouveau really takes effect:
1 sudo update-initramfs-u
You can also reboot, and you will see a problem with the desktop resolution because there is no graphics driver
Step three Download Cuda 8.0
Go to Https://developer.nvidia.com/cuda-downloads, select cuda type then download.
Fourth Step installation cuda8.0
The fourth step download 1.4G CUDA contains NVIDIA graphics drivers, so the installation of Cuda installed includes Nvidia graphics driver installation, this time note whether you have installed NVIDIA graphics drivers, if you do not guarantee that the installed Nvidia graphics drivers must be correct, then uninstall Before installing the Nvidia graphics driver, and then starting to install Cuda 8.0, if you can ensure that the correct Nvidia graphics drivers are installed, start the installation of Cuda 8.0 directly, and choose to no longer install the Nvidia graphics driver during the installation process.
< How to uninstall drivers >
After installing the graphics driver via additional driver some are not satisfied need to change the driver first to uninstall the driver I installed nvidia-331-updates For example if you install another version, please change the command yourself
sudo apt-get remove--purge nvidia-*
If the downloaded driver is installed on the official website, rerun the run file to uninstall sh./nvidia.run--uninstall</Uninstall Drive method > via CTRL + ALT + F1 Enter text mode, enter account password login, via CTRL + ALT + F7 You can return to graphical mode and first turn off desktop Services when you log in in text mode:
1 sudo service LIGHTDM stop
Then, with Ctrl + Alt + F7, it is found that the graphical mode has not been successfully returned, indicating that the desktop service has been successfully shut down, note that this step is especially important for the next Nvidia driver installation and must ensure that the desktop service is turned off.
Ctrl + Alt + F1 into text mode, then run the CUDA installation file for installation, run the installation file directly from the SH command:
1 download Cuda directory on CD 2 3 chmod +x Cuda_ name. Run45sudo ./cuda_ name. Run
After about 1 minutes to execute this command will appear 0% information, this time press ENTER to let this percentage increase until 100%, and then follow the prompts, enter accept first, and then let choose whether to install the Nvidia driver, here the choice corresponds to the beginning of the 5th step, if not installed, enter "Y", Enter "n" If you are sure that the correct driver is installed.
The rest of the choice is to enter "Y" to confirm the installation or confirm the default path installation, start the installation, if the installation failure prompt may not shut down the desktop service or the installation of the Nvidia driver installed repeatedly install the Nvidia driver, after the installation is completed, enter the restart command restart:
1 sudo reboot
Fifth Step configuring environment variables
After restarting, log in to the system, configure the CUDA environment variable, and, as with the 3rd step, open the configuration file with the Gedit command:
1 sudo gedit ~/.BASHRC
At the end of the file, add the following and save:
1 Export ld_library_path=/usr/lib/x86_64-linux-GNU: $LD _library_path23 Export ld_library_path=/lib/x86_64-linux-45 export path=/usr/local/cuda-8.0/Bin : $PATH67 export ld_library_path=/usr/local/cuda/lib64: $LD _library_path
Is that the configuration takes effect
1 Source ~/.BASHRC
Verifying that the Cuda installation is successful
1 cd/usr/local/cuda-8.0/samples/1_utilities/devicequery23sudo make45 ./devicequery
Sixth Step Installation Cudnn
Login Official website: https://developer.nvidia.com/rdp/cudnn-download, download the corresponding CUDA version and Linux system CUDNN compression package, note the official website download CUDNN need to register an account and login
After the download is done, unzip, get a Cuda folder, the folder under Include and lib64 two folders, the command line into the cudn/include path, and then do the following:
1 sudo CP cudnn.h/usr/local/cuda/include/#复制头文件
Then the command line enters the cudn/lib64 path and runs the following command:
1 sudo CPlib*/usr/local/cuda/lib64/#复制动态链接库2 3cd/usr/local/cuda/lib64/sudo RM-RF libcudnn.so libcudnn.so.5#删除原有动态文件4 5 sudo LN-S libcudnn.so.5.1.TenLibcudnn.so.5#生成软衔接6 7 sudo LN-S libcudnn.so.5Libcudnn.so #生成软链接
Note Generate a soft connection here, be sure to correspond to your own download of the CUDNN version is 5.1.10 or other
Seventh Step installation OpenCV
Go to official website: http://opencv.org/releases.html, select 3.1.0 version of source, download Opencv-3.1.0.zip
Unzip to the location you want to install, command line into the unpacked folder opencv-3.1.0 directory, execute:
1 mkdir Build # Create a compiled file directory 2 3 CD Build 4 5 cmake-d cmake_build_type=release-d cmake_install_prefix=/usr/Local: 6 7 make-j8 #编译
The following error may occur when the Execute MAKE-J8 command is compiled to 92%:
1 modules/cudalegacy/src/graphcuts. cpp:2' nppigraphcutstate ' have not been declared3 typedef nppstatus (*4 nppigraphcutstate** ppstate, npp8u* pdevicemem);
This is due to opecv3.1 incompatible with cuda8.0. Workaround:
Modify the contents of the/opencv-3.1.0/modules/cudalegacy/src/graphcuts.cpp file,
Install after successful compilation:
1 sudo Make Install #安装
After the installation is complete, verify that the installation was successful by viewing the OPENCV version:
1 pkg-config --modversion OpenCV
Eighth Step installation Caffe
First, under the path you want to install, clone:
1 git clone https://github.com/bvlc/caffe.git
Enter Caffe, copy the Makefile.config.example file and rename it to Makefile.config, or call the following command directly in the Caffe directory to complete the copy operation:
1 sudo CP Makefile.config.example Makefile.config
The reason for the copy is that the Makefile.config file is required to compile the Caffe, and Makefile.config.example is just an example of the configuration file given by Caffe and cannot be used to compile caffe.
Then modify the Makefile.config file to open the file in the Caffe directory:
1 sudo gedit makefile.config
Modify the contents of the Makefile.config file:
1. Application Cudnn
1 will be 2 1 3 41
2. Apply OPENCV version
1 will be 2 3 3 43
3. Using the Python interface
1 will be 2 1 3 41
4. Modify the Python path
1 include_dirs: = $ (python_include)/usr/local/INCLUDE2 library_dirs: = $ (python_lib)/usr/ local/lib/usr/34 include_dirs: = $ (python_include)/usr/local/include/usr/ include/hdf5/serial5 library_dirs: = $ (python_lib)/usr/local/lib/usr/lib/usr/lib/x86_64- Linux-gnu/usr/lib/x86_64-linux-gnu/hdf5/serial
OK, you can start compiling and executing in the Caffe directory:
1 make All-j8
This is if the previous configuration or installation error, then the compilation will have a variety of problems, so the previous steps must be careful.
After compiling successfully, you can run the test:
1 sudo make Runtest-j8
If the display results are shown, the Caffe has been successfully installed.
Nineth Step Configuration Pycaffe
After the successful installation of Caffe in the previous step, it is possible to do training datasets or predict various related things through Caffe, but if you use the Python layer that you implement, you need to Pycaffe interface
First compile the Pycaffe:
1 CD Caffe 2 3 sudo make Pycaffe-j8
Compilation error may be a necessary package not installed for Python, such as NumPy
1 sudo Install Python-numpy
After compiling Pycaffe successfully, verify that you can import the Caffe package in Python, first into the Python environment:
1 python
2 Import Caffe
Quote File "<stdin>", line 1, in <module> importerror: No module named Caffe Error
Workaround:
1 gedit ~/. BASHRC23 export pythonpath="~/caffe/python" 45 Source ~/.BASHRC
If Importerror appears: No module named skimage. IO error
1 Install sudo Install Python-pip
Ubuntu 1604 + cuda8.0 + Caffe