航拍电网连接端识别检测数据集 yolo数据集 1200张
航拍电网连接端识别检测数据集 yolo数据集 1200张
标注名称以及数量:
5:3302
6:1287
航拍电网连接端识别检测
航拍电网连接端识别检测
基于航拍电网连接端识别检测数据集进行目标检测任务。数据集包含1200张图片,并且已经标注为YOLO格式。具体类别及其数量如下:
- 类别5: 3302个实例
- 类别6: 1287个实例
备注:文章代码仅供参考!
环境准备
确保您已经安装了以下软件和库:
- Python 3.8 或更高版本
- PyTorch 1.9 或更高版本
- torchvision 0.10 或更高版本
- OpenCV
- numpy
- pandas
- matplotlib
- albumentations(用于数据增强)
您可以使用以下命令安装所需的Python库:
pipinstalltorch torchvision opencv-python numpy pandas matplotlib albumentations数据集准备
假设您的数据集已经按照YOLO格式组织好,并且包含训练集、验证集和测试集。以下是数据集的预期结构:
datasets/ └── grid_connection_points/ ├── images/ │ ├── train/ │ ├── val/ │ └── test/ └── labels/ ├── train/ ├── val/ └── test/同时,有一个classes.txt文件包含类别名称,每行一个类别名称。
类别文件 (classes.txt)
connection_point_5 connection_point_6模型训练
我们将使用YOLOv5进行训练。首先,克隆YOLOv5仓库并设置环境。
gitclone https://github.com/ultralytics/yolov5.gitcdyolov5 pipinstall-rrequirements.txt准备配置文件
创建一个hyp.scratch.yaml文件来定义超参数:
# Hyperparameters for YOLOv5 training from scratchlr0:0.01# initial learning rate (SGD=1E-2, Adam=1E-3)lrf:0.1# final OneCycleLR learning rate (lr0 * lrf)momentum:0.937# SGD momentum/Adam beta1weight_decay:0.0005# optimizer weight decay 5e-4warmup_epochs:3.0# warmup epochs (fractions ok)warmup_momentum:0.8# warmup initial momentumwarmup_bias_lr:0.1# warmup initial bias lrbox:0.05# box loss gaincls:0.5# cls loss gaincls_pw:1.0# cls BCELoss positive_weightobj:1.0# obj loss gain (scale with pixels)obj_pw:1.0# obj BCELoss positive_weightiou_t:0.20# IoU training thresholdanchor_t:4.0# anchor-multiple thresholdfl_gamma:0.0# focal loss gamma (efficientDet default gamma=1.5)hsv_h:0.015# image HSV-Hue augmentation (fraction)hsv_s:0.7# image HSV-Saturation augmentation (fraction)hsv_v:0.4# image HSV-Value augmentation (fraction)degrees:0.0# image rotation (+/- deg)translate:0.1# image translation (+/- fraction)scale:0.5# image scale (+/- gain)shear:0.0# image shear (+/- deg)perspective:0.0# image perspective (+/- fraction), range 0-0.001flipud:0.0# image flip up-down (probability)fliplr:0.5# image flip left-right (probability)mosaic:1.0# image mosaic (probability)mixup:0.0# image mixup (probability)copy_paste:0.0# segment copy-paste (probability)paste_in:0.0# segment paste-in (probability)rect:0# rectangular trainingresume:false# resume training from last checkpointnosave:false# only save final checkpointnoval:false# only validate final epochnoautoanchor:true# disable AutoAnchorevolve:false# evolve hyperparametersbucket:''# gsutil bucketcache_images:false# cache images for faster trainingimage_weights:false# use weighted image selection for trainingsingle_cls:false# train multi-class data as single-classoptimizer:SGD# optimizer: SGD or AdamWsync_bn:false# use SyncBatchNorm, only available in DDP modeworkers:8# dataloader workers (max is number of CPU cores)freeze:0# freeze first n layersv5_metric:true# assume maximum recall as 1.0 in AP calculationmulti_scale:true# vary input size between 320 and 640 pixelsrect_training:false# rectangular trainingcos_lr:false# cosine LR schedulerclose_mosaic:1000# close mosaic borderscales:[0.5,1.5]# image size scalesaugment:true# augment dataverbose:false# verbose printseed:0# random seed for reproducibilitylocal_rank:-1# ddp device id (-1 for single gpu train)entity:null# W&B entityupload_dataset:False# upload dataset as W&B artifact tablebbox_interval:-1# W&B bounding box logging intervalartifact_alias:latest# version of dataset artifact to useproject:runs/train# save results to project/nameexist_ok:false# existing project/name ok, do not incrementquad:false# quadrilateral anchorslinear_assignment:false# use linear assignment for NMS创建一个data.yaml文件来定义数据集路径和类别:
train:../datasets/grid_connection_points/images/train/val:../datasets/grid_connection_points/images/val/nc:2# number of classesnames:['connection_point_5','connection_point_6']# list of class names训练模型
使用以下命令开始训练:
python train.py--img640--batch16--epochs50--datadata.yaml--cfgyolov5s.yaml--weightsyolov5s.pt--hyphyp.scratch.yaml结果评估
训练完成后,可以使用以下命令评估模型性能:
python val.py--datadata.yaml--weightsruns/train/exp/weights/best.pt--tasktest使用说明
配置路径:
- 确保
datasets/grid_connection_points/目录结构正确。 - 确保
data.yaml中的路径和类别名称正确。
- 确保
运行脚本:
- 在终端中依次运行训练脚本和评估脚本。
注意事项:
- 根据需要调整超参数和训练设置。
- 可以通过修改
data.yaml中的cfg参数来选择不同的YOLOv5模型架构(如yolov5m.yaml,yolov5l.yaml,yolov5x.yaml)。
示例
假设您的数据集文件夹结构如下:
datasets/ └── grid_connection_points/ ├── images/ │ ├── train/ │ ├── val/ │ └── test/ └── labels/ ├── train/ ├── val/ └── test/并且images/和labels/目录分别包含对应的图片和标注文件。运行上述脚本后,您可以查看训练日志和最终的模型权重文件。
