【效果展示】【训练数据集介绍】数据集格式YOLO格式(不包含分割路径的txt文件仅仅包含jpg图片以及对应的yolo格式txt文件)图片数量(jpg文件个数)2017标注数量(txt文件个数)2017训练集数量1804验证集数量135测试集数量78标注类别数2所在github仓库firc-dataset标注类别名称(注意yolo格式类别顺序不和这个对应而以labels文件夹classes.txt为准):[jiaonang,yaopian]每个类别标注的框数jiaonang 框数15854yaopian 框数25381总框数41235使用标注工具labelImg标注规则对类别进行画矩形框重要说明数据集大约1100是原图剩余为旋转增强生成图片特别声明本数据集不对训练的模型或者权重文件精度作任何保证图片预览标注例子【测试环境】windows10anaconda3python3.8torch2.3.1ultralytics8.4.31【模型可以检测出2类别】药片和胶囊【训练信息】参数值训练集图片数1804验证集图片数135训练map90.7%训练精度(Precision)85.9%训练召回率(Recall)85.7%验证集评估精度信息namemap50%all910胶囊871药片95【训练步骤】使用YOLO26训练自己的数据集需要遵循一些基本的步骤。YOLO26是YOLO系列模型的一个版本它在前代基础上做了许多改进包括但不限于更高效的训练流程和更高的精度。以下是训练自己YOLO格式数据集的详细步骤一、 准备环境1. 安装必要的软件确保你的计算机上安装了Python推荐3.8或更高版本以及CUDA和cuDNN如果你打算使用GPU进行加速。2. 安装YOLO26库你可以通过GitHub克隆YOLOv8的仓库或者直接通过pip安装YOLO26。例如pip install ultralytics二、数据准备3. 组织数据结构按照YOLO的要求组织你的数据文件夹。通常你需要一个包含图像和标签文件的目录结构如dataset/├── images/│ ├── train/│ └── val/├── labels/│ ├── train/│ └── val/其中train和val分别代表训练集和验证集。且images文件夹和labels文件夹名字不能随便改写或者写错否则会在训练时候找不到数据集。4. 标注数据使用合适的工具对图像进行标注生成YOLO格式的标签文件。每个标签文件应该是一个.txt文件每行表示一个边界框格式为类别ID 中心点x 中心点y 宽度 高度这些值都是相对于图像尺寸的归一化值。5. 创建数据配置文件创建一个.yaml文件来定义你的数据集包括路径、类别列表等信息。例如yaml# dataset.yamlpath: ./dataset # 数据集根目录train: images/train # 训练图片相对路径val: images/val # 验证图片相对路径nc: 2 # 类别数names: [class1, class2] # 类别名称三、模型训练6. 加载预训练模型可以使用官方提供的预训练模型作为起点以加快训练速度并提高性能。7. 配置训练参数根据需要调整训练参数如批量大小、学习率、训练轮次等。这通常可以通过命令行参数或配置文件完成。8. 开始训练使用YOLO11提供的命令行接口开始训练过程。例如yolo train datadataset.yaml modelyolo11n.yaml epochs100 imgsz640更多参数如下参数默认值描述modelNoneSpecifies the model file for training. Accepts a path to either a.ptpretrained model or a.yamlconfiguration file. Essential for defining the model structure or initializing weights.dataNonePath to the dataset configuration file (e.g.,coco8.yaml). This file contains dataset-specific parameters, including paths to training and validation data , class names, and number of classes.epochs100Total number of training epochs. Each epoch represents a full pass over the entire dataset. Adjusting this value can affect training duration and model performance.timeNoneMaximum training time in hours. If set, this overrides theepochsargument, allowing training to automatically stop after the specified duration. Useful for time-constrained training scenarios.patience100Number of epochs to wait without improvement in validation metrics before early stopping the training. Helps prevent overfitting by stopping training when performance plateaus.batch16Batch size, with three modes: set as an integer (e.g.,batch16), auto mode for 60% GPU memory utilization (batch-1), or auto mode with specified utilization fraction (batch0.70).imgsz640Target image size for training. All images are resized to this dimension before being fed into the model. Affects model accuracy and computational complexity.saveTrueEnables saving of training checkpoints and final model weights. Useful for resuming training ormodel deployment.save_period-1Frequency of saving model checkpoints, specified in epochs. A value of -1 disables this feature. Useful for saving interim models during long training sessions.cacheFalseEnables caching of dataset images in memory (True/ram), on disk (disk), or disables it (False). Improves training speed by reducing disk I/O at the cost of increased memory usage.deviceNoneSpecifies the computational device(s) for training: a single GPU (device0), multiple GPUs (device0,1), CPU (devicecpu), or MPS for Apple silicon (devicemps).workers8Number of worker threads for data loading (perRANKif Multi-GPU training). Influences the speed of data preprocessing and feeding into the model, especially useful in multi-GPU setups.projectNoneName of the project directory where training outputs are saved. Allows for organized storage of different experiments.nameNoneName of the training run. Used for creating a subdirectory within the project folder, where training logs and outputs are stored.exist_okFalseIf True, allows overwriting of an existing project/name directory. Useful for iterative experimentation without needing to manually clear previous outputs.pretrainedTrueDetermines whether to start training from a pretrained model. Can be a boolean value or a string path to a specific model from which to load weights. Enhances training efficiency and model performance.optimizerautoChoice of optimizer for training. Options includeSGD,Adam,AdamW,NAdam,RAdam,RMSPropetc., orautofor automatic selection based on model configuration. Affects convergence speed and stability.verboseFalseEnables verbose output during training, providing detailed logs and progress updates. Useful for debugging and closely monitoring the training process.seed0Sets the random seed for training, ensuring reproducibility of results across runs with the same configurations.deterministicTrueForces deterministic algorithm use, ensuring reproducibility but may affect performance and speed due to the restriction on non-deterministic algorithms.single_clsFalseTreats all classes in multi-class datasets as a single class during training. Useful for binary classification tasks or when focusing on object presence rather than classification.rectFalseEnables rectangular training, optimizing batch composition for minimal padding. Can improve efficiency and speed but may affect model accuracy.cos_lrFalseUtilizes a cosine learning rate scheduler, adjusting the learning rate following a cosine curve over epochs. Helps in managing learning rate for better convergence.close_mosaic10Disables mosaic data augmentation in the last N epochs to stabilize training before completion. Setting to 0 disables this feature.resumeFalseResumes training from the last saved checkpoint. Automatically loads model weights, optimizer state, and epoch count, continuing training seamlessly.ampTrueEnables AutomaticMixed Precision(AMP) training, reducing memory usage and possibly speeding up training with minimal impact on accuracy.fraction1.0Specifies the fraction of the dataset to use for training. Allows for training on a subset of the full dataset, useful for experiments or when resources are limited.profileFalseEnables profiling of ONNX and TensorRT speeds during training, useful for optimizing model deployment.freezeNoneFreezes the first N layers of the model or specified layers by index, reducing the number of trainable parameters. Useful for fine-tuning or transfer learning.lr00.01Initial learning rate (i.e.SGD1E-2,Adam1E-3) . Adjusting this value is crucial for the optimization process, influencing how rapidly model weights are updated.lrf0.01Final learning rate as a fraction of the initial rate (lr0 * lrf), used in conjunction with schedulers to adjust the learning rate over time.momentum0.937Momentum factor for SGD or beta1 for Adam optimizers, influencing the incorporation of past gradients in the current update.weight_decay0.0005L2 regularization term, penalizing large weights to prevent overfitting.warmup_epochs3.0Number of epochs for learning rate warmup, gradually increasing the learning rate from a low value to the initial learning rate to stabilize training early on.warmup_momentum0.8Initial momentum for warmup phase, gradually adjusting to the set momentum over the warmup period.warmup_bias_lr0.1Learning rate for bias parameters during the warmup phase, helping stabilize model training in the initial epochs.box7.5Weight of the box loss component in the loss_function, influencing how much emphasis is placed on accurately predicting bouding box coordinates.cls0.5Weight of the classification loss in the total loss function, affecting the importance of correct class prediction relative to other components.dfl1.5Weight of the distribution focal loss, used in certain YOLO versions for fine-grained classification.pose12.0Weight of the pose loss in models trained for pose estimation, influencing the emphasis on accurately predicting pose keypoints.kobj2.0Weight of the keypoint objectness loss in pose estimation models, balancing detection confidence with pose accuracy.label_smoothing0.0Applies label smoothing, softening hard labels to a mix of the target label and a uniform distribution over labels, can improve generalization.nbs64Nominal batch size for normalization of loss.overlap_maskTrueDetermines whether object masks should be merged into a single mask for training, or kept separate for each object. In case of overlap, the smaller mask is overlayed on top of the larger mask during merge.mask_ratio4Downsample ratio for segmentation masks, affecting the resolution of masks used during training.dropout0.0Dropout rate for regularization in classification tasks, preventing overfitting by randomly omitting units during training.valTrueEnables validation during training, allowing for periodic evaluation of model performance on a separate dataset.plotsFalseGenerates and saves plots of training and validation metrics, as well as prediction examples, providing visual insights into model performance and learning progression.这里data参数指向你的数据配置文件model参数指定使用的模型架构epochs设置训练轮次imgsz设置输入图像的大小。四、监控与评估9. 监控训练过程观察损失函数的变化确保模型能够正常学习。10. 评估模型训练完成后在验证集上评估模型的性能查看mAP平均精确度均值等指标。11. 调整超参数如果模型的表现不佳可能需要调整超参数比如增加训练轮次、改变学习率等并重新训练模型。五、使用模型12. 导出模型训练完成后可以将模型导出为ONNX或其他格式以便于部署到不同的平台。比如将pytorch转成onnx模型可以输入指令yolo export modelbest.pt formatonnx这样就会在pt模块同目录下面多一个同名的onnx模型best.onnx下表详细说明了可用于将YOLO模型导出为不同格式的配置和选项。这些设置对于优化导出模型的性能、大小和跨各种平台和环境的兼容性至关重要。正确的配置可确保模型已准备好以最佳效率部署在预期的应用程序中。参数类型默认值描述formatstrtorchscriptTarget format for the exported model, such asonnx,torchscript,tensorflow, or others, defining compatibility with various deployment environments.imgszintortuple640Desired image size for the model input. Can be an integer for square images or a tuple(height, width)for specific dimensions.kerasboolFalseEnables export to Keras format for Tensorflow SavedModel, providing compatibility with TensorFlow serving and APIs.optimizeboolFalseApplies optimization for mobile devices when exporting to TorchScript, potentially reducing model size and improving performance.halfboolFalseEnables FP16 (half-precision) quantization, reducing model size and potentially speeding up inference on supported hardware.int8boolFalseActivates INT8 quantization, further compressing the model and speeding up inference with minimal accuracy loss, primarily for edge devices.dynamicboolFalseAllows dynamic input sizes for ONNX, TensorRT and OpenVINO exports, enhancing flexibility in handling varying image dimensions.simplifyboolTrueSimplifies the model graph for ONNX exports withonnxslim, potentially improving performance and compatibility.opsetintNoneSpecifies the ONNX opset version for compatibility with different ONNX parsers and runtimes. If not set, uses the latest supported version.workspacefloat4.0Sets the maximum workspace size in GiB for TensorRT optimizations, balancing memory usage and performance.nmsboolFalseAdds Non-Maximum Suppression (NMS) to the CoreML export, essential for accurate and efficient detection post-processing.batchint1Specifies export model batch inference size or the max number of images the exported model will process concurrently inpredictmode.devicestrNoneSpecifies the device for exporting: GPU (device0), CPU (devicecpu), MPS for Apple silicon (devicemps) or DLA for NVIDIA Jetson (devicedla:0ordevicedla:1).调整这些参数可以定制导出过程以满足特定要求如部署环境、硬件约束和性能目标。选择适当的格式和设置对于实现模型大小、速度和精度之间的最佳平衡至关重要。导出格式可用的YOLO26导出格式如下表所示。您可以使用format参数导出为任何格式即formatonnx或formatengine。您可以直接在导出的模型上进行预测或验证即yolo predict modelyolo26n.onnx。导出完成后将显示您的模型的使用示例。导出格式格式参数模型属性参数pytorch-yolo26n.pt✅-torchscripttorchscriptyolo26n.torchscript✅imgsz,optimize,batchonnxonnxyolo26n.onnx✅imgsz,half,dynamic,simplify,opset,batchopenvinoopenvinoyolo26n_openvino_model/✅imgsz,half,int8,batchtensorrtengineyolo26n.engine✅imgsz,half,dynamic,simplify,workspace,int8,batchCoreMLcoremlyolo26n.mlpackage✅imgsz,half,int8,nms,batchTF SaveModelsaved_modelyolo26n_saved_model/✅imgsz,keras,int8,batchTF GraphDefpbyolo26n.pb❌imgsz,batchTF Litetfliteyolo26n.tflite✅imgsz,half,int8,batchTF Edge TPUedgetpuyolo26n_edgetpu.tflite✅imgszTF.jstfjsyolo26n_web_model/✅imgsz,half,int8,batchPaddlePaddlepaddleyolo26n_paddle_model/✅imgsz,batchMNNmnnyolo26n.mnn✅imgsz,batch,int8,halfNCNNncnnyolo26n_ncnn_model/✅imgsz,half,batch13. 测试模型在新的数据上测试模型确保其泛化能力良好。以上就是使用YOLO26训练自己数据集的基本步骤。请根据实际情况调整这些步骤中的具体细节。希望这些信息对你有所帮助【常用评估参数介绍】在目标检测任务中评估模型的性能是至关重要的。你提到的几个术语是评估模型性能的常用指标。下面是对这些术语的详细解释Class这通常指的是模型被设计用来检测的目标类别。例如一个模型可能被训练来检测车辆、行人或动物等不同类别的对象。Images表示验证集中的图片数量。验证集是用来评估模型性能的数据集与训练集分开以确保评估结果的公正性。Instances在所有图片中目标对象的总数。这包括了所有类别对象的总和例如如果验证集包含100张图片每张图片平均有5个目标对象则Instances为500。P精确度Precision精确度是模型预测为正样本的实例中真正为正样本的比例。计算公式为Precision TP / (TP FP)其中TP表示真正例True PositivesFP表示假正例False Positives。R召回率Recall召回率是所有真正的正样本中被模型正确预测为正样本的比例。计算公式为Recall TP / (TP FN)其中FN表示假负例False Negatives。mAP50表示在IoU交并比阈值为0.5时的平均精度mean Average Precision。IoU是衡量预测框和真实框重叠程度的指标。mAP是一个综合指标考虑了精确度和召回率用于评估模型在不同召回率水平上的性能。在IoU0.5时如果预测框与真实框的重叠程度达到或超过50%则认为该预测是正确的。mAP50-95表示在IoU从0.5到0.95间隔0.05的范围内模型的平均精度。这是一个更严格的评估标准要求预测框与真实框的重叠程度更高。在目标检测任务中更高的IoU阈值意味着模型需要更准确地定位目标对象。mAP50-95的计算考虑了从宽松到严格的多个IoU阈值因此能够更全面地评估模型的性能。这些指标共同构成了评估目标检测模型性能的重要框架。通过比较不同模型在这些指标上的表现可以判断哪个模型在实际应用中可能更有效。【使用步骤】使用步骤1首先根据官方框架ultralytics安装教程安装好yolo26环境并安装好pyqt52切换到自己安装的yolo26环境后并切换到源码目录执行python gui.py即可运行启动界面进行相应的操作即可【提供文件】python源码pytorch模型训练的map,P,R曲线图(在weights\results.png)测试图片若干张在test_img文件夹下面注意提供训练的数据集