环境:Ubuntu 16.04 + CUDA8.0 + cudnn5.1
下载模型:
git clone https://github.com/pjreddie/darknet
cd darknet
修改Makefile文件配置:
在darknet目录下
gedit Makefile
GPU=1 #如果使用GPU设置为1,CPU设置为0
CUDNN=1 #如果使用CUDNN设置为1,否则为0
OPENCV=1 #如果调用摄像头或显示图片,还需要设置OPENCV为1,否则为0
OPENMP=0 #如果使用OPENMP设置为1,否则为0
DEBUG=0 #如果使用DEBUG设置为1,否则为0
ARCH= -gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=[sm_50,compute_50] \
-gencode arch=compute_52,code=[sm_52,compute_52]
# -gencode arch=compute_20,code=[sm_20,sm_21] \ This one is deprecated?
# This is what I use, uncomment if you know your arch and want to specify
ARCH= -gencode arch=compute_61,code=compute_61 #取消此行注释并将52改为61,因为我的GPU是1050Ti和1080Ti,具体GPU算力是多少可以百度
... ...
NVCC=/home/user/cuda-8.0/bin/nvcc #NVCC=nvcc 修改为自己的路径
... ...
COMMON+= -DGPU -I/home/hebao/cuda-8.0/include/ #修改为自己的路径,我的这部分改为cuda也能运行
CFLAGS+= -DGPU
LDFLAGS+= -L/home/hebao/cuda-8.0/lib64 -lcuda -lcudart -lcublas -lcurand #修改为自己的路径
编译:
在darknet目录下
make
若前面的路径错误或GPU算力不匹配都会报错,在服务器上跑的话将Makefile中的opencv置0,否则报错。
下载权重,运行demo:
在darknet目录下
wget https://pjreddie.com/media/files/yolov3.weights
./darknet detector test cfg/coco.data cfg/yolov3.cfg yolov3.weights data/dog.jpg
若demo运行成功,则说明没问题。
制作自己的VOC数据集:
详见另一篇文章。
这里说一下,我用的VOC2007数据集,一般只需要将Annotations替换为自己的xml文件,JPEGImages替换为自己的.jpg图片即可。
需要注意的是VOCdevkit文件目录在darknet下。
下载voc_label.py文件:
在darknet目录下:
wget https://pjreddie.com/media/files/voc_label.py
gedit voc_label.py
修改文件:
sets=[('2007', 'train'), ('2007', 'test'), ('2007', 'val')] #删除2012的部分
classes = ["man", "woman"] #设置为自己的类别
运行修改的voc_label.py文件:
python voc_label.py
将会发现darknet目录下会出现几个.txt文件,然后将其合在一起:
cat 2007_train.txt 2007_val.txt > train.txt
此时会发现darknet目录下出现了一个train.txt文件
修改voc.data文件: