目标检测-图片与标签不一致问题(YOLO标签为例)

当你在训练代码时,是否遇见过图片与标签不一致的情况?

主要分为以下两种情况:

  • 图片多了,标签少了
  • 标签多了,图片少了

解决方法:

使用代码前请确保标签名字和图片名字对应,且图片后缀一致

import os
import shutil
from tqdm import tqdm


def main(txt_path,img_path):
    img_list=[]
    txt_list=[]

    for i in tqdm(os.listdir(txt_path)):
        txt_name=i.split(".")[0]
        txt_suffix=i.split(".")[-1]
        txt_list.append(txt_name)

    for j in os.listdir(img_path):
        img_name=j.split(".")[0]
        img_suffix=j.split(".")[-1]
        img_list.append(img_name)

    #检查对应的图片是不是有标签,无标签则删除该图片
    for img in tqdm(img_list):
        if img not in txt_list:
            remove_img_path=img_path+"/{}.{}".format(img,img_suffix)
            os.remove(remove_img_path)
            print(remove_img_path)

    #检查对应的标签是不是有图片,无图片则删除该标签
    for txt in tqdm(txt_list):
        if txt not in img_list:
            remove_txt_path=txt_path+"/{}.{}".format(txt,txt_suffix)
            os.remove(remove_txt_path)
            print(remove_txt_path)
if __name__ == '__main__':
    # 需修改为自己的标签文件夹路径
    txt_path = r"D:\desk\test_align\labels"

    # 需修改为自己的图片文件夹路径
    img_path = r"D:\desk\test_align\images"

    main(txt_path,img_path)

仅修改txt_path和img——path即可运行

实验准备

 H_175_1.jpg图片无标签

classes.txt标签无对应图片

开始实验

 

 

 实验结果

可以正确移除有无图片的标签以及无标签的图片

完美~,代码寄几用~

  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
### 回答1: RTMDET (Real-Time Multispectral Detection) is a real-time object detection algorithm developed by researchers at the University of Maryland. It is designed to perform well on a variety of object detection tasks, including detecting objects in infrared and visible spectrum images. If you want to convert RTMDET to the YOLO (You Only Look Once) format, you will need to follow these steps: 1. First, you will need to understand the differences between the two formats. RTMDET is a real-time object detection algorithm that uses a combination of multispectral (infrared and visible spectrum) image features and a convolutional neural network (CNN) to detect objects in images. YOLO is a real-time object detection algorithm that uses a single convolutional neural network to predict object bounding boxes and class probabilities directly from full images in one evaluation. 2. Next, you will need to obtain the necessary data and tools to convert RTMDET to YOLO. This may involve collecting a dataset of images and annotations in the RTMDET format, as well as acquiring the software tools needed to perform the conversion. 3. Once you have the necessary data and tools, you will need to follow a process to convert the RTMDET data and model to the YOLO format. This process may involve converting the RTMDET annotations to the YOLO format, training a YOLO model on the converted data, and fine-tuning the model to improve its performance. It is worth noting that converting RTMDET to YOLO is likely to be a complex and time-consuming task, and may require a significant amount of expertise in computer vision and machine learning. If you are not familiar with these topics, it may be helpful to seek the assistance of a researcher or developer who has experience in object detection and conversion between different object detection formats. ### 回答2: RTMDET是一种目标检测算法,它的输出结果通常使用RTMDET格式进行表示。而YOLO是另一种非常流行的目标检测算法,它的输出结果使用YOLO格式进行表示。为了将RTMDET格式的结果转换为YOLO格式,我们需要进行一些处理。 首先,RTMDET格式的结果通常以矩形框为基础,每个矩形框包含目标的位置和类别信息。而YOLO格式的结果则将整个图像划分为一个个网格单元,每个网格单元负责检测其中包含的目标信息。 对于RTMDET格式的结果,我们可以按照以下步骤转换为YOLO格式: 1. 将原始图像划分为固定大小的网格单元,每个网格单元的大小需要根据具体情况进行调整。 2. 对于每个网格单元,计算其中心点在整个图像中的相对位置,并将其归一化为0到1之间的值。 3. 对于每个网格单元,判断其中是否包含目标物体。如果包含,则将目标的类别信息转换为和YOLO格式一致的编码形式。 4. 对于每个网格单元,计算并保存包含目标的矩形框的位置信息。矩形框的位置信息可以用左上角和右下角的坐标表示,也可以用矩形框的中心点、宽度和高度表示。 通过上述步骤,我们可以将RTMDET格式的结果转换为YOLO格式的结果。这样做的好处是可以统一不同目标检测算法的输出格式,方便进行后续的目标跟踪、目标分类等任务。同时,YOLO格式的结果相对于RTMDET格式的结果更加紧凑,有利于提高目标检测算法的效率。 ### 回答3: 要将rtmdet改为yolo格式,首先需要了解rtmdet和yolo的区别和特点。 rtmdet是一种实时目标检测模型,使用的是两阶段的检测算法,包含了区域生成网络(RPN)和基于Fast R-CNN的检测器。rtmdet可以提供较高的检测精度,但相应地会增加计算量和推理时间。 而yolo(You Only Look Once)是一种单阶段的目标检测模型,其主要特点是将目标检测问题转化为回归问题,采用一个卷积神经网络同时进行目标的定位和分类。yolo模型具有较快的检测速度,但可能在检测小目标和密集目标时存在一定的精度损失。 要将rtmdet改为yolo格式,可以按照以下步骤进行: 1. 数据准备:将rtmdet所需的数据集转化为yolo所需的数据集格式。yolo通常使用的是标签文件(如txt或xml),其中包含了每个样本的目标类别、边界框的坐标和尺寸等信息。 2. 修改网络架构:将rtmdet的网络结构修改为yolo的网络结构。yolo通常采用多个卷积层和池化层,最后接上全连接层和预测层,用于输出目标的检测结果。 3. 调整参数设置:根据yolo的特点,对rtmdet中的一些参数进行调整。例如,yolo中的anchor参数可以用于定义不同尺寸目标的先验框。 4. 训练和测试:使用修改后的yolo格式进行训练和测试。根据实际需求和资源情况,选择适当的训练策略和优化算法。 5.评估和调优:对训练后的模型进行评估和调优,提高检测精度和性能。 通过以上步骤,就可以将rtmdet改为yolo格式,并使用yolo进行目标检测任务。需要注意的是,由于rtmdet和yolo的算法和结构差异,所以在改变模型格式后,性能和精度可能会有所变化,因此需要进行一定的调优和优化。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值