mmdetection中的anchor部分的代码理解和注释

/home/wuchenxi/mmdetection/mmdet/models/anchor_heads/anchor_head.pyfrom future import divisionimport numpy as npimport torchimport torch.nn as nnfrom mmcv.cnn import normal_initfrom mmdet.core i...
摘要由CSDN通过智能技术生成

/home/wuchenxi/mmdetection/mmdet/models/anchor_heads/anchor_head.py

from future import division

import numpy as np
import torch
import torch.nn as nn
from mmcv.cnn import normal_init

from mmdet.core import (AnchorGenerator, anchor_target, delta2bbox,
multi_apply, multiclass_nms, force_fp32)
from …builder import build_loss
from …registry import HEADS

@HEADS.register_module
class AnchorHead(nn.Module):
“”"Anchor-based head (RPN, RetinaNet, SSD, etc.).

Args:
    in_channels (int): Number of channels in the input feature map.
    feat_channels (int): Number of channels of the feature map.
    anchor_scales (Iterable): Anchor scales.
    anchor_ratios (Iterable): Anchor aspect ratios.
    anchor_strides (Iterable): Anchor strides.
    anchor_base_sizes (Iterable): Anchor base sizes.
    target_means (Iterable): Mean values of regression targets.
    target_stds (Iterable): Std values of regression targets.
    loss_cls (dict): Config of classification loss.
    loss_bbox (dict): Config of localization loss.
"""  # noqa: W605

def __init__(self,
             num_classes,
             in_channels,
             feat_channels=256,
             anchor_scales=[8, 16, 32],
             anchor_ratios=[0.5, 1.0, 2.0],#1:2,1:1,2:1的anchor比例
             anchor_strides=[4, 8, 16, 32, 64],    #初始的base_size就是通过这个生成的,个数应和FPN的输出层数相等
             anchor_base_sizes=None,
             target_means=(.0, .0, .0, .0),
             target_stds=(1.0, 1.0, 1.0, 1.0),
             loss_cls=dict(
                 type='CrossEntropyLoss',
                 use_sigmoid=True,
                 loss_weight=1.0),
             loss_bbox=dict(
                 type='SmoothL1Loss', beta=1.0 / 9.0, loss_weight=1.0)):
    super(AnchorHead, self).__init__()
    self.in_channels = in_channels
    self.num_classes = num_classes
    self.feat_channels = feat_channels
    self.anchor_scales = anchor_scales
    self.anchor_ratios = anchor_ratios
    self.anchor_strides = anchor_strides
    self.anchor_base_sizes = list(
        anchor_strides) if anchor_base_sizes is None else anchor_base_sizes  #生成base_size部分代码
    self.target_means = target_means
    self.target_stds = target_stds

    self.use_sigmoid_cls = loss_cls.get('use_sigmoid', False)
    self.sampling = loss_cls['type'] not in ['FocalLoss', 'GHMC']
    if self.use_sigmoid_cls:
        self.cls_out_channels = num_classes - 1
    else:
        self.cls_out_channels = num_classes
    self.loss_cls = build_loss(loss_cls)
    self.loss_bbox = build_loss(loss_bbox)
    self.fp16_enabled = 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
mmdetection是一个基于PyTorch的开源目标检测框架,支持多种主流的检测模型,包括Faster R-CNN、Mask R-CNN、RetinaNet等。而anchor是目标检测的一种重要的概念,它是在图像上预定义的一些框,用于检测目标的位置和大小。在mmdetection,可以通过可视化anchor来更好地理解它们在检测的作用。 要进行anchor可视化,可以按照以下步骤进行操作: 1. 在mmdet/core/anchor/anchor_generator.py文件找到AnchorGenerator类,修改其的forward函数,使其返回生成的anchors。 2. 在mmdet/models/detectors/base.py文件找到BaseDetector类,修改其的forward函数,使其返回生成的anchors。 3. 在mmdet/models/detectors/single_stage.py文件找到SingleStageDetector类,修改其的forward函数,使其返回生成的anchors。 4. 在mmdet/models/detectors/two_stage.py文件找到TwoStageDetector类,修改其的forward函数,使其返回生成的anchors。 5. 在mmdet/models/detectors/yolo.py文件找到YOLOV3类,修改其的forward函数,使其返回生成的anchors。 6. 在mmdet/models/detectors/fcos.py文件找到FCOSDetector类,修改其的forward函数,使其返回生成的anchors。 7. 在mmdet/models/detectors/atss.py文件找到ATSSDetector类,修改其的forward函数,使其返回生成的anchors。 8. 在mmdet/models/detectors/faster_rcnn.py文件找到FasterRCNN类,修改其的forward函数,使其返回生成的anchors。 9. 在mmdet/models/detectors/mask_rcnn.py文件找到MaskRCNN类,修改其的forward函数,使其返回生成的anchors。 10. 在mmdet/models/detectors/retinanet.py文件找到RetinaNet类,修改其的forward函数,使其返回生成的anchors。 11. 在mmdet/models/detectors/guided_anchor.py文件找到GuidedAnchorDetector类,修改其的forward函数,使其返回生成的anchors。 12. 在mmdet/models/detectors/fovea.py文件找到FoveaDetector类,修改其的forward函数,使其返回生成的anchors。 13. 在mmdet/models/detectors/reppoints.py文件找到RepPointsDetector类,修改其的forward函数,使其返回生成的anchors。 14. 在mmdet/models/detectors/centernet.py文件找到CenterNet类,修改其的forward函数,使其返回生成的anchors。 15. 在mmdet/models/detectors/htc.py文件找到HTCDetector类,修改其的forward函数,使其返回生成的anchors。 16. 在mmdet/models/detectors/libra_rcnn.py文件找到LibraRCNNDetector类,修改其的forward函数,使其返回生成的anchors。 17. 在mmdet/models/detectors/ghm_rcnn.py文件找到GHMRCNNDetector类,修改其的forward函数,使其返回生成的anchors。 18. 在mmdet/models/detectors/fovea_align.py文件找到FoveaAlignDetector类,修改其的forward函数,使其返回生成的anchors。 19. 在mmdet/models/detectors/fovea_align_ms.py文件找到FoveaAlignMSDetector类,修改其的forward函数,使其返回生成的anchors。 20. 在mmdet/models/detectors/fovea_align_resnet.py文件找到FoveaAlignResNetDetector类,修改其的forward函数,使其返回生成的anchors。 21. 在mmdet/models/detectors/fovea_align_resnet_ms.py文件找到FoveaAlignResNetMSDetector类,修改其的forward函数,使其返回生成的anchors。 22. 在mmdet/models/detectors/fovea_box.py文件找到FoveaBoxDetector类,修改其的forward函数,使其返回生成的anchors。 23. 在mmdet/models/detectors/fovea_box_ms.py文件找到FoveaBoxMSDetector类,修改其的forward函数,使其返回生成的anchors。 24. 在mmdet/models/detectors/fovea_box_resnet.py文件找到FoveaBoxResNetDetector类,修改其的forward函数,使其返回生成的anchors。 25. 在mmdet/models/detectors/fovea_box_resnet_ms.py文件找到FoveaBoxResNetMSDetector类,修改其的forward函数,使其返回生成的anchors。 26. 在mmdet/models/detectors/fovea_rcnn.py文件找到FoveaRCNNDetector类,修改其的forward函数,使其返回生成的anchors。 27. 在mmdet/models/detectors/fovea_rcnn_ms.py文件找到FoveaRCNNMSDetector类,修改其的forward函数,使其返回生成的anchors。 28. 在mmdet/models/detectors/fovea_rcnn_resnet.py文件找到FoveaRCNNResNetDetector类,修改其的forward函数,使其返回生成的anchors。 29. 在mmdet/models/detectors/fovea_rcnn_resnet_ms.py文件找到FoveaRCNNResNetMSDetector类,修改其的forward函数,使其返回生成的anchors。 30. 在mmdet/models/detectors/fovea_rcnn_se.py文件找到FoveaRCNNSEDetector类,修改其的forward函数,使其返回生成的anchors。 31. 在mmdet/models/detectors/fovea_rcnn_se_ms.py文件找到FoveaRCNNSEMSDetector类,修改其的forward函数,使其返回生成的anchors。 32. 在mmdet/models/detectors/fovea_rcnn_se_resnet.py文件找到FoveaRCNNSEResNetDetector类,修改其的forward函数,使其返回生成的anchors。 33. 在mmdet/models/detectors/fovea_rcnn_se_resnet_ms.py文件找到FoveaRCNNSEResNetMSDetector类,修改其的forward函数,使其返回生成的anchors。 34. 在mmdet/models/detectors/fovea_se.py文件找到FoveaSEDetector类,修改其的forward函数,使其返回生成的anchors。 35. 在mmdet/models/detectors/fovea_se_ms.py文件找到FoveaSEMSDetector类,修改其的forward函数,使其返回生成的anchors。 36. 在mmdet/models/detectors/fovea_se_resnet.py文件找到FoveaSEResNetDetector类,修改其的forward函数,使其返回生成的anchors。 37. 在mmdet/models/detectors/fovea_se_resnet_ms.py文件找到FoveaSEResNetMSDetector类,修改其的forward函数,使其返回生成的anchors。 38. 在mmdet/models/detectors/fovea_se_resnext.py文件找到FoveaSEResNeXtDetector类,修改其的forward函数,使其返回生成的anchors。 39. 在mmdet/models/detectors/fovea_se_resnext_ms.py文件找到FoveaSEResNeXtMSDetector类,修改其的forward函数,使其返回生成的anchors。 40. 在mmdet/models/detectors/fovea_se_resnext_ms_32x4d.py文件找到FoveaSEResNeXtMS32x4dDetector类,修改其的forward函数,使其返回生成的anchors。 以上是对mmdetectionanchor可视化的一些操作步骤,具体实现可以参考mmdetection的官方文档或者相关代码

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值