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

news2024/9/20 18:36:43

请添加图片描述
【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

1.2.3

Exception in thread Thread-9:
Traceback (most recent call last):
  File "/usr/local/miniconda3/envs/PIAFusion/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/local/miniconda3/envs/PIAFusion/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/hy-tmp/multispectral-object-detection/utils/plots.py", line 164, in plot_images
    mosaic[block_y:block_y + h, block_x:block_x + w, :] = img
ValueError: could not broadcast input array from shape (519,640,6) into shape (519,640,3)
Exception in thread Thread-10:
Traceback (most recent call last):
  File "/usr/local/miniconda3/envs/PIAFusion/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/local/miniconda3/envs/PIAFusion/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/hy-tmp/multispectral-object-detection/utils/plots.py", line 164, in plot_images
    mosaic[block_y:block_y + h, block_x:block_x + w, :] = img
ValueError: could not broadcast input array from shape (519,640,6) into shape (519,640,3)

二. 数据集处理

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

请添加图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/80181.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

基于燃压缩空气储能系统的零碳微能源互联网优化调度(Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️❤️&#x1f4a5;&#x1f4a5;&#x1f4a5; &#x1f468;‍&#x1f4bb;做科研&#xff0c;涉及到一个深在的思想系统&#xff0c;需要科研者逻辑缜密&#xff0c;…

由美国火星照片细节,分析造假的疑点

穿帮都是细节。 除了阿波罗登月&#xff0c;你觉得美国还在哪些航天项目中有造假嫌疑&#xff1f; - 知乎 西红柿加醋 能走着游泳就好了 ​ 关注 无可靠信息来源 423 人赞同了该回答 除了登月&#xff0c;比较又争议的当然就数登火了&#xff0c;比如出自Nasa官方网站上的…

CSS布局-定位,相对,绝对,子绝父相,固定定位,层级关系。

CSS布局-定位&#xff0c;相对&#xff0c;绝对&#xff0c;子绝父相。 目录CSS布局-定位&#xff0c;相对&#xff0c;绝对&#xff0c;子绝父相。1、定位1.1 网页常见布局方式1.2 定位的常见应用场景2.1 定位初体验2.2 使用定位的步骤3.1 静态定位4.1 相对定位5.1 绝对定位5.…

矩阵理论复习(五)

2004年试题 Hermite矩阵酉相似于对角阵 验证相容矩阵范数 盖尔圆盘互不相交&#xff0c;则特征值都不相同&#xff0c;若盖尔圆盘全部出现在右半复平面上&#xff0c;则特征值全为实数。 矩阵二范数的计算 最大秩分解M-P广义逆矩阵方程是否有解 2005年试题 正定矩阵&a…

【秒杀购物商城业务服务】「分布式架构服务」盘点中间件服务的高可用模式及集群技术的方案分析

秒杀购物商城业务服务-分布式架构介绍 基于MySQL数据库集群技术实现服务的高可用基于Tomcat的集群负载机制实现Tomcat服务器的高可用基于Nginx负载均衡机制实现负载均衡&#xff08;介绍和配置&#xff09;基于Redis缓存服务实现数据缓存控制相关介绍和技术点分析 基于MySQL数…

RTC 时钟电路如何选择法拉电容的容量

理论依据&#xff1a; 公式 1&#xff1a;Q I * t 公式 2&#xff1a;Q CU 由此推导出→I * t CU →t CU/I(将根据这个计算时钟保留时长) 说明 Q&#xff1a; 电荷量 &#xff08;单位&#xff1a;库仑&#xff09;I&#xff1a; 电流 &#xff08;单位&#xff1a;安培&a…

QT/C语言 实现数据库sqlite3

QT/C语言 实现数据库sqlite3【1】引入数据库【2】下载移植sqlite31.移植sqlite32.使用sqlite33.sqlite3中的数据类型4.常用的SQL语句(全部都是分号结尾)(1)新建表格(2)往表格中插入数据(3)查询表格中的数据(4)删除表格中的数据(5)修改表格中的数据【3】C语言调用sqlite31.接口函…

第10部分 DHCP

目录 10.1 DHCP 概述 10.2 实验1&#xff1a;DHCP 基本配置 1.实验目的 2.拓扑结构 3.实验步骤 4.实验调试 &#xff08;1&#xff09;在客户端测试 &#xff08;2&#xff09;show ip dhcp pool &#xff08;3&#xff09;show ip dhcp binding 10.3 实验&#xff…

LeetCode 1827. 最少操作使数组递增

最少操作使数组递增 简单 46 相关企业 给你一个整数数组 nums &#xff08;下标从 0 开始&#xff09;。每一次操作中&#xff0c;你可以选择数组中一个元素&#xff0c;并将它增加 1 。 比方说&#xff0c;如果 nums [1,2,3] &#xff0c;你可以选择增加 nums[1] 得到 nums …

实战讲解Spring定时任务:@Scheduled(图+文+源码)

1 缘起 最近看到有些定时任务的项目&#xff0c; 使用了Spring自带的定时任务系统&#xff0c;通过添加Scheduled注解的方式实现&#xff0c; 并且&#xff0c;使用了不只cron表达式的方式实现定时执行&#xff0c; 恍然大悟&#xff0c;原来Scheduled还有其他的方式实现定时任…

《小猫猫大课堂》3之字符串,转义字符,注释,选择和循环语句,函数等小概括。

更新不易&#xff0c;麻烦多多点赞&#xff0c;欢迎你的提问&#xff0c;感谢你的转发&#xff0c; 最后的最后&#xff0c;关注我&#xff0c;关注我&#xff0c;关注我&#xff0c;你会看到更多有趣的博客哦&#xff01;&#xff01;&#xff01; 喵喵喵&#xff0c;你对我…

这十套练习,教你如何用Pandas做数据分析(01)

Pandas是入门Python做数据分析所必须要掌握的一个库。本文内容由和鲸社区翻译整理自Github&#xff0c;建议读者完成科赛网 从零上手Python关键代码 和 Pandas基础命令速查表 教程学习的之后&#xff0c;点击本篇Notebook右上角的 Fork 按钮对本教程代码进行调试学习。 转载本…

(附源码)SSM的KTV管理系统 毕业设计 291807

基于SSM的KTV管理系统 摘 要 随着社会的发展&#xff0c;人类的进步&#xff0c;21世纪人们的生活水平有所提高&#xff0c;为了满足人们对生活的需要&#xff0c;丰富业余生活&#xff0c;娱乐KTV等行业蓬勃发展&#xff0c;在数字化的今天&#xff0c;我们已离不开计算机&…

Redis的面试题

一、Redis支持的数据类型&#xff1f; Redis支持的数据类型主要有五种&#xff1a;string&#xff08;字符串&#xff09;&#xff0c;hash&#xff08;哈希&#xff09;&#xff0c;list&#xff08;列表&#xff09;&#xff0c;set&#xff08;集合&#xff09;及zset(sorte…

opencv图像特征

图像特征类型可以分为如下三种&#xff1a; 边缘角点&#xff08;感兴趣关键点&#xff09;斑点&#xff08;感兴趣区域&#xff09; 其中&#xff0c;角点是个很特殊的存在。如果某一点在任意方向的一个微小变动都会引起灰度很大的变化&#xff0c;我们就把它称之为角点。角点…

17、Redis6.0新功能

文章目录17、Redis6.0新功能17.1 ACL17.1.1 简介17.1.2 命令17.2 IO多线程17.2.1 简介17.2.2 原理架构17.3 工具支持 Cluster17.4 Redis新功能持续关注Redis 6 入门到精通-讲师&#xff1a;王泽 世态炎凉&#xff0c;世界并不善良 17、Redis6.0新功能 17.1 ACL 17.1.1 简介 …

如何利用场追迹控制衍射的包含

1. 摘要 VirtualLab Fusion包括一系列建模方法便于用户可以地调整光学仿真的精度级别和时间。不仅如此&#xff0c;这种功能还有助于隔离物理原因产生的不同影响。在本示例中&#xff0c;我们提出了一个清晰的工作流程配置一个仿真&#xff0c;以便在物理光学模拟中考虑或忽略衍…

MOSFET 和 IGBT 栅极驱动器电路的基本原理学习笔记(六)变压器耦合栅极驱动

变压器耦合栅极驱动 1.单端变压器耦合栅极驱动电路 2.双端变压器耦合栅极驱动 在高电压栅极驱动 IC 出现以前&#xff0c;使用栅极驱动变压器是唯一一种在离线或类似高电压电路中驱动高侧开关的可行解决方案。 现在&#xff0c;两种解决方案同时存在并且各有利弊&#xff0c;…

基础数据结构线性表

基础数据结构 1.基础概念 数据结构是一种具有一定逻辑关系&#xff0c;在计算机中应用某种存储结构&#xff0c;并且封装了相应操作的数据元素的集合。它包含三方面的内容&#xff0c;逻辑关系、存储关系以及操作。 一般而言&#xff0c;数据结构的选择首先会从抽象数据类型…

springboot整合Canal实时同步数据库表

一、Canal介绍 1、应用场景 在前面的统计分析功能中&#xff0c;我们采取了服务调用获取统计数据&#xff0c;这样耦合度高&#xff0c;效率相对较低&#xff0c;目前我采取另一种实现方式&#xff0c;通过实时同步数据库表的方式实现&#xff0c;例如我们要统计每天注册与登…