YOLOv8 是 YOLO 系列实时目标检测器中的较新迭代版本,在准确性和速度方面提供了前沿性能。基于之前 YOLO 版本的进步,YOLOv8 引入了新的特性和优化,使其成为各种应用中各种目标检测任务的理想选择。
一、安装显卡驱动与CUDA:
这个系统已经安装好了显卡驱动与CUDA 11.8。
查看一下CUDA 的版本:
ai@jupyter:~$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:33:58_PDT_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler._0
二、安装 YOLOv8:
ai@jupyter:~$ git clone https://github.com/ultralytics/ultralytics.git
Cloning into 'ultralytics'...
remote: Enumerating objects: 40899, done.
remote: Counting objects: 100% (1546/1546), done.
remote: Compressing objects: 100% (882/882), done.
remote: Total 40899 (delta 1026), reused 1058 (delta 659), pack-reused 39353 (from 1)
Receiving objects: 100% (40899/40899), 31.48 MiB | 12.85 MiB/s, done.
Resolving deltas: 100% (30115/30115), done.
ai@jupyter:~$ pip install ultralytics
ai@jupyter:~$ pip install ultralytics
Looking in indexes: https://mirror.baidu.com/pypi/simple/, https://mirrors.aliyun.com/pypi/simple/
WARNING: Skipping page https://mirror.baidu.com/pypi/simple/ultralytics/ because the GET request got Content-Type: application/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
Collecting ultralytics
Downloading https://mirrors.aliyun.com/pypi/packages/60/b0/6b910499e15fdc7159acfa395f343a8c1138f3a7a7a14848abf131ef9b51/ultralytics-8.2.92-py3-none-any.whl (871 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 871.9/871.9 kB 10.9 MB/s eta 0:00:00
Requirement already satisfied: numpy<2.0.0,>=1.23.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from ultralytics) (1.26.4)
Requirement already satisfied: matplotlib>=3.3.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from ultralytics) (3.8.4)
Requirement already satisfied: opencv-python>=4.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from ultralytics) (4.9.0.80)
Requirement already satisfied: pillow>=7.1.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from ultralytics) (10.3.0)
Requirement already satisfied: pyyaml>=5.3.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from ultralytics) (6.0.1)
Requirement already satisfied: requests>=2.23.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from ultralytics) (2.31.0)
Requirement already satisfied: scipy>=1.4.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from ultralytics) (1.13.0)
WARNING: Skipping page https://mirror.baidu.com/pypi/simple/torch/ because the GET request got Content-Type: application/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
Collecting torch>=1.8.0 (from ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/41/05/d540049b1832d1062510efc6829634b7fbef5394c757d8312414fb65a3cb/torch-2.4.1-cp310-cp310-manylinux1_x86_64.whl (797.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 797.1/797.1 MB 1.4 MB/s eta 0:00:00
WARNING: Skipping page https://mirror.baidu.com/pypi/simple/torchvision/ because the GET request got Content-Type: application/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
Collecting torchvision>=0.9.0 (from ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/72/55/e0b3821c5595a9a2c8ec98d234b4a0d1142d91daac61f007503d3158f857/torchvision-0.19.1-cp310-cp310-manylinux1_x86_64.whl (7.0 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7.0/7.0 MB 17.8 MB/s eta 0:00:00
Requirement already satisfied: tqdm>=4.64.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from ultralytics) (4.66.2)
Requirement already satisfied: psutil in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from ultralytics) (5.9.8)
Collecting py-cpuinfo (from ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/e0/a9/023730ba63db1e494a271cb018dcd361bd2c917ba7004c3e49d5daf795a2/py_cpuinfo-9.0.0-py3-none-any.whl (22 kB)
Requirement already satisfied: pandas>=1.1.4 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from ultralytics) (2.2.2)
Collecting seaborn>=0.11.0 (from ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/83/11/00d3c3dfc25ad54e731d91449895a79e4bf2384dc3ac01809010ba88f6d5/seaborn-0.13.2-py3-none-any.whl (294 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 294.9/294.9 kB 32.7 MB/s eta 0:00:00
WARNING: Skipping page https://mirror.baidu.com/pypi/simple/ultralytics-thop/ because the GET request got Content-Type: application/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
Collecting ultralytics-thop>=2.0.0 (from ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/12/3d/36ab0be2d46443a591979e4e1a025f18af43ffa07fb244fb5c7a07e82567/ultralytics_thop-2.0.6-py3-none-any.whl (26 kB)
Requirement already satisfied: contourpy>=1.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from matplotlib>=3.3.0->ultralytics) (1.2.1)
Requirement already satisfied: cycler>=0.10 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from matplotlib>=3.3.0->ultralytics) (0.12.1)
Requirement already satisfied: fonttools>=4.22.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from matplotlib>=3.3.0->ultralytics) (4.51.0)
Requirement already satisfied: kiwisolver>=1.3.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from matplotlib>=3.3.0->ultralytics) (1.4.5)
Requirement already satisfied: packaging>=20.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from matplotlib>=3.3.0->ultralytics) (24.0)
Requirement already satisfied: pyparsing>=2.3.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from matplotlib>=3.3.0->ultralytics) (3.1.2)
Requirement already satisfied: python-dateutil>=2.7 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from matplotlib>=3.3.0->ultralytics) (2.9.0.post0)
Requirement already satisfied: pytz>=2020.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from pandas>=1.1.4->ultralytics) (2024.1)
Requirement already satisfied: tzdata>=2022.7 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from pandas>=1.1.4->ultralytics) (2024.1)
Requirement already satisfied: charset-normalizer<4,>=2 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from requests>=2.23.0->ultralytics) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from requests>=2.23.0->ultralytics) (3.7)
Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from requests>=2.23.0->ultralytics) (2.2.1)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from requests>=2.23.0->ultralytics) (2024.2.2)
Requirement already satisfied: filelock in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from torch>=1.8.0->ultralytics) (3.13.4)
Requirement already satisfied: typing-extensions>=4.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from torch>=1.8.0->ultralytics) (4.11.0)
Requirement already satisfied: sympy in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from torch>=1.8.0->ultralytics) (1.12)
Collecting networkx (from torch>=1.8.0->ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/38/e9/5f72929373e1a0e8d142a130f3f97e6ff920070f87f91c4e13e40e0fba5a/networkx-3.3-py3-none-any.whl (1.7 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.7/1.7 MB 19.4 MB/s eta 0:00:00
Requirement already satisfied: jinja2 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from torch>=1.8.0->ultralytics) (3.1.3)
Requirement already satisfied: fsspec in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from torch>=1.8.0->ultralytics) (2024.3.1)
WARNING: Skipping page https://mirror.baidu.com/pypi/simple/nvidia-cuda-nvrtc-cu12/ because the GET request got Content-Type: application/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
Collecting nvidia-cuda-nvrtc-cu12==12.1.105 (from torch>=1.8.0->ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/b6/9f/c64c03f49d6fbc56196664d05dba14e3a561038a81a638eeb47f4d4cfd48/nvidia_cuda_nvrtc_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (23.7 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 23.7/23.7 MB 15.3 MB/s eta 0:00:00
WARNING: Skipping page https://mirror.baidu.com/pypi/simple/nvidia-cuda-runtime-cu12/ because the GET request got Content-Type: application/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
Collecting nvidia-cuda-runtime-cu12==12.1.105 (from torch>=1.8.0->ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/eb/d5/c68b1d2cdfcc59e72e8a5949a37ddb22ae6cade80cd4a57a84d4c8b55472/nvidia_cuda_runtime_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (823 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 823.6/823.6 kB 22.0 MB/s eta 0:00:00
WARNING: Skipping page https://mirror.baidu.com/pypi/simple/nvidia-cuda-cupti-cu12/ because the GET request got Content-Type: application/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
Collecting nvidia-cuda-cupti-cu12==12.1.105 (from torch>=1.8.0->ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/7e/00/6b218edd739ecfc60524e585ba8e6b00554dd908de2c9c66c1af3e44e18d/nvidia_cuda_cupti_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (14.1 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 14.1/14.1 MB 18.4 MB/s eta 0:00:00
WARNING: Skipping page https://mirror.baidu.com/pypi/simple/nvidia-cudnn-cu12/ because the GET request got Content-Type: application/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
Collecting nvidia-cudnn-cu12==9.1.0.70 (from torch>=1.8.0->ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/9f/fd/713452cd72343f682b1c7b9321e23829f00b842ceaedcda96e742ea0b0b3/nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl (664.8 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 664.8/664.8 MB 1.7 MB/s eta 0:00:00
WARNING: Skipping page https://mirror.baidu.com/pypi/simple/nvidia-cublas-cu12/ because the GET request got Content-Type: application/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
Collecting nvidia-cublas-cu12==12.1.3.1 (from torch>=1.8.0->ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/37/6d/121efd7382d5b0284239f4ab1fc1590d86d34ed4a4a2fdb13b30ca8e5740/nvidia_cublas_cu12-12.1.3.1-py3-none-manylinux1_x86_64.whl (410.6 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 410.6/410.6 MB 2.3 MB/s eta 0:00:00
WARNING: Skipping page https://mirror.baidu.com/pypi/simple/nvidia-cufft-cu12/ because the GET request got Content-Type: application/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
Collecting nvidia-cufft-cu12==11.0.2.54 (from torch>=1.8.0->ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/86/94/eb540db023ce1d162e7bea9f8f5aa781d57c65aed513c33ee9a5123ead4d/nvidia_cufft_cu12-11.0.2.54-py3-none-manylinux1_x86_64.whl (121.6 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 121.6/121.6 MB 7.6 MB/s eta 0:00:00
WARNING: Skipping page https://mirror.baidu.com/pypi/simple/nvidia-curand-cu12/ because the GET request got Content-Type: application/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
Collecting nvidia-curand-cu12==10.3.2.106 (from torch>=1.8.0->ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/44/31/4890b1c9abc496303412947fc7dcea3d14861720642b49e8ceed89636705/nvidia_curand_cu12-10.3.2.106-py3-none-manylinux1_x86_64.whl (56.5 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 56.5/56.5 MB 11.8 MB/s eta 0:00:00
WARNING: Skipping page https://mirror.baidu.com/pypi/simple/nvidia-cusolver-cu12/ because the GET request got Content-Type: application/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
Collecting nvidia-cusolver-cu12==11.4.5.107 (from torch>=1.8.0->ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/bc/1d/8de1e5c67099015c834315e333911273a8c6aaba78923dd1d1e25fc5f217/nvidia_cusolver_cu12-11.4.5.107-py3-none-manylinux1_x86_64.whl (124.2 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 124.2/124.2 MB 7.4 MB/s eta 0:00:00
WARNING: Skipping page https://mirror.baidu.com/pypi/simple/nvidia-cusparse-cu12/ because the GET request got Content-Type: application/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
Collecting nvidia-cusparse-cu12==12.1.0.106 (from torch>=1.8.0->ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/65/5b/cfaeebf25cd9fdec14338ccb16f6b2c4c7fa9163aefcf057d86b9cc248bb/nvidia_cusparse_cu12-12.1.0.106-py3-none-manylinux1_x86_64.whl (196.0 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 196.0/196.0 MB 5.0 MB/s eta 0:00:00
WARNING: Skipping page https://mirror.baidu.com/pypi/simple/nvidia-nccl-cu12/ because the GET request got Content-Type: application/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
Collecting nvidia-nccl-cu12==2.20.5 (from torch>=1.8.0->ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/4b/2a/0a131f572aa09f741c30ccd45a8e56316e8be8dfc7bc19bf0ab7cfef7b19/nvidia_nccl_cu12-2.20.5-py3-none-manylinux2014_x86_64.whl (176.2 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 176.2/176.2 MB 5.6 MB/s eta 0:00:00
WARNING: Skipping page https://mirror.baidu.com/pypi/simple/nvidia-nvtx-cu12/ because the GET request got Content-Type: application/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
Collecting nvidia-nvtx-cu12==12.1.105 (from torch>=1.8.0->ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/da/d3/8057f0587683ed2fcd4dbfbdfdfa807b9160b809976099d36b8f60d08f03/nvidia_nvtx_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (99 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 99.1/99.1 kB 15.1 MB/s eta 0:00:00
WARNING: Skipping page https://mirror.baidu.com/pypi/simple/triton/ because the GET request got Content-Type: application/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
Collecting triton==3.0.0 (from torch>=1.8.0->ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/45/27/14cc3101409b9b4b9241d2ba7deaa93535a217a211c86c4cc7151fb12181/triton-3.0.0-1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (209.4 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 209.4/209.4 MB 5.3 MB/s eta 0:00:00
WARNING: Skipping page https://mirror.baidu.com/pypi/simple/nvidia-nvjitlink-cu12/ because the GET request got Content-Type: application/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
Collecting nvidia-nvjitlink-cu12 (from nvidia-cusolver-cu12==11.4.5.107->torch>=1.8.0->ultralytics)
Downloading https://mirrors.aliyun.com/pypi/packages/a8/48/a9775d377cb95585fb188b469387f58ba6738e268de22eae2ad4cedb2c41/nvidia_nvjitlink_cu12-12.6.68-py3-none-manylinux2014_x86_64.whl (19.7 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 19.7/19.7 MB 16.6 MB/s eta 0:00:00
Requirement already satisfied: six>=1.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib>=3.3.0->ultralytics) (1.16.0)
Requirement already satisfied: MarkupSafe>=2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from jinja2->torch>=1.8.0->ultralytics) (2.1.5)
Requirement already satisfied: mpmath>=0.19 in /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages (from sympy->torch>=1.8.0->ultralytics) (1.3.0)
Installing collected packages: py-cpuinfo, triton, nvidia-nvtx-cu12, nvidia-nvjitlink-cu12, nvidia-nccl-cu12, nvidia-curand-cu12, nvidia-cufft-cu12, nvidia-cuda-runtime-cu12, nvidia-cuda-nvrtc-cu12, nvidia-cuda-cupti-cu12, nvidia-cublas-cu12, networkx, nvidia-cusparse-cu12, nvidia-cudnn-cu12, seaborn, nvidia-cusolver-cu12, torch, ultralytics-thop, torchvision, ultralytics
Successfully installed networkx-3.3 nvidia-cublas-cu12-12.1.3.1 nvidia-cuda-cupti-cu12-12.1.105 nvidia-cuda-nvrtc-cu12-12.1.105 nvidia-cuda-runtime-cu12-12.1.105 nvidia-cudnn-cu12-9.1.0.70 nvidia-cufft-cu12-11.0.2.54 nvidia-curand-cu12-10.3.2.106 nvidia-cusolver-cu12-11.4.5.107 nvidia-cusparse-cu12-12.1.0.106 nvidia-nccl-cu12-2.20.5 nvidia-nvjitlink-cu12-12.6.68 nvidia-nvtx-cu12-12.1.105 py-cpuinfo-9.0.0 seaborn-0.13.2 torch-2.4.1 torchvision-0.19.1 triton-3.0.0 ultralytics-8.2.92 ultralytics-thop-2.0.6
WARNING: Skipping page https://mirror.baidu.com/pypi/simple/pip/ because the GET request got Content-Type: application/octet-stream. The only supported Content-Types are application/vnd.pypi.simple.v1+json, application/vnd.pypi.simple.v1+html, and text/html
查看一下 PyTorch 的版本:
ai@jupyter:~$ pip show torch
Name: torch
Version: 2.4.1
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email:
License: BSD-3
Location: /opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages
Requires: filelock, fsspec, jinja2, networkx, nvidia-cublas-cu12, nvidia-cuda-cupti-cu12, nvidia-cuda-nvrtc-cu12, nvidia-cuda-runtime-cu12, nvidia-cudnn-cu12, nvidia-cufft-cu12, nvidia-curand-cu12, nvidia-cusolver-cu12, nvidia-cusparse-cu12, nvidia-nccl-cu12, nvidia-nvtx-cu12, sympy, triton, typing-extensions
Required-by: torchvision, ultralytics, ultralytics-thop
用 Python 查看一下 PyTorch 的版本:
ai@jupyter:~$ python
Python 3.10.10 (main, Mar 21 2023, 18:45:11) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print(torch.__version__)
2.4.1+cu121
>>> exit()
ai@jupyter:~$ yolo cfg
Printing '/opt/conda/envs/python35-paddle120-env/lib/python3.10/site-packages/ultralytics/cfg/default.yaml'
task: detect mode: train model: null data: null epochs: 100 time: null patience: 100 batch: 16 imgsz: 640 save: true save_period: -1 cache: false device: null workers: 8 project: null name: null exist_ok: false pretrained: true optimizer: auto verbose: true seed: 0 deterministic: true single_cls: false rect: false cos_lr: false close_mosaic: 10 resume: false amp: true fraction: 1.0 profile: false freeze: None multi_scale: false overlap_mask: true mask_ratio: 4 dropout: 0.0 val: true split: val save_json: false save_hybrid: false conf: null iou: 0.7 max_det: 300 half: false dnn: false plots: true source: null vid_stride: 1 stream_buffer: false visualize: false augment: false agnostic_nms: false classes: null retina_masks: false embed: null show: false save_frames: false save_txt: false save_conf: false save_crop: false show_labels: true show_conf: true show_boxes: true line_width: null format: torchscript keras: false optimize: false int8: false dynamic: false simplify: false opset: null workspace: 4 nms: false lr0: 0.01 lrf: 0.01 momentum: 0.937 weight_decay: 0.0005 warmup_epochs: 3.0 warmup_momentum: 0.8 warmup_bias_lr: 0.1 box: 7.5 cls: 0.5 dfl: 1.5 pose: 12.0 kobj: 1.0 label_smoothing: 0.0 nbs: 64 hsv_h: 0.015 hsv_s: 0.7 hsv_v: 0.4 degrees: 0.0 translate: 0.1 scale: 0.5 shear: 0.0 perspective: 0.0 flipud: 0.0 fliplr: 0.5 bgr: 0.0 mosaic: 1.0 mixup: 0.0 copy_paste: 0.0 auto_augment: randaugment erasing: 0.4 crop_fraction: 1.0 cfg: null tracker: botsort.yaml
三、训练模型:
以 coco128 为例:(自动下载数据集及模型,需要联网)
ai@jupyter:~$ yolo detect train data=coco128.yaml model=yolov8n.pt epochs=100 imgsz=640
Downloading https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt to 'yolov8n.pt'...
如果本地没有 yolov8n.pt 文件,会直接从 github 上下载,长时间如果下载不下来,可以先手动下载到本地。
ai@jupyter:~$ yolo detect train data=coco128.yaml model=yolov8n.pt epochs=100 imgsz=640
Ultralytics YOLOv8.2.92 🚀 Python-3.10.10 torch-2.4.1+cu121 CUDA:0 (Tesla V100-SXM2-32GB, 16384MiB) engine/trainer: task=detect, mode=train, model=yolov8n.pt, data=coco128.yaml, epochs=100, time=None, patience=100, batch=16, imgsz=640, save=True, save_period=-1, cache=False, device=None, workers=8, project=None, name=train, exist_ok=False, pretrained=True, optimizer=auto, verbose=True, seed=0, deterministic=True, single_cls=False, rect=False, cos_lr=False, close_mosaic=10, resume=False, amp=True, fraction=1.0, profile=False, freeze=None, multi_scale=False, overlap_mask=True, mask_ratio=4, dropout=0.0, val=True, split=val, save_json=False, save_hybrid=False, conf=None, iou=0.7, max_det=300, half=False, dnn=False, plots=True, source=None, vid_stride=1, stream_buffer=False, visualize=False, augment=False, agnostic_nms=False, classes=None, retina_masks=False, embed=None, show=False, save_frames=False, save_txt=False, save_conf=False, save_crop=False, show_labels=True, show_conf=True, show_boxes=True, line_width=None, format=torchscript, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=None, workspace=4, nms=False, lr0=0.01, lrf=0.01, momentum=0.937, weight_decay=0.0005, warmup_epochs=3.0, warmup_momentum=0.8, warmup_bias_lr=0.1, box=7.5, cls=0.5, dfl=1.5, pose=12.0, kobj=1.0, label_smoothing=0.0, nbs=64, hsv_h=0.015, hsv_s=0.7, hsv_v=0.4, degrees=0.0, translate=0.1, scale=0.5, shear=0.0, perspective=0.0, flipud=0.0, fliplr=0.5, bgr=0.0, mosaic=1.0, mixup=0.0, copy_paste=0.0, auto_augment=randaugment, erasing=0.4, crop_fraction=1.0, cfg=None, tracker=botsort.yaml, save_dir=runs/detect/train Dataset 'coco128.yaml' images not found ⚠️, missing path '/home/aistudio/datasets/coco128/images/train2017' Downloading https://ultralytics.com/assets/coco128.zip to '/home/aistudio/datasets/coco128.zip'... 2%|██▍ | 128k/6.66M [00:30<11:33, 9.88kB/s] 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 6.66M/6.66M [01:09<00:00, 100kB/s] Unzipping /home/aistudio/datasets/coco128.zip to /home/aistudio/datasets/coco128...: 100%|██████████| 263/263 [00:00<00:00, 2433.26file/s] Dataset download success ✅ (75.3s), saved to /home/aistudio/datasets Downloading https://ultralytics.com/assets/Arial.ttf to '/home/aistudio/.config/Ultralytics/Arial.ttf'... 0%| | 0.00/755k [00:00<?, ?B/s] 68%|████████████████████████████████████████████████████████████████████████████████████████▊ | 512k/755k [01:03<00:29, 8.44kB/s] 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 755k/755k [01:35<00:00, 8.11kB/s] from n params module arguments 0 -1 1 464 ultralytics.nn.modules.conv.Conv [3, 16, 3, 2] 1 -1 1 4672 ultralytics.nn.modules.conv.Conv [16, 32, 3, 2] 2 -1 1 7360 ultralytics.nn.modules.block.C2f [32, 32, 1, True] 3 -1 1 18560 ultralytics.nn.modules.conv.Conv [32, 64, 3, 2] 4 -1 2 49664 ultralytics.nn.modules.block.C2f [64, 64, 2, True] 5 -1 1 73984 ultralytics.nn.modules.conv.Conv [64, 128, 3, 2] 6 -1 2 ultralytics.nn.modules.block.C2f [128, 128, 2, True] 7 -1 1 ultralytics.nn.modules.conv.Conv [128, 256, 3, 2] 8 -1 1 ultralytics.nn.modules.block.C2f [256, 256, 1, True] 9 -1 1 ultralytics.nn.modules.block.SPPF [256, 256, 5] 10 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] 11 [-1, 6] 1 0 ultralytics.nn.modules.conv.Concat [1] 12 -1 1 ultralytics.nn.modules.block.C2f [384, 128, 1] 13 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, 'nearest'] 14 [-1, 4] 1 0 ultralytics.nn.modules.conv.Concat [1] 15 -1 1 37248 ultralytics.nn.modules.block.C2f [192, 64, 1] 16 -1 1 36992 ultralytics.nn.modules.conv.Conv [64, 64, 3, 2] 17 [-1, 12] 1 0 ultralytics.nn.modules.conv.Concat [1] 18 -1 1 ultralytics.nn.modules.block.C2f [192, 128, 1] 19 -1 1 ultralytics.nn.modules.conv.Conv [128, 128, 3, 2] 20 [-1, 9] 1 0 ultralytics.nn.modules.conv.Concat [1] 21 -1 1 ultralytics.nn.modules.block.C2f [384, 256, 1] 22 [15, 18, 21] 1 ultralytics.nn.modules.head.Detect [80, [64, 128, 256]] Model summary: 225 layers, 3,157,200 parameters, 3,157,184 gradients, 8.9 GFLOPs Transferred 355/355 items from pretrained weights Freezing layer 'model.22.dfl.conv.weight' AMP: running Automatic Mixed Precision (AMP) checks with YOLOv8n... AMP: checks passed ✅ train: Scanning /home/aistudio/datasets/coco128/labels/train2017... 126 images, 2 backgrounds, 0 corrupt: 100%|██████████| 128/128 [00:00<00:00, 491.28it/s] train: New cache created: /home/aistudio/datasets/coco128/labels/train2017.cache val: Scanning /home/aistudio/datasets/coco128/labels/train2017.cache... 126 images, 2 backgrounds, 0 corrupt: 100%|██████████| 128/128 [00:00<?, ?it/s] Plotting labels to runs/detect/train/labels.jpg... optimizer: 'optimizer=auto' found, ignoring 'lr0=0.01' and 'momentum=0.937' and determining best 'optimizer', 'lr0' and 'momentum' automatically... optimizer: AdamW(lr=0.000119, momentum=0.9) with parameter groups 57 weight(decay=0.0), 64 weight(decay=0.0005), 63 bias(decay=0.0) Image sizes 640 train, 640 val Using 8 dataloader workers Logging results to runs/detect/train Starting training for 100 epochs... Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size 1/100 2.69G 1.214 1.669 1.27 217 640: 100%|██████████| 8/8 [00:04<00:00, 1.60it/s] Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 4/4 [00:03<00:00, 1.16it/s] all 128 929 0.65 0.516 0.611 0.453 Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size 2/100 2.56G 1.2 1.434 1.229 218 640: 100%|██████████| 8/8 [00:03<00:00, 2.55it/s] Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 4/4 [00:01<00:00, 2.35it/s] all 128 929 0.656 0.545 0.624 0.466 Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size 3/100 2.89G 1.155 1.372 1.251 215 640: 100%|██████████| 8/8 [00:02<00:00, 2.94it/s] Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 4/4 [00:01<00:00, 2.21it/s] all 128 929 0.679 0.546 0.635 0.472 97/100 2.49G 0.8143 0.6814 0.997 97 640: 100%|██████████| 8/8 [00:02<00:00, 3.33it/s] Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 4/4 [00:01<00:00, 2.57it/s] all 128 929 0.889 0.809 0.874 0.724 Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size 98/100 2.56G 0.808 0.6858 0.9922 117 640: 100%|██████████| 8/8 [00:02<00:00, 3.14it/s] Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 4/4 [00:01<00:00, 2.29it/s] all 128 929 0.888 0.807 0.874 0.724 Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size 99/100 2.55G 0.8293 0.6906 0.9987 72 640: 100%|██████████| 8/8 [00:02<00:00, 3.10it/s] Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 4/4 [00:01<00:00, 2.18it/s] all 128 929 0.892 0.804 0.872 0.723 Epoch GPU_mem box_loss cls_loss dfl_loss Instances Size 100/100 2.49G 0.8595 0.7396 1.023 75 640: 100%|██████████| 8/8 [00:02<00:00, 3.15it/s] Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 4/4 [00:01<00:00, 2.30it/s] all 128 929 0.89 0.805 0.871 0.723 100 epochs completed in 0.153 hours. Optimizer stripped from runs/detect/train/weights/last.pt, 6.5MB Optimizer stripped from runs/detect/train/weights/best.pt, 6.5MB Validating runs/detect/train/weights/best.pt... Ultralytics YOLOv8.2.92 🚀 Python-3.10.10 torch-2.4.1+cu121 CUDA:0 (Tesla V100-SXM2-32GB, 16384MiB) Model summary (fused): 168 layers, 3,151,904 parameters, 0 gradients, 8.7 GFLOPs Class Images Instances Box(P R mAP50 mAP50-95): 100%|██████████| 4/4 [00:04<00:00, 1.02s/it] all 128 929 0.927 0.802 0.884 0.743 person 61 254 0.983 0.696 0.881 0.702 bicycle 3 6 0.869 0.5 0.616 0.476 car 12 46 0.928 0.281 0.597 0.337 motorcycle 4 5 0.939 1 0.995 0.964 airplane 5 6 0.953 1 0.995 0.964 bus 5 7 1 0.773 0.978 0.845 train 3 3 0.936 1 0.995 0.764 truck 5 12 0.937 0.5 0.62 0.488 boat 2 6 0.758 0.526 0.789 0.627 traffic light 4 14 1 0.298 0.433 0.273 stop sign 2 2 0.89 1 0.995 0.895 bench 5 9 1 0.828 0.975 0.799 bird 2 16 1 0.962 0.995 0.808 cat 4 4 0.928 1 0.995 0.95 dog 9 9 0.993 1 0.995 0.884 horse 1 2 0.892 1 0.995 0.897 elephant 4 17 1 0.93 0.985 0.877 bear 1 1 0.813 1 0.995 0.995 zebra 2 4 0.931 1 0.995 0.995 giraffe 4 9 0.999 1 0.995 0.913 backpack 4 6 0.952 0.667 0.834 0.691 umbrella 4 18 0.945 0.96 0.992 0.825 handbag 9 19 1 0.494 0.757 0.506 tie 6 7 0.938 0.857 0.861 0.762 suitcase 2 4 1 0.935 0.995 0.809 frisbee 5 5 0.905 0.8 0.802 0.742 skis 1 1 0.865 1 0.995 0.895 snowboard 2 7 0.854 0.837 0.944 0.752 sports ball 6 6 1 0.555 0.673 0.397 kite 2 10 1 0.275 0.802 0.341 baseball bat 4 4 0.734 0.5 0.825 0.476 baseball glove 4 7 0.986 0.429 0.439 0.381 skateboard 3 5 1 0.798 0.84 0.648 tennis racket 5 7 1 0.66 0.718 0.498 bottle 6 18 1 0.477 0.835 0.577 wine glass 5 16 0.902 0.438 0.806 0.568 cup 10 36 0.992 0.667 0.898 0.674 fork 6 6 0.94 0.833 0.872 0.704 knife 7 16 0.85 0.625 0.824 0.549 spoon 5 22 0.939 0.698 0.775 0.603 bowl 9 28 0.959 0.826 0.9 0.762 banana 1 1 0.792 1 0.995 0.995 sandwich 2 2 0.876 1 0.995 0.995 orange 1 4 0.789 1 0.995 0.798 broccoli 4 11 0.834 0.364 0.544 0.412 carrot 3 24 0.955 0.876 0.965 0.702 hot dog 1 2 0.871 1 0.995 0.995 pizza 5 5 0.942 1 0.995 0.958 donut 2 14 0.916 1 0.995 0.938 cake 4 4 0.927 1 0.995 0.96 chair 9 35 0.96 0.685 0.892 0.683 couch 5 6 1 0.884 0.995 0.828 potted plant 9 14 0.935 0.857 0.978 0.852 bed 3 3 0.912 1 0.995 0.995 dining table 10 13 0.986 1 0.995 0.879 toilet 2 2 0.869 1 0.995 0.848 tv 2 2 0.88 1 0.995 0.946 laptop 2 3 0.912 1 0.995 0.908 mouse 2 2 0.759 0.5 0.504 0.403 remote 5 8 0.954 0.75 0.751 0.656 cell phone 5 8 1 0.58 0.653 0.442 microwave 3 3 0.971 1 0.995 0.901 oven 5 5 0.755 0.618 0.722 0.588 sink 4 6 0.977 1 0.995 0.788 refrigerator 5 5 0.93 1 0.995 0.977 book 6 29 0.967 0.448 0.709 0.509 clock 8 9 0.958 0.889 0.961 0.856 vase 2 2 0.86 1 0.995 0.895 scissors 1 1 0.805 1 0.995 0.697 teddy bear 6 21 1 0.851 0.958 0.797 toothbrush 2 5 0.99 1 0.995 0.929 Speed: 0.2ms preprocess, 3.1ms inference, 0.0ms loss, 5.2ms postprocess per image Results saved to runs/detect/train 💡 Learn more at https://docs.ultralytics.com/modes/train
训练完的最好模型为:/home/aistudio/runs/detect/train/weights/best.pt
训练过程保存为:runs/detect/train/results.png,如下图:
四、推理验证:
- 使用经典的图片验证:
直接使用网上的图片作为测试:source='https://ultralytics.com/images/bus.jpg',或者先下载到本地。
ai@jupyter:~$ yolo detect predict model=runs/detect/train/weights/best.pt source=bus.jpg
image 1/1 /home/aistudio/bus.jpg: 640x480 3 persons, 1 bus, 1 stop sign, 39.6ms
Speed: 7.0ms preprocess, 39.6ms inference, 2.4ms postprocess per image at shape (1, 3, 640, 480)
Results saved to runs/detect/predict
💡 Learn more at https://docs.ultralytics.com/modes/predict
- 换一张图片测试:
ai@jupyter:~$ yolo detect predict model=runs/detect/train/weights/best.pt source=030.jpg
Ultralytics YOLOv8.2.92 🚀 Python-3.10.10 torch-2.4.1+cu121 CUDA:0 (Tesla V100-SXM2-32GB, 16384MiB)
Model summary (fused): 168 layers, 3,151,904 parameters, 0 gradients, 8.7 GFLOPs
image 1/1 /home/aistudio/030.jpg: 448x640 1 potted plant, 1 vase, 139.9ms
Speed: 7.6ms preprocess, 139.9ms inference, 2.5ms postprocess per image at shape (1, 3, 448, 640)
Results saved to runs/detect/predict2
💡 Learn more at https://docs.ultralytics.com/modes/predict
五、导出(Export)
将 训练好的模型导出为不同的格式,如 ONNX、CoreML 等。
yolo export model=runs/detect/train/weights/best.pt format=onnx
小结:
YOLOv8 在多个领域中表现出色,特别是在需要高精度和高速度的实时检测任务中,如无人驾驶、智能监控和工业检测等。这些应用场景对目标检测的实时性和准确性有着极高的要求,而 YOLOv8 正是满足这些需求的理想选择。
综上所述,YOLOv8 通过模型结构改进、数据增强和训练策略优化、多尺度检测和轻量化以及提供多种模型变体等新特性和优化措施,进一步提升了目标检测的精度和速度,并扩展了其应用场景。
老徐,仲秋,2024/9/17
今天的文章 YOLOv8 的安装与训练分享到此就结束了,感谢您的阅读。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/bian-cheng-ji-chu/81547.html