Installing Darknet

本文详细介绍了如何在Ubuntu 18.04环境下安装并配置Darknet深度学习框架,包括使用GCC 7.4.0编译,以及如何启用CUDA和OpenCV支持,提升神经网络运行速度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

文章来源

https://pjreddie.com/darknet/install/

应用环境

UBUNTU18.04

gcc和g++版本7.4.0

Installing The Base System

First clone the Darknet git repository here. This can be accomplished by:

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

If this works you should see a whole bunch of compiling information fly by:

mkdir -p obj
gcc -I/usr/local/cuda/include/  -Wall -Wfatal-errors  -Ofast....
gcc -I/usr/local/cuda/include/  -Wall -Wfatal-errors  -Ofast....
gcc -I/usr/local/cuda/include/  -Wall -Wfatal-errors  -Ofast....
.....
gcc -I/usr/local/cuda/include/  -Wall -Wfatal-errors  -Ofast -lm....

If you have any errors, try to fix them? If everything seems to have compiled correctly, try running it!

./darknet

You should get the output:

usage: ./darknet <function>

Great! Now check out the cool things you can do with darknet here.

Compiling With CUDA

Darknet on the CPU is fast but it's like 500 times faster on GPU! You'll have to have an Nvidia GPU and you'll have to install CUDA. I won't go into CUDA installation in detail because it is terrifying.

Once you have CUDA installed, change the first line of the Makefile in the base directory to read:

GPU=1

Now you can make the project and CUDA will be enabled. By default it will run the network on the 0th graphics card in your system (if you installed CUDA correctly you can list your graphics cards using nvidia-smi). If you want to change what card Darknet uses you can give it the optional command line flag -i, like:

./darknet -i 1 imagenet test cfg/alexnet.cfg alexnet.weights

If you compiled using CUDA but want to do CPU computation for whatever reason you can use -nogpu to use the CPU instead:

./darknet -nogpu imagenet test cfg/alexnet.cfg alexnet.weights

Enjoy your new, super fast neural networks!

Compiling With OpenCV

By default, Darknet uses stb_image.h for image loading. If you want more support for weird formats (like CMYK jpegs, thanks Obama) you can use OpenCV instead! OpenCV also allows you to view images and detections without having to save them to disk.

First install OpenCV. If you do this from source it will be long and complex so try to get a package manager to do it for you.

Next, change the 2nd line of the Makefile to read:

OPENCV=1

You're done! To try it out, first re-make the project. Then use the imtest routine to test image loading and displaying:

./darknet imtest data/eagle.jpg
L2 Norm: 371.979095
Not compiled with OpenCV, saving to Original.png instead
Not compiled with OpenCV, saving to Gray.png instead
Not compiled with OpenCV, saving to C1.png instead
Not compiled with OpenCV, saving to C2.png instead
Not compiled with OpenCV, saving to C3.png instead
Not compiled with OpenCV, saving to C4.png instead

If you get a bunch of windows with eagles in them you've succeeded!

我没有安装CUBA和OpenCV。这样我们就可以当前目录下看到Original.jpg、Gray.jpg、C1.jpg、C2.jpg、C3.jpg和C4.jpg。惭愧,由于第一次使用darknet,也不知道图像进行了什么处理。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值