当前位置:   article > 正文

YOLOV9训练自己的数据集_pred_distri, pred_scores = torch.cat([xi.view(feat

pred_distri, pred_scores = torch.cat([xi.view(feats[0].shape[0], self.no, -1

 1.代码下载地址GitHub - WongKinYiu/yolov9: Implementation of paper - YOLOv9: Learning What You Want to Learn Using Programmable Gradient Information

 2.准备自己的数据集

这里数据集我以SAR数据集为例

具体的下载链接如下所示:

链接:https://pan.baidu.com/s/1cIiaOT2hbnQsa8e93cHQrg 
提取码:yyds

3.数据集路径调整

将数据集存放在yolov9的文件夹下面

4.新建data.yaml文件

  1. train: E:\liqiang\yolov9-main\data\SSDD\train\images # 训练集绝对路径 进入到训练集存放图片的文件夹里面,按ctrl+L复制过来即可
  2. val: E:\liqiang\yolov9-main\data\SSDD\val\images # 验证集绝对路径 进入到验证集存放图片的文件夹里面,按ctrl+L复制过来即可
  3. # test: D:\needed\air-filter\train\images
  4. nc: 1 # class数
  5. names: ['ship'] # 模型类别名

train的路径是训练集下面的images路径

val的路径是验证集下面的images路径

其他的根据自己的数据集进行调整

5.修改yolov9.yaml文件

把nc改为数据集类别即可

6.训练

报错1:

训练如果出现AttributeError: 'list' object has no attribute 'view'报错时,使用tain_dual.py进行训练,不要使用train.py进行训练

AMP: checks passed 
optimizer: SGD(lr=0.01) with parameter groups 230 weight(decay=0.0), 247 weight(decay=0.0005), 245 bias
albumentations: Blur(p=0.01, blur_limit=(3, 7)), MedianBlur(p=0.01, blur_limit=(3, 7)), ToGray(p=0.01), CLAHE(p=0.01, clip_limit=(1, 4.0), tile_grid_size=(8, 8))
train: Scanning E:\liqiang\yolov9-main\data\SSDD\train\labels.cache... 928 images, 0 backgrounds, 0 corrupt: 100%|██████████| 928/928 00:00
val: Scanning E:\liqiang\yolov9-main\data\SSDD\val\labels.cache... 232 images, 0 backgrounds, 0 corrupt: 100%|██████████| 232/232 00:00
Plotting labels to runs\train\exp10\labels.jpg... 
Image sizes 640 train, 640 val
Using 0 dataloader workers
Logging results to runs\train\exp10
Starting training for 10 epochs...

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss  Instances       Size
  0%|          | 0/232 00:01
Traceback (most recent call last):
  File "E:\liqiang\yolov9-main\train.py", line 634, in <module>
    main(opt)
  File "E:\liqiang\yolov9-main\train.py", line 528, in main
    train(opt.hyp, opt, device, callbacks)
  File "E:\liqiang\yolov9-main\train.py", line 304, in train
    loss, loss_items = compute_loss(pred, targets.to(device))  # loss scaled by batch_size
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\liqiang\yolov9-main\utils\loss_tal.py", line 168, in __call__
    pred_distri, pred_scores = torch.cat([xi.view(feats[0].shape[0], self.no, -1) for xi in feats], 2).split(
                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\liqiang\yolov9-main\utils\loss_tal.py", line 168, in <listcomp>
    pred_distri, pred_scores = torch.cat([xi.view(feats[0].shape[0], self.no, -1) for xi in feats], 2).split(
                                          ^^^^^^^

AttributeError: 'list' object has no attribute 'view'

报错2:

AttributeError: 'FreeTypeFont' object has no attribute 'getsize'

解决:

pip install Pillow==9.5  -i https://pypi.douban.com/simple/

训练命令:

 python .\train_dual.py  --cfg E:\liqiang\yolov9-main\models\detect\yolov9.yaml --data E:\liqiang\yolov9-main\data\data.yaml --device 0 --batch-size 4 --epoch 10 --hyp E:\liqiang\yolov9-main\data\hyps\hyp.scratch-high.yaml

yolov9.yaml绝对路径复制

data.yaml绝对路径复制

hyps绝对路径复制

 

7.推理

python detect.py --weights E:\liqiang\yolov9-main\runs\train\exp11\weights\best.pt  --source E:\liqiang\yolov9-main\data\images\000002.jpg

报错:AttributeError: 'list' object has no attribute 'device'

 解决:

将general.py中的:

  1. if isinstance(prediction, (list, tuple)): # YOLO model in validation model, output = (inference_out, loss_out)
  2. prediction = prediction[0] # select only inference output
  3. device = prediction.device

 替换为:

  1. if isinstance(prediction, (list, tuple)):
  2. processed_predictions = []
  3. for pred_tensor in prediction:
  4. processed_tensor = pred_tensor[0]
  5. processed_predictions.append(processed_tensor)
  6. prediction = processed_predictions[0]
  7. device = prediction.device

 结果如下:

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/292129
推荐阅读
相关标签
  

闽ICP备14008679号