更好的阅读体验,参考我公布的Windows && Ubuntu 双硬盘双系统。
Windows && Ubuntu 双硬盘双系统
主要参考SDD+HDD+Win7+Ubuntu12.04双硬盘双系统安装流程进行操作。
我的一些硬件环境:
- 120GB Intel SSD 和 250GB Samsung SSD
- 显卡是英伟达的GeForce GTX 750 Ti
- 内存8G
- 处理器Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
安装Windows系统
- Windows7 旗舰版64位系统,来自系统之家下载;
- 利用UltraISO制作U盘启动盘,进行安装(具体教程请自行搜索完成)。
安装Ubuntu系统
- 分区设置
/boot
4GB (Windows7 系统盘压缩出来的4GB空间) –> Intel 120GB SSD
/
104GB (Ubuntu16.04 系统的根分区) –> Samsung 250GB SSD 中压缩出120GB空间的104GB
swap
16GB (Ubuntu16.04 系统交换分区) –> Samsung 250GB SSD 中压缩出120GB空间的16GB
8G内存,设置swap
大小为16GB。
- 无法引导进入Windows7
解决方法:
修改/boot/grub/grub.cfg
将
### BEGIN /etc/grub.d/30_os-prober ###
menuentry "Windows 7 (loader) (on /dev/sda1)" --class windows --class os {
insmod part_msdos
insmod ntfs
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root AAAA9A0DAA99D663
chainloader +1
}
### END /etc/grub.d/30_os-prober ###
修改为:
### BEGIN /etc/grub.d/30_os-prober ###
menuentry "Windows 7 (loader) (on /dev/sda1)" --class windows --class os
insmod part_msdos
insmod ntfs
set root='(hd0,msdos1)'
search --no-floppy --fs-uuid --set=root AAAA9A0DAA99D663
ntldr ($root)/bootmgr
}
### END /etc/grub.d/30_os-prober ###
Caffe
安装显卡驱动
- 参考显卡信息
tzx@jt:~$ lspci | grep -i vga
01:00.0 VGA compatible controller: NVIDIA Corporation GM107 [GeForce GTX 750 Ti] (rev a2)
tzx@jt:~$
- 参考这里安装英伟达显卡驱动
- 利用
nvidia-smi
检验英伟达显卡驱动是否安装成功
tzx@jt:~$ nvidia-smi
Wed Jan 4 15:52:48 2017
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 367.57 Driver Version: 367.57 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 750 Ti Off | 0000:01:00.0 On | N/A |
| 33% 35C P0 1W / 38W | 244MiB / 1998MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1022 G /usr/lib/xorg/Xorg 122MiB |
| 0 1788 G compiz 120MiB |
+-----------------------------------------------------------------------------+
安装CUDA
- 官网下载CUDA
下载时,我的选择如下所示:
Operating SystemLinux
Architecturex86_64(这个可能不同)
DistributionUbuntu
Version16.04
Installer Typedeb(local)
$ sudo dpkg -i cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64.deb
$ sudo apt-get update
$ sudo apt-get
- 测试是否安装成功
$ cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery
$ make
$ sudo ./deviceQuery
[sudo] password for tzx:
./deviceQuery Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 1 CUDA Capable device(s)
Device 0: "GeForce GTX 750 Ti"
CUDA Driver Version / Runtime Version 8.0 / 8.0
CUDA Capability Major/Minor version number: 5.0
Total amount of global memory: 1999 MBytes (2095841280 bytes)
( 5) Multiprocessors, (128) CUDA Cores/MP: 640 CUDA Cores
GPU Max Clock rate: 1084 MHz (1.08 GHz)
Memory Clock rate: 2700 Mhz
Memory Bus Width: 128-bit
L2 Cache Size: 2097152 bytes
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), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(16384, 16384), 2048 layers
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 2048
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: 2147483647 bytes
Texture alignment: 512 bytes
Concurrent copy and kernel execution: Yes with 1 copy engine(s)
Run time limit on kernels: Yes
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
Device supports Unified Addressing (UVA): Yes
Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 8.0, CUDA Runtime Version = 8.0, NumDevs = 1, Device0 = GeForce GTX 750
安装cuDNN
- 官方下载cuDNN,需要注册账号才能下载。
我下载的是cudnn-8.0-linux-x64-v5.0-ga.tgz
!
然后,执行以下命令:
$ cd ~/Downloads
$ sudo tar -zxvf ./cudnn-8.0-linux-x64-v5.0-ga.tgz
$ cd cuda/include
$ sudo cp cudnn.h /usr/local/cuda/include # 复制头文件
$ cd ../lib64
$ sudo cp lib* /usr/local/cuda/lib64/ # 复制动态链接库
$ cd /usr/local/cuda/lib64/
$ sudo rm -rf libcudnn.so libcudnn.so.5 # 删除原有动态文件
$ sudo ln -s libcudnn.so.5.0.5 libcudnn.so.5 # 生成软衔接
$ sudo ln -s libcudnn.so.5 libcudnn.so # 生成软链接
安装OpenCV3.2.0
参考我之前写的博客Ubuntu16.04 编译OpenCV 和 Tesseract-OCR。
opencv-3.2.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e
目录下的ippicv_linux_20151201.tgz 和
opencv_contrib-3.2.0/modules/dnn/.download/bd5e3eed635a8d32e2b99658633815ef/v3.1.0
目录下的protobuf-cpp-3.1.0.tar.gz两个文件,可能因为网络下载问题,无法下载成功。自己下载后替换到相应的位置。
下载ippicv_linux_20151201.tgz
下载protobuf-cpp-3.1.0.tar.gz
安装Caffe
安装相关依赖库
tzx@jt:~$ sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
tzx@jt:~$ sudo apt-get install --no-install-recommends libboost-all-dev
tzx@jt:~$ sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev
tzx@jt:~$ sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
获取Caffe代码并修改配置
- 获取Caffe代码
$ sudo apt-get update
$ sudo apt-get install git
$ mkdir Github
$ cd Github
$ git clone https://github.com/BVLC/caffe.git
- 修改Makefile.config
$ cd ~/Github/caffe
$ sudo cp Makefile.config.example Makefile.config
$ sudo gedit Makefile.config #打开Makefile.config文件
- 若使用cuDNN,则将
#USE_CUDNN := 1
修改成:USE_CUDNN := 1
- 若使用的OpenCV版本是3的,则将
#OPENCV_VERSION := 3
修改为:OPENCV_VERSION := 3
- 若要使用python来编写layer,则将
#WITH_PYTHON_LAYER := 1
修改为WITH_PYTHON_LAYER := 1
- 重要的一项: 将
# Whatever else you find you need goes here.
下面的
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB)
修改为:
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
- 修改Makefile
$ sudo
将
NVCCFLAGS +=-ccbin=$(CXX) -Xcompiler-fPIC $(COMMON_FLAGS)
替换为:
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC
将
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
替换为:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
- 注意自己CUDA的版本号!
$ sudo cp /usr/local/cuda-8.0/lib64/libcudart.so.8.0 /usr/local/lib/libcudart.so.8.0 && sudo ldconfig
$ sudo cp /usr/local/cuda-8.0/lib64/libcublas.so.8.0 /usr/local/lib/libcublas.so.8.0 && sudo ldconfig
$ sudo cp /usr/local/cuda-8.0/lib64/libcurand.so.8.0 /usr/local/lib/libcurand.so.8.0 && sudo ldconfig
$ sudo cp /usr/local/cuda-8.0/lib64/libcudnn.so.5 /usr/local/lib/libcudnn.so.5
编译Caffe
$ cd ~/Github/caffe
$ make all -j4 #-j根据自己电脑配置决定
$ make test
$ make runtest
$ make distribute
- pycaffe
$ cd ~/Github/caffe/python
$ for req in $(cat requirements.txt); do pip install $req -i https://pypi.douban.com/simple; done
$ cd ~/Github/caffe
$ make pycaffe
$ cd ~/Github/caffe/python
$ pwd
/home/tzx/Github/caffe/python # 替换tzx为你自己的用户名
$ sudo
在.bashrc
最后,添加以下代码
export PYTHONPATH=/home/tzx/Github/caffe/python:$PYTHONPATH # 替换tzx为你自己的用户名
然后,让修改立即生效$ source ~/.bashrc
。
- 验证pycaffe
tzx@jt:~$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import caffe
>>> caffe.__version__
'1.0.0-rc3'
>>>
运行MNIST测试
$ cd ~/Github/caffe
$ ./data/mnist/get_mnist.sh # 下载MNIST数据库并解压缩
$ ./examples/mnist/create_mnist.sh # 将其转换成Lmdb数据库格式
$ ./examples/mnist/train_lenet.sh # 训练网络
最后的训练结果
I0104 16:56:03.183193 28155 solver.cpp:317] Iteration 10000, loss = 0.00346665
I0104 16:56:03.183210 28155 solver.cpp:337] Iteration 10000, Testing net (#0)
I0104 16:56:03.324321 28155 solver.cpp:404] Test net output #0: accuracy = 0.9908
I0104 16:56:03.324347 28155 solver.cpp:404] Test net output #1: loss = 0.0303717 (* 1 = 0.0303717 loss)
I0104 16:56:03.324350 28155 solver.cpp:322] Optimization Done.
I0104 16:56:03.324353 28155 caffe.cpp:254] Optimization Done.
精度已经到99.08%。
参考
- SDD+HDD+Win7+Ubuntu12.04双硬盘双系统安装流程
- ubuntu 和win7双系统安装后win7无法启动解决办法
- Ubuntu16.04 安装配置Caffe