Windows 11通过WSL安装ubuntu系统部署原版 Darknet/YOLO

📅 2026/7/15 5:37:34
Windows 11通过WSL安装ubuntu系统部署原版 Darknet/YOLO
目录一、概述二、环境安装2.1 Windows启用WSL功能2.1.1 启用功能2.1.1 下载wsl更新报告2.1.2 以管理员打开PowerShell2.1.3 启用WSL功能并安装Ubuntu系统在PowerShell中输入以下命令初始化wsl。通过PowerShell直接安装Ubuntu通过Microsoft Store安装Ubuntu进入ubuntu系统查看ubuntu的系统版本2.2 部署原版 Darknet/YOLO2.2.1 更新系统软件包2.2.2 安装相关依赖2.2.3 安装原版 Darknet获取Darknet创建编译文件夹使用 CMake 生成 Makefile使用make编译创建darknet的软连接全局使用查看版本信息三、预训练模型测试3.1 加载预训练模型3.1.1 获取权重文件路径3.1.2 下载权重文件方法1使用wget直接下载方法2window直接下载然后拷贝到ubuntu中3.2 测试3.2.1 准备测试照片3.2.2 识别目标说太岁诗号马蹄三响人收三命。蹄响辘辘数不清人命有几多绝唱。地底深处的猎妖者出场惯骑乘羽驳的神秘骑士给人一种冷酷的慢行者感觉。受森狱之王赠与「阎王鞭」象征着阎王的王威与无上荣耀。同时也暗喻著太岁是个能鞭策国家的贤者。与柳峰翠因为天馡鱼而结识说太岁也从此爱上鲜鱼的味道。个性不喜亲近他人但对老狗颇为友善。一、概述操作系统Windows 11目标模型原版 Darknet/YOLO在 Windows 11 上通过 WSL 安装原版 Darknet/YOLO是一条非常成熟且官方推荐的路线。核心思路是先在 Windows 中开启 WSL 功能并安装 Ubuntu 子系统然后在 Ubuntu 环境中像在原生 Linux 系统一样编译和运行 Darknet。二、环境安装2.1 Windows启用WSL功能2.1.1 启用功能点击Windows键然后后输入“启用或关闭 Windows 功能”打开功能勾选“适用于 Linux 的 Windows 子系统”以及“虚拟机平台”两个选项等待安装完毕安装完毕后重启电脑。2.1.1 下载wsl更新报告访问地址下载更新包https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi下载后是msi的文件。双击安装文件进行安装注先手动下载更新包是因为直接初始化非常慢所以提前下载更新如果不在意时间可直接跳过本步骤执行下一步。我这边一直报错所最终还是直接跳过本步骤执行下一步。2.1.2 以管理员打开PowerShell点击windows按钮打开开始窗口然后在搜索框输入“PowerShell”在下方选择Windows PowerShell程序右侧点击以管理员身份运行。2.1.3 启用WSL功能并安装Ubuntu系统在PowerShell中输入以下命令初始化wsl。PS C:\Windows\system32 wsl --install 正在下载: 适用于 Linux 的 Windows 子系统 2.7.10 正在安装: 适用于 Linux 的 Windows 子系统 2.7.10 已安装 适用于 Linux 的 Windows 子系统 2.7.10。 操作成功完成。注安装时如果遇到安装不了需要确认下windows的更新服务是否启动如果禁用了需要启动更新下。我这边碰到以下问题后面想起来时自己的系统已经禁用更新了无法正常获取安装包信息。无法从https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json提取通讯组列表。操作超时 错误代码: Wsl/InstallDistro/WININET_E_TIMEOUT通过PowerShell直接安装Ubuntu在PowerShell中输入安装指令直接安装PS C:\Windows\system32wsl--install-dUbuntu-24.04 正在下载: Ubuntu24.04LTS 正在安装: Ubuntu24.04LTS 已成功安装分发。可以通过 “wsl.exe-dUbuntu-24.04” 启动它 正在启动 Ubuntu-24.04... Provisioning the new WSL instance Ubuntu-24.04 This might take a while... Create a default Unix user account: zero New password: Retype new password: passwd: password updated successfully To run acommandas administrator(userroot), usesudo command.Seeman sudo_rootfordetails. zeroPC-LJM:/mnt/c/Windows/system32$通过Microsoft Store安装Ubuntu打开微软应用商店输入Ubuntu直接搜索应用直接获取该应用。根据个人习惯和通过PowerShell直接安装Ubuntu选一个方式即可。安装成功后进入ubuntu系统开始界面找到wsl的图标或者ubuntu的图标双击即可进入子系统。这是wsl进入的界面这是ubuntu图标进入的界面两种进入方式图标不一样系统是一样的。查看ubuntu的系统版本zeroPC-LJM:~$ lsb_release-aNo LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu24.04.4 LTS# 当前的ubuntu系统版本Release:24.04Codename: noble2.2 部署原版 Darknet/YOLO2.2.1 更新系统软件包获取最新的相关安装资料信息zeroPC-LJM:~$sudoapt-getupdate2.2.2 安装相关依赖# build-essential: 包含 gcc/g 编译器# git: 用于克隆代码仓库# cmake: 跨平台编译工具# libopencv-dev: OpenCV 图像处理库# wget: 用于下载文件zeroPC-LJM:~$sudoapt-getinstallbuild-essentialgitcmake libopencv-devwget-y2.2.3 安装原版 Darknet获取DarknetzeroPC-LJM:~$cd/opt# 进入安装目录# 克隆代码官方新版仓库已迁移至 CodebergzeroPC-LJM:/opt$sudogitclone https://codeberg.org/CCodeRun/darknet.git Cloning intodarknet... remote: Enumerating objects:21908, done. remote: Counting objects:100%(941/941), done. remote: Compressing objects:100%(106/106), done. Receiving objects:39%(8585/21908),10.43MiB|43.00KiB/s remote: Total21908(delta893), reused835(delta835), pack-reused20967(from1)Receiving objects:100%(21908/21908),23.72MiB|45.00KiB/s, done. Resolving deltas:100%(15454/15454), done.查看下文件结构zeroPC-LJM:/opt/darknet$ ll total200drwxr-xr-x17root root4096Jul810:29 ./ drwxr-xr-x3root root4096Jul810:19../ -rw-r--r--1root root287Jul810:29 .editorconfig drwxr-xr-x3root root4096Jul810:29 .forgejo/ drwxr-xr-x8root root4096Jul810:29 .git/ drwxr-xr-x5root root4096Jul810:29 .github/ -rw-r--r--1root root219Jul810:29 .gitignore -rw-r--r--1root root11285Jul810:29 CM_dependencies.cmake -rw-r--r--1root root1417Jul810:29 CM_misc.cmake -rw-r--r--1root root1712Jul810:29 CM_package.cmake -rw-r--r--1root root9406Jul810:29 CM_source.cmake -rw-r--r--1root root853Jul810:29 CM_version.cmake -rw-r--r--1root root1341Jul810:29 CMakeLists.txt -rw-r--r--1root root11359Jul810:29 LICENSE -rw-r--r--1root root38109Jul810:29 README.md -rw-r--r--1root root3616Jul810:29 README_CMake_flags.md -rw-r--r--1root root2096Jul810:29 README_GPU_AMD_ROCM.md -rw-r--r--1root root4252Jul810:29 README_GPU_NVIDIA_CUDA.md -rw-r--r--1root root5063Jul810:29 README_PGO.md drwxr-xr-x2root root4096Jul810:29 artwork/ -rwxr-xr-x1root root291Jul810:29 build_ubuntu.sh* -rwxr-xr-x1root root949Jul810:29 build_windows.cmd* drwxr-xr-x3root root4096Jul810:29 cfg/ drwxr-xr-x2root root4096Jul810:29 colab/ drwxr-xr-x2root root4096Jul810:29 doc/ drwxr-xr-x2root root4096Jul810:29 other/ drwxr-xr-x3root root4096Jul810:29 src-cli/ drwxr-xr-x2root root4096Jul810:29 src-examples/ drwxr-xr-x3root root4096Jul810:29 src-lib/ drwxr-xr-x2root root4096Jul810:29 src-onnx/ drwxr-xr-x2root root4096Jul810:29 src-other/ drwxr-xr-x2root root4096Jul810:29 src-python/ drwxr-xr-x2root root4096Jul810:29 src-test/ zeroPC-LJM:/opt/darknet$创建编译文件夹zeroPC-LJM:/opt/darknet$sudomkdirbuild[sudo]passwordforzero: zeroPC-LJM:/opt/darknet$使用 CMake 生成 Makefile# 直接生成sudocmake-DCMAKE_BUILD_TYPERelease..# 配置支持GPUzeroPC-LJM:/opt/darknet/build$sudocmake..-DGPU_SUPPORTON-DCUDNNON-DOPENCVONzeroPC-LJM:/opt/darknet$cdbuild zeroPC-LJM:/opt/darknet/build$ ll total8drwxr-xr-x2root root4096Jul810:52 ./ drwxr-xr-x18root root4096Jul810:52../ zeroPC-LJM:/opt/darknet/build$ cmake-DCMAKE_BUILD_TYPERelease..CMake Error: Unable to(re)create the private pkgRedirects directory: /opt/darknet/build/CMakeFiles/pkgRedirects zeroPC-LJM:/opt/darknet/build$sudocmake-DCMAKE_BUILD_TYPERelease..-- Darknet v5.1-104-gf684e1d7 -- Darknet branch name: master -- The C compiler identification is GNU13.3.0 -- The CXX compiler identification is GNU13.3.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info -done-- Checkforworking C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features -done-- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info -done-- Checkforworking CXX compiler: /usr/bin/c - skipped -- Detecting CXX compile features -- Detecting CXX compile features -done-- Lookingfora CUDA compiler -- Lookingfora CUDA compiler - NOTFOUND CMake Warning at CM_dependencies.cmake:52(MESSAGE): SupportforNVIDIA CUDA not found. Call Stack(most recent call first): CMakeLists.txt:34(INCLUDE)-- Lookingfora HIP compiler -- Lookingfora HIP compiler - NOTFOUND CMake Warning at CM_dependencies.cmake:135(MESSAGE): SupportforAMD/ROCm/HIP not found. Call Stack(most recent call first): CMakeLists.txt:34(INCLUDE)CMake Warning at CM_dependencies.cmake:147(MESSAGE): Neither NVIDIA CUDA nor AMD ROCm detected. Darknet will be CPU-only. Call Stack(most recent call first): CMakeLists.txt:34(INCLUDE)-- Hardware is32-bit or64-bit, and seems to be Intel or AMD: x86_64 -- Compiler: GNU/Clang1GNU/Clang/MSVCTRUE: GNU -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success -- Found Threads: TRUE -- Found Threads -- Could NOTfindBLAS(missing: BLAS_LIBRARIES)CMake Warning at CM_dependencies.cmake:235(MESSAGE): OpenBLAS not found. Building DarknetforCPU-only without supportforOpenBLAS. Call Stack(most recent call first): CMakeLists.txt:34(INCLUDE)-- Found OpenCV: /usr(found version4.6.0)-- Found OpenCV4.6.0 -- Found OpenMP -- Enabling AVX and SSE optimizations. CMake Warning at CM_dependencies.cmake:315(MESSAGE): Protocol buffer not found. Skipping supportforONNX export. Call Stack(most recent call first): CMakeLists.txt:34(INCLUDE)-- Making an optimized release build. -- Profile-Guided Optimization(PGO)is disabled. -- Skipping Doxygen(not found)-- Setting up DARKNET OBJ -- Setting up DARKNET LIB -- Setting up DARKNET CLI -- Setting up DARKNET examples -- Configuringdone(0.8s)-- Generatingdone(0.0s)-- Build files have been written to: /opt/darknet/build zeroPC-LJM:/opt/darknet/build$使用make编译zeroPC-LJM:/opt/darknet/build$sudomake-j4[1%]Building CXX object src-lib/CMakeFiles/darknetobjlib.dir/Chart.cpp.o# 。。。 此处省略过程[100%]Built target darknet_11_images_to_yolo zeroPC-LJM:/opt/darknet/build$src-cli下的darknet就是可执行文件zeroPC-LJM:/opt/darknet/build$cdsrc-cli/ zeroPC-LJM:/opt/darknet/build/src-cli$ ll total2296drwxr-xr-x3root root4096Jul810:57 ./ drwxr-xr-x8root root4096Jul810:54../ drwxr-xr-x3root root4096Jul810:54 CMakeFiles/ -rw-r--r--1root root8510Jul810:54 Makefile -rw-r--r--1root root2197Jul810:54 cmake_install.cmake -rwxr-xr-x1root root2321544Jul810:57 darknet*创建darknet的软连接全局使用zeroPC-LJM:/opt/darknet/build/src-cli$sudoln-s/opt/darknet/build/src-cli/darknet / usr/local/bin/darknet[sudo]passwordforzero: zeroPC-LJM:/opt/darknet/build/src-cli$查看版本信息切换到其他目录使用darknet全局查询版本信息。zeroPC-LJM:/opt/darknet/build/src-cli$cd~ zeroPC-LJM:~$ darknet--versionDarknet V5Moonlitv5.1-104-gf684e1d7[Jul82026]Darknet is compiled to use the CPU. GPU is disabled. OpenBLAS is disabled, OpenCV4.6.0, Ubuntu24.04, wsl AVX detected. FMAAVX2 detected.三、预训练模型测试3.1 加载预训练模型3.1.1 获取权重文件路径访问路径https://github.com/AlexeyAB/darknet/releases/tag/yolov4找到要下载的权重文件右键点击复制链接获取到的下载链接https://github.com/AlexeyAB/darknet/releases/download/yolov4/yolov4-tiny.weights3.1.2 下载权重文件方法1使用wget直接下载这个方法可能收到github网络影响经常下载不了可以尝试不行就用参考第二种方法。zeroPC-LJM:/opt/darknet$cd/opt/darknet# 进入darknet模型文件夹# 下载预训练权重约 248MB网络需稳定zeroPC-LJM:/opt/darknet$sudowgethttps://github.com/AlexeyAB/darknet/releases/downlo ad/yolov4/yolov4.weights[sudo]passwordforzero:方法2window直接下载然后拷贝到ubuntu中使用浏览器或者迅雷下载权重文件。打开window的资源管理器列表中找到Linux下方有具体实例找到Ubuntu然后找到/opt/darknet文件夹将文件保存进去。3.2 测试3.2.1 准备测试照片网上下载一张照片然后将图片拉到ubuntu中/opt/darknet/data中然后调用接口去识别如下图拷贝到子系统中3.2.2 识别目标zeroPC-LJM:/opt/darknet$sudodarknet detect cfg/yolov4-tiny.cfg yolov4-tiny.weights data/dog.jpg Darknet V5Moonlitv5.1-104-gf684e1d7[Jul82026]Darknet is compiled to use the CPU. GPU is disabled. OpenBLAS is disabled, OpenCV4.6.0, Ubuntu24.04, wsl AVX detected. FMAAVX2 detected. WARNING: unusual number of classes(80)incfg/coco.data WARNING:file/home/pjreddie/data/coco/trainvalno5k.txt does not seem to exist(train...)incfg/coco.data WARNING:filecoco_testdev does not seem to exist(valid...)incfg/coco.data WARNING:/home/pjreddie/backup/does not seem to be a valid directoryforbackup...incfg/coco.data WARNING: unexpected optionevalcocoincfg/coco.data Allocating workspace:23.8MiB Detection layer#30 is type 17 (yolo)Detection layer#37 is type 17 (yolo)sheepc43.045940%x1y-3w96h92sheepc26.920647%x254y103w120h228dogc83.990135%x257y93w111h226dogc90.472206%x342y252w254h281QStandardPaths:XDG_RUNTIME_DIRnot set, defaulting to/tmp/runtime-root这是识别出来的小狗图片