服务器配置darkflow,darknet,GPU版本

1.pip安装


sudo apt-get update

sudo apt-get -y install python-pip

sudo apt-get install python3-pip

将驱动添加到黑名单blacklist.conf中,但是由于该文件的属性不允许修改。所以需要先修改文件属性。

查看属性


$sudo ls -lh /etc/modprobe.d/blacklist.conf

修改属性


$sudo chmod 666 /etc/modprobe.d/blacklist.conf

用gedit打开


$sudo gedit /etc/modprobe.d/blacklist.conf

在该文件后添加以下几行:

`blacklist vga16fb

blacklist nouveau

blacklist rivafb

blacklist rivatv

blacklist nvidiafb`

2.ubuntu-drivers


sudo apt-get install ubuntu-drivers-common

查看适合安装的驱动版本:


sudo ubuntu-drivers devices  

输出:

`

== cpu-microcode.py ==

driver : intel-microcode - distro free

== /sys/devices/pci0000:00/0000:00:04.0 ==

modalias : pci:v000010DEd0000102Dsv000010DEsd0000106Cbc03sc02i00

vendor : NVIDIA Corporation

model : GK210GL [Tesla K80]

driver : nvidia-384 - distro non-free recommended

driver : xserver-xorg-video-nouveau - distro free builti`

安装推荐的驱动:


sudo apt-get update   

sudo apt-get install nvidia-367   

sudo apt-get install mesa-common-dev   

sudo apt-get install freeglut3-dev 

判断安装是否成功:


nvidia-smi

输出如下,则OK:
img

安装CUDA:


sh cuda_8.0.27_linux.run --override  

输出如下:

`Using more to view the EULA.
End User License Agreement

-----------------------

Preface

-------



The following contains specific license terms and conditions

for four separate NVIDIA products. By accepting this

agreement, you agree to comply with all the terms and

conditions applicable to the specific product(s) included

herein.





NVIDIA CUDA Toolkit





Description



The NVIDIA CUDA Toolkit provides command-line and graphical

tools for building, debugging and optimizing the performance

of applications accelerated by NVIDIA GPUs, runtime and math

libraries, and documentation including programming guides,

user manuals, and API references. The NVIDIA CUDA Toolkit

License Agreement is available in Chapter 1.





Default Install Location of CUDA Toolkit



Windows platform:



Do you accept the previously read EULA?

accept/decline/quit: accept



Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 367.48?

(y)es/(n)o/(q)uit: n



Install the CUDA 8.0 Toolkit?

(y)es/(n)o/(q)uit: y



Enter Toolkit Location

 [ default is /usr/local/cuda-8.0 ]:  



Do you want to install a symbolic link at /usr/local/cuda?

(y)es/(n)o/(q)uit: y



Install the CUDA 8.0 Samples?

(y)es/(n)o/(q)uit: y 



Enter CUDA Samples Location

 [ default is /home/kinny ]: 



Installing the CUDA Toolkit in /usr/local/cuda-8.0 ...

Missing recommended library: libXmu.so



Installing the CUDA Samples in /home/kinny ...

Copying samples to /home/kinny/NVIDIA_CUDA-8.0_Samples now...

Finished copying samples.



===========

= Summary =

===========



Driver:   Not Selected

Toolkit:  Installed in /usr/local/cuda-8.0

Samples:  Installed in /home/kinny, but missing recommended libraries



Please make sure that

 -   PATH includes /usr/local/cuda-8.0/bin

 -   LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root



To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin



Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.



***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work.

To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
    sudo <CudaInstaller>.run -silent -driver
Logfile is /tmp/cuda_install_17494.log`

添加环境变量


sudo vim ~/.bashrc

在bashrc末尾添加:

export CUDA_HOME=/usr/local/cuda-8.0
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH
export PATH=/usr/local/cuda-8.0/bin:$PATH

保存退出后使其立刻生效

source ~/.bashrc 

4、安装例程测试

(1)查看cuda版本

    nvcc --version  

(2)最后进入cuda自带的例子中看cuda是否已正确配置

cd ~/NVIDIA_CUDA-8.0_Samples/  

make -j16  

进入例程

cd ~/NVIDIA_CUDA-8.0_Samples/bin/x86_64/linux/release  

./deviceQuery  

输出如下,则成功:
img

这里写图片描述

cudnn加速,安装记录如下:

下载对应cuda版本的cudnn,需要注册Nvidia开发者账号。NVIDIA cuDNN下载地址

解压:tar zxvf cudnn-8.0-linux-x64-v5.1.tgz

看到如下目录:

3.cuda的安装目录通过which nvcc 查看
img

cuda安装目录为/usr/loca/cuda-8.0
img

4 把include/lib64/目录下的文件拷贝到cuda的安装目录下的include/lib64里面


$ cd ~/src/cuda #解压后的路径

$ sudo cp -P include/cudnn.h /usr/local/cuda-8.0/include

$ sudo cp -P lib64/libcudnn* /usr/local/cuda-8.0/lib64

$ sudo chmod a+r /usr/local/cuda-8.0/lib64/libcudnn*

通过pip安装TensorFlow指定版本命令:


cpu版本:pip install tensorflow==1.4.1   (==后面为所要安装的版本号)



gpu版本类似:pip install tensorflow-gpu==1.4.1

查看版本:

python -c 'import tensorflow as tf; print(tf.__version__)'  # for Python 2
python3 -c 'import tensorflow as tf; print(tf.__version__)'  # for Python 3

Opencv

sudo apt-get install build-essential

sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

##opencv安装

    cd ~ //比如工作目录为opencv即,cd ~/opencv

    git clone https://github.com/Itseez/opencv.git

    git clone https://github.com/Itseez/opencv_contrib.git

    cd ~/opencv

    mkdir build //建立一个build目录,把cmake的文件都放着里边

    cd build   //进入build目录

    cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..

    make -j7 # 并行运行七个jobs,这一步也在build目录中进行,编译时间很长,耐心等待

    sudo make install

下载与安装darkfolw:

首先需要安转cython for python3,安装命令为:


sudo pip3 install Cython --install-option="--no-cython-compile"

下载darkflow:

git clonehttps://github.com/thtrieu/darkflow

进入darkflow目录,并安装:

cd darkflow

python3 setup.py build_ext --inplace

pip3 install .  #中间有空格

成功显示:
img

操作见官方

darknet配置

网上找的,亲测可行

sudo apt-get update

sudo apt-get -y install python-pip

sudo apt-get install python3-pip

sudo apt-get install unzip

安装顺序

opencv

CUDA

darknet

安装顺序一定要注意,不然出现错误非常麻烦。darknet安装顺序可以随意,但是opencv一定要cuda前面安装。不然报错很难解决只能重装系统。

这里我们安装的版本是opencv3.2.0+cuda8.0,由于需要利用tensorlfow进行后续的开发,所以cuda需要选择cuda8。tensorlfow暂时不支持cuda9。


sudo apt-get install build-essential

sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.2.0.zip  

wget -O opencvcon.zip https://github.com/opencv/opencv_contrib/archive/3.2.0.zip

unzip opencv.zip# 此时会生成一个opencv3.2.0

unzip opencvcon.zip

cd opencv-3.2.0

#创建一个文件夹

mkdir build

cd build

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

make -j4

make install

设置相关路径


sudo gedit /etc/ld.so.conf.d/opencv.conf 

在文件中添加/usr/local/lib

执行下面指令


sudo ldconfig  

打开另一个opencv的配置文件


sudo gedit /etc/bash.bashrc  

在里面添加


PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig  

export PKG_CONFIG_PATH

如:

测试opencv是否安装成功

这里我选择的是samples/python里面的例子

进入到该文件家,执行


python turing.py

配置cuda

#

1.配置darknet

git clone https://github.com/pjreddie/darknet

cd darknet

打开Makefile文件,将开头几行改为

GPU=1 #确保已经配置好

CUDNN=1

OPENCV=1

之后重新编译make,就可以实现基于cuda和opencv的编译

  1. 下载预训练文件

wget https://pjreddie.com/media/files/yolo.weights

  1. 测试

./darknet detect cfg/yolo.cfg yolo.weights data/dog.jpg

你可以得到以下输出

layer filters size input output

0 conv     32  3 x 3 / 1   416 x 416 x   3   ->   416 x 416 x  32

1 max          2 x 2 / 2   416 x 416 x  32   ->   208 x 208 x  32

.......

29 conv 425 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 425

30 detection

Loading weights from yolo.weights…Done!

data/dog.jpg: Predicted in 0.016287 seconds.

car: 54%

bicycle: 51%

dog: 56%

说明yolo2能顺利实现功能

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值