做网站客户一般会问什么问题代发网站建设
- 作者: 五速梦信息网
- 时间: 2026年04月18日 09:55
当前位置: 首页 > news >正文
做网站客户一般会问什么问题,代发网站建设,苍南县规划建设局网站,广州营销型网站建设本文介绍了使用用于目标检测的自定义数据训练 YOLOv8 模型。我正在使用来自 kaggle 的 yolo 格式的“Face Mask Dataset”#xff0c;数据集链接如下#xff1a;https://www.kaggle.com/datasets/maalialharbi/face-mask-dataset?resourcedownloadYOLOv8 是目前最先进的 YOL…本文介绍了使用用于目标检测的自定义数据训练 YOLOv8 模型。我正在使用来自 kaggle 的 yolo 格式的“Face Mask Dataset”数据集链接如下https://www.kaggle.com/datasets/maalialharbi/face-mask-dataset?resourcedownloadYOLOv8 是目前最先进的 YOLO 模型可用于目标检测、图像分类和实例分割任务。我使用 Google Colab 进行训练如果您有兴趣使用 YOLOv5 对自定义数据进行检查可是使用下面链接中的代码https://github.com/Balakishan77/yolov5_custom_traffic_sign_detector。关于这个用于目标检测任务的数据集数据集“Face Mask Dataset”已转换好 YOLO 格式以用于检测任务。它既可以用于训练也可以用于测试。图像数据集可以切分如下测试136 10%训练990 70%验证294 20%总计 1420 张图片图像数据增强是为了增加数据集的大小并使其更强大。图像格式JPEG、PNG共有 3 个类no_mask mask improper_mask。训练自定义检测模型我正在使用 Yolov8m 对口罩数据进行自定义训练。我通过从 Google Drive 读取数据并在 Google colab 上进行训练。以下步骤将详细介绍使用 YOLOv8 在 Mask Data 上进行自定义训练配置 Google ColabYOLOv8 安装安装 Google Drive创建 face_mask_detetcion.yaml数据集配置文件YOLOV8格式训练我们的自定义口罩检测模型指标使用自定义 YOLOv8 目标检测模型训练权重进行推理1. 配置 Google ColabGoogle Colab 是一个类似于 Jupiter notebook 的在线深度学习训练环境您可以在上面的 GPU/TPU 上训练深度学习模型。Google Colab 允许您在断开连接之前免费训练深度学习模型长达 12 小时。通过访问运行时部分将运行类型更改为 GPU 并使用以下命令检查 GPU 详细信息。# to check and monitoring of NVIDIA GPU devices. !nvidia-smi2. YOLOv8 安装我们可以通过 clone git 上面的代码或使用 torch hub 使用 YOLOv5。最近的 YOLOv8 已经发布为 pip 包所以我们不需要 clone 任何代码便可以安装 v8 版本所有的依赖项。# installing package to work with yolov8 !pip install ultralytics3. 安装 Google Drive我已经将 mask_dataset 文件夹上传到“MyDrive/datasets/mask_dataset/”路径中的 Google Drive我将使用以下代码进行安装。它会要求您输入授权码您可以通过单击下面显示的链接来输入授权码。标注数据已按照图像和标签文本文件分开的方式进行切分。from google.colab import drive drive.mount(/content/drive)YOLOv8格式YOLOv8 的格式与 Yolov5 相同。YOLO 格式每个图像有一个对应的 .txt 文件如果图像中没有对象则不需要 .txt 文件。*.txt 文件规范为每个对象对应一行每行依次保存了 class, x_center, y_center width height。框坐标必须采用 xywh 格式归一化到 0–1。如果您的框以像素为单位请将 x_center 和 width 除以图像 width将 y_center 和 height 除以图像 heigth。class 是从零进行索引的。下面我们将探索数据集中的一些示例图像。# Checking the size of images and displaying them import numpy as np import cv2
Image shape in Training
image cv2.imread(/content/drive/MyDrive/datasets/mask_dataset/train/images/5e353e347af50726986e84c0.jpeg) height np.size(image, 0) width np.size(image, 1) print (shape of the training image {}, {}.format(height, width))
Image shape in validation
image cv2.imread(/content/drive/MyDrive/datasets/mask_dataset/valid/images/maksssksksss67.png) height np.size(image, 0) width np.size(image, 1) print (shape of the validation image {}, {}.format(height, width))# dispying with different width from IPython.display import Image Image(filename/content/drive/MyDrive/datasets/mask_dataset/train/images/5e353e347af50726986e84c0.jpeg, width300)4. 创建 face_mask_detetcion.yaml数据集配置文件“face mask dataset”中的图像拆分如下训练990 70%验证294 20%测试136 10% 我没有使用测试数据集而是用一些来自互联网的视频进行测试总计 1420 张图片下面创建的 mask_dataset/face_mask_detetcion.yaml 是定义以下内容的数据集配置文件数据集根目录路径和 train / test /val 图像目录的相对路径或带有图像路径的 *.txt 文件nc类别数目names类名列表# I will write the contents of the cell to a file %%writefile /content/drive/MyDrive/datasets/mask_dataset/face_mask_detection.yaml # Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..] path: /content/drive/MyDrive/datasets/mask_dataset # dataset root dir train: train/images/ # train images (relative to path) val: valid/images/ # val images (relative to path) test: # test images (optional)# number of classes nc: 3# class names #names: [0, 1, 2] names: [ no_mask, mask,improper_mask] # class names5. 训练我们自定义口罩检测模型我正在使用 YOLOv8m 预训练模型对口罩数据集进行训练。我们可以调整多个参数以获得更好的结果我正在使用 yolov8m 模型训练 25 个 epoch。参数指定数据配置文件的路径输入图像尺寸epochfrom ultralytics import YOLO# Load a model
model YOLO(yolov8m.yaml) # build a new model from scratch
model YOLO(yolov8m.pt) # load a pretrained model (recommended for training)# Use the model results model.train(data/content/drive/MyDrive/datasets/mask_dataset/face_mask_detection.yaml, epochs25, imgsz640) # train the modelVAL在验证数据集上验证经过训练的 YOLOv8m 模型准确性。不需要传递参数因为模型将其训练数据和参数保留为一个完整模型。results model.val() # evaluate model performance on the validation set6. 指标每个类别和整体的训练 mAP 效果都很好视频测试结果也很好。如果我们针对 epoch 进行训练添加更多数据并使用超参数可以提高模型的性能。下面我们可以看到 Precision-Recall 和 F1 置信度曲线。# dislaying metrics for train data from IPython.display import Image from IPython.display import display x Image(filenameruns/detect/train2/F1_curve.png) y Image(filenameruns/detect/train2/PR_curve.png) z Image(filenameruns/detect/train2/confusion_matrix.png) display(x, y,z)7. 推理# checking the latest trained files !ls runs/detect/train2/weights best.pt last.pt
loading the trianed model
model YOLO(runs/detect/train2/weights/best.pt) # load a custom model
testing the model on a video
!yolo taskdetect modepredict modelruns/detect/train2/weights/best.pt source/content/drive/MyDrive/datasets/mask_dataset/mask_testing.mp4下面是使用该模型对图像进行推理的示例。下面提供了使用经过训练模型推理并进行标注的视频链接https://github.com/Balakishan77/Yolov8-Custom-ObjectDetetction/blob/main/face_mask_detetcion_yolov8.mp4结论根据推理结果经过训练的模型效果很好。我们可以尝试通过使用更大型的 YOLOv8 模型、扩增数据集和添加超参数的方式对模型进行改进小伙伴们有兴趣可以自行尝试。· END ·HAPPY LIFE
- 上一篇: 做网站客户济南百度推广优化
- 下一篇: 做网站课程做影视网站版权问题
相关文章
-
做网站客户济南百度推广优化
做网站客户济南百度推广优化
- 技术栈
- 2026年04月18日
-
做网站客户不给钱怎么办wordpress 内网映射
做网站客户不给钱怎么办wordpress 内网映射
- 技术栈
- 2026年04月18日
-
做网站可以赚钱么wordpress访问太慢
做网站可以赚钱么wordpress访问太慢
- 技术栈
- 2026年04月18日
-
做网站课程做影视网站版权问题
做网站课程做影视网站版权问题
- 技术栈
- 2026年04月18日
-
做网站空间济南网站建设设计公司
做网站空间济南网站建设设计公司
- 技术栈
- 2026年04月18日
-
做网站空间需要多大微商货源网下载
做网站空间需要多大微商货源网下载
- 技术栈
- 2026年04月18日
