Ubuntu 16.04 安装 Darknet

Ubuntu16.04下Darknet安装指南
本文详细介绍了在Ubuntu16.04系统上安装Darknet的全过程,包括GPU驱动、CUDA、cuDNN、OpenCV的安装配置,以及解决常见错误的方法。
部署运行你感兴趣的模型镜像

安装Ubuntu 16.04

使用UltraISO制作安装盘会出现问题,建议使用Rufu制作安装盘。

安装GPU驱动、CUDA、cuDNN

安装GPU驱动:

sudo add-apt-repository ppa:graphics-drivers
sudo apt update
sudo apt install nvidia-396
sudo reboot now

重启后在settings→Software & Updates→Other Software中将源删除;在/etc/apt/sources.list.d中将对应文件删除,避免自动升级驱动。

安装CUDA、cuDNN:

正确选择CUDA、cuDNN版本号,建议CUDA使用runfile版,cuDNN使用Library版安装

//CUDA
sudo chmod +x (CUDA安装文件名)
./(CUDA安装文件名) //询问是否安装GPU驱动时选择“n”,切记不要重复安装GPU驱动
sudo vim ~/.bashrc
//在文件结尾加入如下两行
export PATH=/usr/local/cuda-9.2/bin${PATH:+:$PATH}}      //注意,根据自己的版本,修改cuda-9.2/9.0...
export LD_LIBRARY_PATH=/usr/local/cuda-9.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}  //注意,根据自己的版本,修改cuda-9.2/9.0...
//cuDNN
tar -xzvf (cuDNN安装文件名)
cd CUDA
sudo cp include/cudnn.h    /usr/local/cuda/include
sudo cp lib64/libcudnn*    /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h   /usr/local/cuda/lib64/libcudnn*
//关闭终端,重新打开终端
nvcc -V
//如果显示nvcc版本,则说明安装成功

安装OpenCV

安装pip时用如下命令安装:

wget https://bootstrap.pypa.io/get-pip.py
sudo python3 get-pip.py

编译安装opencv

//下载源码
git clong https://github.com/opencv/opencv.git
git clong https://github.com/opencv/opencv_contrib.git
//切换版本
cd opencv
git checkout 3.4.0
cd ../opencv_contrib
git checkout 3.4.0

cd ../opencv
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \ 
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D WITH_CUDA=ON \ //使用GPU
      -D INSTALL_PYTHON_EXAMPLES=ON \ 
      -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
      -D BUILD_EXAMPLES=ON -D PYTHON3_EXECUTABLE=$(which python3) \
      -D BUILD_opencv_python3=ON \
      -D PYTHON3_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so ..
make
sudo make install

若在cmake中出现如下错误

[proxychains] DLL init: proxychains-ng 4.13-git-3-geb36238
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
CUDA_CUDA_LIBRARY (ADVANCED)
    linked by target "example_gpu_optical_flow" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_houghlines" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_video_reader" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_surf_keypoint_matcher" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_cascadeclassifier_nvidia_api" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_alpha_comp" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_bgfg_segm" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_morphology" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_generalized_hough" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_farneback_optical_flow" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_stereo_multi" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_driver_api_multi" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_opticalflow_nvidia_api" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_hog" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_pyrlk_optical_flow" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_cascadeclassifier" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_driver_api_stereo_multi" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_super_resolution" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_multi" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_video_writer" in directory /home/bfyb/Downloads/opencv/samples/gpu
    linked by target "example_gpu_stereo_match" in directory /home/bfyb/Downloads/opencv/samples/gpu

-- Configuring incomplete, errors occurred!
See also "/home/bfyb/Downloads/opencv/build/CMakeFiles/CMakeOutput.log".
See also "/home/bfyb/Downloads/opencv/build/CMakeFiles/CMakeError.log".

则,在cmake的参数中添加如下:

      -D CMAKE_LIBRARY_PATH=/usr/local/cuda/lib64/stubs

如果在cmake过程中,出现ffmpeg无法找到,

Can't find ffmpeg - 'pkg-config' utility is missing
...
--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      NO
--       avcodec:                   NO
--       avformat:                  NO
--       avutil:                    NO
--       swscale:                   NO
--       avresample:                NO
--     GStreamer:                   NO

通过

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

可以解决,具体原因参见这篇博客

删除opencv

install 完成后若想要删除,则

cd (opencv/build目录)
sudo make uninstall
cd ..
sudo rm -r build

安装darknet

git clone https://github.com/AlexeyAB/darknet.git
cd darknet
//根据条件设置Makefile文件中的GPU、CUDNN、CUDNN_HALF、OPENCV、AVX、OPENMP、LIBSO
vim Makefile
make

完成安装!!!

如果运行检测命令后出现如下错误:

./darknet ./darknet: error while loading shared libraries: libopencv_highgui.so.3.4: cannot open shared object file: No such file or directory

则参考这条issue进行如下修改:

sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig

您可能感兴趣的与本文相关的镜像

PyTorch 2.5

PyTorch 2.5

PyTorch
Cuda

PyTorch 是一个开源的 Python 机器学习库,基于 Torch 库,底层由 C++ 实现,应用于人工智能领域,如计算机视觉和自然语言处理

### 配置并使用 YOLOv3 进行训练 要在 Ubuntu 16.04 上成功配置并使用 YOLOv3 模型进行训练,需完成以下几个主要部分的工作: #### 一、安装 Darknet 和依赖项 首先需要克隆 AlexeyAB 的 `darknet` 仓库,并按照官方指南编译项目。 ```bash git clone https://github.com/AlexeyAB/darknet.git cd darknet make ``` 上述命令会下载源码并尝试编译 Darknet 工具包[^1]。如果遇到错误提示缺少某些库,则可能需要手动安装这些依赖项。 #### 二、设置 CUDA 和 cuDNN 支持 为了加速 GPU 训练过程,建议启用 NVIDIA 提供的 CUDA 及其深度学习优化库 cuDNN。以下是具体操作方法: 1. **安装 CUDA**: 下载适合系统的版本 (推荐 CUDA 8 或更高),并通过 dpkg 安装器执行安装脚本。 2. **配置环境变量**: 编辑用户的 `.bashrc` 文件来添加必要的路径信息: ```bash sudo nano ~/.bashrc export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}} export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64\ ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} ``` 3. **加载 cuDNN 库**: 将 libcudnn.so.x.y.z 复制至 `/usr/local/cuda/targets/x86_64-linux/lib/`, 并创建软链接指向最新版共享对象文件[^3]: ```bash sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/ sudo chmod a+r /usr/local/cuda/lib64/libcudnn* ``` 重新登录使更改生效或者直接运行 source 命令更新当前 shell session 中的环境变量。 #### 三、准备自定义数据集 对于特定领域内的目标检测任务来说,通常都需要用自己的标注图片作为输入资料。这里假设已经准备好了一个 VOC 格式的 XML 数据描述文档集合以及对应的 JPEG 图像资源。 编辑配置文件以匹配个人的数据结构布局: - 创建一个新的 .cfg 文件用于指定网络架构参数; - 修改 classes 参数数量等于类别总数; - 更新 filters 属性值为 `(classes + 5)*3`; 最后记得调整 batch size, subdivisions 等超参设定以便更好地适应硬件条件限制情况下的性能表现需求[^2]. #### 四、开始正式训练流程 当一切准备工作就绪以后就可以发起实际的学习进程啦! ```bash ./darknet detector train cfg/voc.data cfg/yolov3-voc.cfg darknet53.conv.74 -gpu 1 2>&1 | tee logs/train_yolov3.log ``` 这条指令将会调用预训练权重初始化模型参数并向终端打印实时进度报告的同时将其记录下来存入日志文件当中方便日后分析查看效果曲线变化趋势等问题所在之处进而采取相应措施加以改进提升最终成果质量水平达到预期标准之上. --- ### 注意事项 确保所有软件组件兼容性良好;密切监视系统资源消耗状况防止过热宕机等情况发生影响整体效率进展速度等方面因素考虑全面合理规划时间安排科学管理整个开发周期直至顺利完成既定目标任务为止.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值