mmdetection 预测目标框和类别颜色的修改

image.py 修改

在这里插入图片描述
主要修改imshow_det_bboxes函数,按照类别进行不同颜色的显示

def imshow_det_bboxes(img,
                      bboxes,
                      labels,
                      segms=None,
                      class_names=None,
                      score_thr=0,
                      bbox_color='green',
                    
                      text_color='green',
                      mask_color=None,
                      thickness=6,
                      font_size=36,
                      win_name='',
                      show=True,
                      wait_time=0,
                      out_file=None):
    """Draw bboxes and class labels (with scores) on an image.

    Args:
        img (str or ndarray): The image to be displayed.
        bboxes (ndarray): Bounding boxes (with scores), shaped (n, 4) or
            (n, 5).
        labels (ndarray): Labels of bboxes.
        segms (ndarray or None): Masks, shaped (n,h,w) or None
        class_names (list[str]): Names of each classes.
        score_thr (float): Minimum score of bboxes to be shown.  Default: 0
        bbox_color (str or tuple(int) or :obj:`Color`):Color of bbox lines.
           The tuple of color should be in BGR order. Default: 'green'
        text_color (str or tuple(int) or :obj:`Color`):Color of texts.
           The tuple of color should be in BGR order. Default: 'green'
        mask_color (str or tuple(int) or :obj:`Color`, optional):
           Color of masks. The tuple of color should be in BGR order.
           Default: None
        thickness (int): Thickness of lines. Default: 2
        font_size (int): Font size of texts. Default: 13
        show (bool): Whether to show the image. Default: True
        win_name (str): The window name. Default: ''
        wait_time (float): Value of waitKey param. Default: 0.
        out_file (str, optional): The filename to write the image.
            Default: None

    Returns:
        ndarray: The image with bboxes drawn on it.
    """
    assert bboxes.ndim == 2, \
        f' bboxes ndim should be 2, but its ndim is {bboxes.ndim}.'
    assert labels.ndim == 1, \
        f' labels ndim should be 1, but its ndim is {labels.ndim}.'
    assert bboxes.shape[0] == labels.shape[0], \
        'bboxes.shape[0] and labels.shape[0] should have the same length.'
    assert bboxes.shape[1] == 4 or bboxes.shape[1] == 5, \
        f' bboxes.shape[1] should be 4 or 5, but its {bboxes.shape[1]}.'
    img = mmcv.imread(img).astype(np.uint8)

    if score_thr > 0:
        assert bboxes.shape[1] == 
  • 5
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
mmdetection是一个开源的目标检测架,用于训练和测试图像中的目标物体。在使用mmdetection进行目标检测任务时,如果我们的数据集的类别数与预训练权重文件基于的MS COCO数据集不一致,我们需要对类别进行修改。 要修改类别,我们需要在模型的配置文件中进行相应的设置。一般来说,我们需要修改两个地方:model和state_dict。在model中,我们可以通过修改meta这个key来设置我们自定义数据集的类别信息。可以使用以下代码来查看meta中包含的基础信息: ```python for metak in model['meta'].keys(): print(metak) ``` 通过打印meta中的内容,我们可以看到包含了关于数据集类别的信息。我们可以根据自己的数据集中的类别数量进行相应的修改。在state_dict中,我们需要修改类别相关的字段,以保证模型在训练和测试时正确地识别和分类目标物体。 综上所述,要修改mmdetection类别,我们需要在模型配置文件中修改model和state_dict的相关字段,以适应自己的数据集的类别信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [修改mmdetection预训练模型权重的类别数,以Pascal VOC为例](https://blog.csdn.net/qq_45586192/article/details/127985800)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值