当前位置:   article > 正文

Yolov7一代版本与二代版本改LOSS注意点_yolov7改损失函数

yolov7改损失函数

YOLOv7的utils文件夹下的loss文件中给了两种损失函数:computeloss和computelossota,默认都使用computelossota。

YOLOv7一代计算LOSS:

  1. # Forward
  2. with amp.autocast(enabled=cuda):
  3. pred = model(imgs) # forward
  4. if 'loss_ota' not in hyp or hyp['loss_ota'] == 1:
  5. loss, loss_items = compute_loss_ota(pred, targets.to(device), imgs) # loss scaled by batch_size
  6. else:
  7. loss, loss_items = compute_loss(pred, targets.to(device)) # loss scaled by batch_size
  8. if rank != -1:
  9. loss *= opt.world_size # gradient averaged between devices in DDP mode
  10. if opt.quad:
  11. loss *= 4.

YOLOv7二代计算LOSS:

  1. # Forward
  2. with amp.autocast(enabled=cuda):
  3. pred = model(imgs) # forward
  4. loss, loss_items = compute_loss_ota(pred, targets.to(device), imgs) # loss scaled by batch_size
  5. if rank != -1:
  6. loss *= opt.world_size # gradient averaged between devices in DDP mode
  7. if opt.quad:
  8. loss *= 4.

一代版本是根据hyp文件中最后一行,判断使用何种loss,例如默认的hyp.scratch.p5.yaml:

  1. lr0: 0.01 # initial learning rate (SGD=1E-2, Adam=1E-3)
  2. lrf: 0.1 # final OneCycleLR learning rate (lr0 * lrf)
  3. momentum: 0.937 # SGD momentum/Adam beta1
  4. weight_decay: 0.0005 # optimizer weight decay 5e-4
  5. warmup_epochs: 3.0 # warmup epochs (fractions ok)
  6. warmup_momentum: 0.8 # warmup initial momentum
  7. warmup_bias_lr: 0.1 # warmup initial bias lr
  8. box: 0.05 # box loss gain
  9. cls: 0.3 # cls loss gain
  10. cls_pw: 1.0 # cls BCELoss positive_weight
  11. obj: 0.7 # obj loss gain (scale with pixels)
  12. obj_pw: 1.0 # obj BCELoss positive_weight
  13. iou_t: 0.20 # IoU training threshold
  14. anchor_t: 4.0 # anchor-multiple threshold
  15. # anchors: 3 # anchors per output layer (0 to ignore)
  16. fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5)
  17. hsv_h: 0.015 # image HSV-Hue augmentation (fraction)
  18. hsv_s: 0.7 # image HSV-Saturation augmentation (fraction)
  19. hsv_v: 0.4 # image HSV-Value augmentation (fraction)
  20. degrees: 0.0 # image rotation (+/- deg)
  21. translate: 0.2 # image translation (+/- fraction)
  22. scale: 0.9 # image scale (+/- gain)
  23. shear: 0.0 # image shear (+/- deg)
  24. perspective: 0.0 # image perspective (+/- fraction), range 0-0.001
  25. flipud: 0.0 # image flip up-down (probability)
  26. fliplr: 0.5 # image flip left-right (probability)
  27. mosaic: 1.0 # image mosaic (probability)
  28. mixup: 0.15 # image mixup (probability)
  29. copy_paste: 0.0 # image copy paste (probability)
  30. paste_in: 0.15 # image copy paste (probability), use 0 for faster training
  31. loss_ota: 1 # use ComputeLossOTA, use 0 for faster training

loss_ota: 1 # use ComputeLossOTA, use 0 for faster training,其中的1代表使用ComputeLOSSOTA

二代中hyp文件删掉了最后一行,改为默认使用 computelossota

因此在两代版本改loss函数会有不同,注意改的位置要和使用的loss函数对应,例如使用默认computelossota计算,就要在class computelossota中进行修改

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

闽ICP备14008679号