多模态(红外,可见光)目标检测

这篇具有很好参考价值的文章主要介绍了多模态(红外,可见光)目标检测。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

【github】https://github.com/DocF/multispectral-object-detection

一.环境

1.1 环境

基本依赖和yolov5基本相同,当然也可以配置在虚拟环境中

git clone https://github.com/DocF/multispectral-object-detection
cd  multispectral-object-detection
pip install -r requirements.txt

1.2 报错解决

1.2.1 找不到sppf

AttributeError: Can't get attribute 'SPPF' on <module 'models.common' from '/hy-tmp/multispectral-object-detection/models/common.py'>

【参考文章】找不到SPPF错误
在models/common.py下找到ssp,将下面这段添加到ssp之前

class SPPF(nn.Module):
    def __init__(self, c1, c2, k=5):
        super().__init__()
        c_ = c1 // 2
        self.cv1 = Conv(c1, c_, 1, 1)
        self.cv2 = Conv(c_ * 4, c2, 1, 1)
        self.m = nn.MaxPool2d(kernel_size=k, stride=1, padding=k // 2)
 
    def forward(self, x):
        x = self.cv1(x)
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')
            y1 = self.m(x)
            y2 = self.m(y1)
            return self.cv2(torch.cat([x, y1, y2, self.m(y2)], 1))

1.2.2

RuntimeError: result type Float can't be cast to the desired output type __int64

【参考】报错解决方法
将下面这段替换utils/loss.py中build_targets函数,注意保留返回值

        for i in range(self.nl):
            anchors, shape = self.anchors[i], p[i].shape
            gain[2:6] = torch.tensor(shape)[[3, 2, 3, 2]]  # xyxy gain
 
            # Match targets to anchors
            t = targets * gain  # shape(3,n,7)
            if nt:
                # Matches
                r = t[..., 4:6] / anchors[:, None]  # wh ratio
                j = torch.max(r, 1 / r).max(2)[0] < self.hyp['anchor_t']  # compare
                # j = wh_iou(anchors, t[:, 4:6]) > model.hyp['iou_t']  # iou(3,n)=wh_iou(anchors(3,2), gwh(n,2))
                t = t[j]  # filter
 
                # Offsets
                gxy = t[:, 2:4]  # grid xy
                gxi = gain[[2, 3]] - gxy  # inverse
                j, k = ((gxy % 1 < g) & (gxy > 1)).T
                l, m = ((gxi % 1 < g) & (gxi > 1)).T
                j = torch.stack((torch.ones_like(j), j, k, l, m))
                t = t.repeat((5, 1, 1))[j]
                offsets = (torch.zeros_like(gxy)[None] + off[:, None])[j]
            else:
                t = targets[0]
                offsets = 0
 
            # Define
            bc, gxy, gwh, a = t.chunk(4, 1)  # (image, class), grid xy, grid wh, anchors
            a, (b, c) = a.long().view(-1), bc.long().T  # anchors, image, class
            gij = (gxy - offsets).long()
            gi, gj = gij.T  # grid indices
 
            # Append
            indices.append((b, a, gj.clamp_(0, shape[2] - 1), gi.clamp_(0, shape[3] - 1)))  # image, anchor, grid
            tbox.append(torch.cat((gxy - gij, gwh), 1))  # box
            anch.append(anchors[a])  # anchors
            tcls.append(c)  # class

二. 数据集处理

2.1 数据集下载

【github】https://github.com/DocF/multispectral-object-detection包含了对应的链接

链接:https://pan.baidu.com/s/1zO_1Olognq2atY6m4StZUA?pwd=4i77 提取码:4i77
–来自百度网盘超级会员V1的分享

权重还有数据集全部都打包在这里面了

2.2 数据集放置格式

其实没有严格的规定,我的话是这样:在datasets文件夹下
多模态(红外,可见光)目标检测

2.3 数据集预处理成txt

以FLIR(就是那个align)为例

2.3.1 训练集验证集

split_train_val.py

import os
import random
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('--xml_path', type=str, help='input xml label path')
parser.add_argument('--txt_path', type=str, help='output txt label path')
opt = parser.parse_args()

trainval_percent = 1.0
train_percent = 0.9
xmlfilepath = opt.xml_path
txtsavepath = opt.txt_path
total_xml = os.listdir(xmlfilepath)
if not os.path.exists(txtsavepath):
  os.makedirs(txtsavepath)

num=len(total_xml)
list=range(num)

ftrainval = open(txtsavepath + '/trainval.txt', 'w')
ftest = open(txtsavepath + '/test.txt', 'w')
ftrain = open(txtsavepath + '/train.txt', 'w')
fval = open(txtsavepath + '/val.txt', 'w')

for i in list:
    name=total_xml[i][:-4]+'\n'
    ftrainval.write(name)
    if i%7 == 0:
        fval.write(name)
    else:
        ftrain.write(name)

ftrainval.close()
ftrain.close()
fval.close()
ftest.close()

输入命令:

python split_train_val.py --xml_path xml文件路径 --txt_path 输出txt文件路径

(1)xml文件路径:我是先将xml为文件全部放到一个文件夹里面
以我的为例就是:

cp D:\computervision\cross\detection\align\Annotations\*.xml D:\computervision\cross\detection\align\annotation 

(2)输出txt文件路径:直接输出到前面提到的datasets下
得到下面这四个
多模态(红外,可见光)目标检测

2.3.2 格式转换

voc_label.py文件,应该改一下路径就可以用了,就不多说了

import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir, getcwd
from os.path import join

sets=['train', 'val', 'test']
classes = ['person','car','bicycle']

abs_path = os.getcwd()
def convert(size, box):
    dw = 1./(size[0])
    dh = 1./(size[1])
    x = (box[0] + box[1])/2.0 - 1
    y = (box[2] + box[3])/2.0 - 1
    w = box[1] - box[0]
    h = box[3] - box[2]
    x = x*dw
    w = w*dw
    y = y*dh
    h = h*dh
    return (x,y,w,h)
def convert_annotation(image_id ,RGBid ):
    in_file = open(r'D:\computervision\cross\detection\align\annotation\%s.xml'%( image_id))
    irout_file = open('D:\computervision\cross\detection\multispectral-object-detection-main\datasets\IR\labels\%s.txt'%(image_id), 'w')
    rgbout_file= open('D:\computervision\cross\detection\multispectral-object-detection-main\datasets\RGB\labels\%s.txt'%(RGBid), 'w')
    tree=ET.parse(in_file)
    root = tree.getroot()
    size = root.find('size')
    w = int(size.find('width').text)
    h = int(size.find('height').text)
    for obj in root.iter('object'):
        #difficult = obj.find('difficult').text
        cls = obj.find('name').text
        if cls not in classes :
            continue
        cls_id = classes.index(cls)
        xmlbox = obj.find('bndbox')
        b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text))
        bb = convert((w,h), b)
        irout_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')
        rgbout_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')

for image_set in sets:
    # if not os.path.exists('D:\computervision\cross\detection\multispectral-object-detection-main\datasets'):
    #     os.makedirs('D:\computervision\cross\detection\multispectral-object-detection-main\datasets')
    #创建两个txt文件
    #(1)先创建rgb文件
    #
    image_ids = open('D:\computervision\cross\detection\multispectral-object-detection-main\datasets\%s.txt'%(image_set)).read().strip().split()
    ir_file = open('D:\computervision\cross\detection\multispectral-object-detection-main\datasets\IR\%s.txt'%(image_set), 'w')
    rgb_file= open('D:\computervision\cross\detection\multispectral-object-detection-main\datasets\RGB\%s.txt'%(image_set), 'w')
    for image_id in image_ids:
        ir_file.write('D:\computervision\cross\detection\multispectral-object-detection-main\datasets\IR\images\%s.jpeg\n'%(image_id))
        id=image_id.split("_")[1]
        RGBid='FLIR_'+id+"_RGB"
        rgb_file.write(
            'D:\computervision\cross\detection\multispectral-object-detection-main\datasets\RGB\images\%s.jpg\n' % (RGBid))

        convert_annotation(image_id,RGBid)
    ir_file.close()
    rgb_file.close()

三 .训练

修改data/multispectral/FLIR_aligned.yaml文件夹

多模态(红外,可见光)目标检测
直接

python train.py

多模态(红外,可见光)目标检测文章来源地址https://www.toymoban.com/news/detail-430716.html

到了这里,关于多模态(红外,可见光)目标检测的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 热红外相机图片与可见光图片配准教程

    图像配准是一种图像处理技术,用于将多个场景对齐到单个集成图像中。在这篇文章中,我将讨论如何在可见光及其相应的热图像上应用图像配准。在继续该过程之前,让我们看看什么是热图像及其属性。 热图像本质上通常是灰度图像:黑色物体是冷的,白色物体是热的,灰

    2024年02月07日
    浏览(26)
  • 红外图像和可见光图像异源图像配准问题研究

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 图像配准方法有很多,可分为基于灰度的图像配准方法和基于特征的图像配准方法,其中基于特征的图像配准方法是目前图像配准算法中常用方法,如尺度不变特征变换(Scale Invariant Feature Transform, SIF

    2023年04月11日
    浏览(28)
  • 图像融合论文阅读:CrossFuse: 一种基于交叉注意机制的红外与可见光图像融合方法

    @article{li2024crossfuse, title={CrossFuse: A novel cross attention mechanism based infrared and visible image fusion approach}, author={Li, Hui and Wu, Xiao-Jun}, journal={Information Fusion}, volume={103}, pages={102147}, year={2024}, publisher={Elsevier} } 论文级别:SCI A1 影响因子:18.6 📖[论文下载地址] 💽[代码下载地址] 以往的交

    2024年01月15日
    浏览(37)
  • 【图像融合】小波变换可见光与红外光图像融合(带面板)【含GUI Matlab源码 701期】

    ✅博主简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,Matlab项目合作可私信。 🍎个人主页:海神之光 🏆代码获取方式: 海神之光Matlab王者学习之路—代码获取方式 ⛳️座右铭:行百里者,半于九十。 更多Matlab仿真内容点击👇 Matlab图像处理(进阶版) 路径规划

    2024年02月19日
    浏览(34)
  • 【红外与可见光图像融合】离散平稳小波变换域中基于离散余弦变换和局部空间频率的红外与视觉图像融合方法(Matlab代码实现)

     💥💥💞💞 欢迎来到本博客 ❤️❤️💥💥 🏆博主优势: 🌞🌞🌞 博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。 ⛳️ 座右铭: 行百里者,半于九十。 📋📋📋 本文目录如下: 🎁🎁🎁 目录 💥1 概述 📚2 运行结果 🎉3 参考文献 🌈4 Matlab代码及文献 基于

    2024年02月07日
    浏览(35)
  • 图像融合论文阅读:CS2Fusion: 通过估计特征补偿图谱实现自监督红外和可见光图像融合的对比学习

    @article{wang2024cs2fusion, title={CS2Fusion: Contrastive learning for Self-Supervised infrared and visible image fusion by estimating feature compensation map}, author={Wang, Xue and Guan, Zheng and Qian, Wenhua and Cao, Jinde and Liang, Shu and Yan, Jin}, journal={Information Fusion}, volume={102}, pages={102039}, year={2024}, publisher={Elsevier} } 论文级

    2024年01月22日
    浏览(43)
  • ADAS-可见光相机之Cmos Image Sensor

    “ 可见光相机在日常生活、工业生产、智能制造等应用有着重要的作用。在ADAS中更是扮演着重要的角色,如tesla model系列全车身10多个相机,不断感知周围世界。本文着重讲解下可见光相机中的CIS(CMOS Image Sensor)。” 光是一种电磁波,自然界的光是由各种波长的电磁波组成,

    2024年02月09日
    浏览(27)
  • 【CVPR小目标检测】- ISNet红外小目标检测

    红外图像:    红外小目标使用红外热成像技术,使得 红外目标检测能够全天候工作 ,可视距离远,抗干扰能力强。当像素距离较远时,目标所占比例小、亮度低,呈现弱小目标。红外图像中,弱小目标所占像素非常少,特征不明显、容易被杂波、热源等噪声干扰。 贡献

    2024年02月09日
    浏览(27)
  • 目标检测数据集:红外图像弱小飞机目标检测数据集

    ✨✨✨✨✨✨目标检测数据集✨✨✨✨✨✨ 本专栏提供各种场景的数据集,主要聚焦: 工业缺陷检测数据集、小目标数据集、遥感数据集、红外小目标数据集 ,该专栏的数据集会在多个专栏进行验证,在多个数据集进行验证mAP涨点明显, 尤其是小目标、遮挡物精度提升明显

    2024年02月08日
    浏览(26)
  • 综述:自动驾驶中的多模态 3D 目标检测

    在驾驶场景中,自动驾驶车辆需要精准高效的感知运算,时刻预测其所处的驾驶环境。 其中,感知系统将各种传感器数据转化为语义信息,是自动驾驶系统的核心和不可缺少的组成部分。 图像具有丰富的语义信息,点云包含深度信息。 两者具有互补特性,可以提高三维物体

    2024年02月03日
    浏览(32)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包