Toward Generalist Anomaly Detection via In-context Residual Learning with Few-shot Sample Prompts

原文 https://arxiv.org/pdf/2403.06495
代码 https:// github.com/ mala-lab/ InCTRL
数据集 ELPV SDD AITEX VisA \ BrainMRI HeadCT \ MNIST CIFAR-10

一、方法原理
本文作者研究了广义异常检测问题(GAD),目的是训练一个单一的检测模型,这个模型泛化能力强,可以检测不同领域的未经处理数据集中的异常。本文提出的方法叫做InCTRL(incontext residual learning model for GAD),它结合了图像和文本提示,它的主要思想是利用查询图像和少量正常样提示之间的残差学习来进行异常样本和正常样本的分类,使异常查询样本与样本提示之间的差异会远大于正常查询样本与样本提示之间的差异。InCTRL通过学习这种差异,可以实现跨不同领域数据的泛化,从而在无需训练或微调的情况下,只通过比较目标数据集给定测试数据的差异判别异常和正常样本。在实验设置上,作者选取了来自工业、医学和语义领域的9个异常数据集,采用其他的全样本和小样本检测方法进行对比实验,评价指标为AUPRC\AUROC,还进行了消融实验。
该方法主要是两部分构成:文本编码和视觉编码。对辅助数据进行训练,在视觉编码器中,利用不同层对辅助数据进行卷积,分别查询计算查询图像和小样本正常样本提示之间的局部和全局残差。在文本编码器中,融合正常和异常文本提示引导的先验知识,

在这里插入图片描述
辅助数据:Dtrain={Xtrain, Ytrain},Xtrain={xi}是包含N个正常图像和异常图像的数据集,Ytrain={yi}是对应xi的标签,当yi=0时,xi是正常图像;当yi=1时,xi是异常图像。
小样本异常数据提示P’:P={p1, p2, …, pk},K远远小于N,
编码器:ft( )表示文本编码器,fv( )表示视觉编码器。
损失:本文的损失有2部分组成,分别是LIRL和Lh
Block i:可以从图中看到,视觉编码器中Block共有n个,
1.视觉编码器
CLIP视觉编码器由一系列块层组成。从底层到顶层,视觉编码器逐渐学习不同抽象层次上的视觉模式。从图示可以看出,本文中视觉编码器中Block共有n个,通过不同的层依次对输入的查询图像x和一系列的小样本正常图像提示P′进行逐渐的残差学习。残差学习还在图像级别进行。下面对两部分原理进行说明。
1.1。Multi-Layer Patch-Level Residual Learning
假设视觉编码器由n个块组成,对于给定的一组小样本正常样本提示P′和训练查询图像x,提取一系列块标记嵌入映射和,其中Tl(·)∈Rh×w×d和x′∈P′,h,w和d分别是特征图T的高度,宽度和维度。在每一层layer,通过P′中所有图像提示xi和查询图像x提示的嵌入之间的距离来捕获patch-level的残差。视觉编码器由多个层次的Block组成,层与层之间通过逐步的学习来捕捉不同层次的视觉模式。每个Block的输出包括一个class embedding和多个patch embeddings,其中class embedding负责捕捉全局图像级信息,而patch embeddings则代表局部图像块级的信息。
在形式上,对于查询图像x,它在每一层与提示图像之间的,其中x的每个块的残差值根据它的块嵌入和所有图像的最近块嵌入计算:
在这里插入图片描述
最终的patch-level残差图Mx是在n层残差图上取平均得到,对于给定的查询图像x,在层级上计算其图像块级别上下文差异,差异图通过比较查询图像的patch embeddings和少量正常样本提示中所有图像的最相似patch embeddings来建模。函数 h(·)返回与查询图像最相似的patch embeddings。最终的图像块级差异图就是通过对n个层级的残差图进行平均得到的:
在这里插入图片描述

1.2。Image-level Residual Learning
本文还比较查询图像与少量正常样本提示的全局(图像级)特征来学习全局差异,帮助捕捉到图像整体层面的异常特征。选择了CLIP视觉编码器最后一个block输出的class embedding作为特征输入,引入了一个Adapter来进一步将获取的图像表征适配到异常检测任务中,并基于适配后的图像特征来学习图像级异常。使用的是少量样本提示的原型特征(prototype)来学习上下文差异,因原型特征通常能够捕捉到正常模式的更具代表性的特征Ip:

在这里插入图片描述
通过对查询图像的特征图和原型特征进行逐元素的减法操作,获得了上下文图像级差异特征Fx:
在这里插入图片描述
最后,这些上下文图像级残差特征被输入到图像级异常分类学习器中,以基于图像级信息获得异常分数。通过二分类损失函数Lb来优化:
在这里插入图片描述
2.文本编码器
文本编码器是利用融合文本提示的先验知识,通过引入正常和异常的文本提示,利用文本-图像联合表征空间中的先验知识。这种做法帮助InCTRL利用CLIP预训练时的图像文本对齐信息,把握正常和异常样本背后的语义差异,进一步提升异常检测的性能。具体来说,假设有一组定义正常的文本提示集合,记为Pn,使用CLIP的文本编码器得到这些文本提示的特征表示,并使用正常的文本提示特征的原型特征)作为正常文本的表征。类似地,是异常性文本提示集Pa的原型特征。InCTRL根据查询图像x与两个文本提示原型之间的相似度,提取面向异常检测的判别分数。实际上这是利用查询图像特征与原型特征之间的余弦相似度的softmax概率表示的。因此,所得分数代表x被分类为异常的概率

在这里插入图片描述
3.损失函数
在辅助数据集上优化InCTRL模型,使其能够在不同领域的测试数据集上直接应用,无需额外训练。在测试时,直接利用目标数据集的少量正常样本作为提示,计算测试图像的异常分数。具体地,在训练过程中,对于每个查询图像,首先定义上下文残差图:
在这里插入图片描述
这个残差图由3个部分组成:(1)Mx: 多层次图像块级上下文差异图 ;(2)si(x): 图像级残差图的异常分数,基于函数得出;(3)sa(x): 基于文本提示的异常概率,它表示了作为异常的可能性。
这些组成部分通过逐元素相加结合在一起,得到整个查询图像的残差图 。最终的异常分数被表示为:
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/352ba9e5a3394985ab65924d717a720d.png#pic_center 300x100)
最终,通过比较预测值和真实标签来优化最终的异常得分:
在这里插入图片描述
而InCTRL的最终优化是通过最小化整体损失函数来实现的:
在这里插入图片描述

### Q-Learning Algorithm for Drone Swarm Control In the context of unmanned aerial vehicles (UAVs), particularly when dealing with a swarm, implementing reinforcement learning techniques such as Q-learning can significantly enhance coordination and navigation capabilities among multiple drones. The essence lies in training each agent within the swarm to make decisions based on rewards or penalties received from its environment. The objective is to maximize cumulative reward over time by selecting optimal actions given specific states. For UAV swarms, this translates into optimizing flight paths while avoiding collisions and maintaining formation integrity. Each follower drone learns through interactions with both the target drone and other followers, adjusting its behavior according to feedback obtained during missions[^1]. #### State Representation For effective implementation of Q-learning in drone swarms: - **State Space**: Defined using parameters like relative positions between drones, velocities, distances to obstacles, etc. - **Action Set**: Includes discrete movements that allow drones to navigate towards desired locations safely without colliding with one another or external objects. Actions might include moving up, down, left, right, forward, backward, hovering, accelerating, decelerating, turning at certain angles, changing altitude levels, etc. #### Reward Function Design Designing an appropriate reward function plays a crucial role in guiding agents toward desirable outcomes efficiently. Rewards should encourage behaviors beneficial for achieving mission objectives—such as staying close enough but not too near to targets, keeping formations stable under varying conditions—and discourage undesirable ones like excessive speed changes which could lead to instability or accidents. ```python def calculate_reward(current_state, next_state): distance_to_target = get_distance(next_state['target_position'], next_state['follower_position']) if collision_detected(): return -10 elif distance_improved(current_state, next_state): return 5 else: return -1 ``` This Python snippet demonstrates how simple rules-based logic can be applied to compute immediate rewards after taking action A transitioning state S to new state S'. Adjustments may vary depending upon application specifics; however, core principles remain consistent across implementations involving multi-agent systems controlled via RL algorithms. #### Exploration vs Exploitation Balance During early stages of training, exploration dominates so that all possible strategies are explored adequately before exploiting learned knowledge more aggressively later on. Techniques such as epsilon-greedy policies help strike this balance effectively ensuring sufficient discovery alongside exploitation phases throughout learning process. --- --related questions-- 1. How does incorporating deep neural networks improve performance compared to traditional tabular methods? 2. What challenges arise specifically due to communication latency issues amongst members within large-scale UAV swarms? 3. Can you provide examples where real-world applications have successfully utilized these concepts beyond simulation environments? 4. Are there alternative approaches besides Q-learning worth considering for similar tasks? If yes, what advantages do they offer? 5. In practical scenarios, how would safety measures against unpredictable environmental factors integrate into existing frameworks discussed here?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值