type
status
date
slug
summary
tags
category
icon
password
page icon
该工作个人主观打分:7.5 打分理由:在其他follow CLIP工作在卷任务复杂度和领域适配性的时候,LongCLIP这篇工作在文本长度上进行拓展的创新,有种预期之内的惊喜。整个文章结构清晰明了,读起来很顺畅,对该工作的实现代码写的也很清晰,follow这篇文章的后续工作也有不少,且在civitai的工作流中时不时能看见应用的。

Long Clip

Long-CLIP: Unlocking the Long-Text Capability of CLIP | ECCV2024.
page icon
创新点:A significant limitation of CLIP lies in the inadequate length of text input. The length of the text token is restricted to 77, and an empirical study shows the actual effective length is even less than 20.
总的来说,该文就是想突破 clip 原本 77 个 token 的限制,达到更长 token,能够让相关的下游应用(图像生成) 能够应对更加丰富的细节和对齐能力。但是在实验过程中,发现 clip 在位置 20 以后的 token 其实训练的都不太行。所以该文把前 20 个 token 的 embedding 保留,然后重新训练了 20 以后的token。
挑战:想当然的去直接训练一个长的 clip 并不合适:
page icon
Nevertheless, achieving this goal is far from straightforward, as simplistic fine-tuning can result in a significant degradation of CLIP’s performance.
 
所以提出两个办法来做:
  • Knowledge-preserved stretching of positional embedding 位置嵌入在保留知识的情况下拉长
  • primary component matching of CLIP Features 和 CLIP 特征的主成分匹配
 

训练数据:1-million extra long text-image pairs。
效果:20%的 long-caption text-image Retrieval,6%的 traditional text-image Retrieval 的提升
notion image

扩展性

由 CLIP 的 77 变成了 256 的长度

技术方案

首先说了下常见的 image-text pair 的数据集:Visual Genome [10], Conceptual-12M [1], SBU [19], COCO [15], LAION-5B 这些基本都是短的 caption。然后他们 找了个叫 ShareGPT4V 的数据集,有长的 caption,大概 1.2 million 个数据对。

CLIP 的有效长度

作者认为 CLIP 虽然最大长度是 77,但有效长度更短。他们用了一个自己建的数据集叫 urban-200 (后续做了一个urban-1k 公开在了 huggingface:https://huggingface.co/datasets/BeichenZhang/Urban1k
After the first submission, we further scaled up Urban-200 into Urban-1k. The dataset has been released at https://huggingface.co/datasets/BeichenZhang/Urban1k. Urban-200 is used in the main paper. Detailed results about Urban-1k is shown in supplementary materials.
他们认为理论上随着 text 的长度增加,信息越丰富,那么图片的 Retrieve 能力会增强(应为对该图片的描述增多了),然而他们通过实验发现,CLIP 的 R@1 准确率在文字长度超过 20 以后就增长的非常缓慢了,所以认为 CLIP 的有效长度实际上在 20.
 
notion image
此外,他们还发现 clip 模型在对图片进行训练时,由于是整个图片和整个 caption 进行配对的,所以对于图片的细节内容容易混淆。这里给了个例子:一张图片里含有柠檬(左)和茄子(右)。然后写 4 个 prompt,分别物体的位置和颜色进行混淆。
 
理想的情况下是 A 第一,然而 CLIP 把 A 排最后。

Knowledge Preserving Stretching

Therefore, instead of performing full interpolation with a fixed value, we choose to retain the embedding of the top 20 positions, which aligns with the effective length identified in our experiment. As for the remaining 57 positions, we apply interpolation using a larger ratio denoted as λ2. This process can be mathematically formulated as follows
notion image
也就是对 positional encoding 进行重新训练, 但保留位置在 20 及以内的。对于 20-77 的,用另外一个 function 去做插入,这里 λ2设置为 4,两个符号不一样估计是向下取整和向上取整把。这里把 pos 最大限制为 248, 这里也就是 PE(x)中的 x 应该不超过 62。
具体代码如下
LongClip/model/longclip.py --> def load_from_clip
他们还把这种改过的方法和直接插值的方法的最后微调效果做了比较,确实 direct fine-tuning 可能会下降,也可能会提升,但他们的这种一定会提升。
notion image
 
在具体训练中,参数设置如下,
notion image

Fine-tuning with Primary Component matching

文中说只把模型在长的 caption 上微调是不太行的,会把模型推向另一个极端,也就是不分重点的把图片的所有描述细节都融合到 embedding 里。
Merely fine-tuning the model with long captions may push it to another extreme, where it attempts to encompass all attributes in a single image without distinguishing their respective importance.
 
所以文章中同样做了粗粒度的 shot summary caption 的图像 文本对的数据准备,然后训练
Apart from aligning the fine-grained feature of an image with its long caption, we extract a coarse-grained image feature that focuses on capturing key attributes. This coarse-grained feature is then aligned with a short summary caption.By doing so,we require the model not only to capture detailed attributes but also to discern and prioritize the importance of different attribute
 
为此,做了三个 modules,(分解、过滤、重建)
  • component docomposition function F, This function decomposes the feature into several vectors that represent different attributes and also analyzes the importance of each attribute.
  • component-filtration function E,根据重要性来过滤掉不重要的 attributes
  • component-reconstruction function F−1, reconstruct the image feature
 
notion image
 
notion image
 
notion image
 
这里的 F 用的是 PCA,然后用 32 个最大的 eigen value 来保证最大的重要性得以保留。然后再反过去重建得到这个 coarse 输出。

实际表现

notion image
notion image
notion image
 
Relate Posts
MobileAgent系列学习 — Mobile Agent v2
Lazy loaded image
MobileAgent系列学习 — FERRET-UI 2
Lazy loaded image
CLIP系列学习(八) — CLIPSeg
Lazy loaded image
CLIP系列学习(七)— SigLIP
Lazy loaded image
CLIP系列学习(二) — BLIP & BLIP 2
Lazy loaded image
CLIP系列学习(一)— CLIP
Lazy loaded image
CLIP系列学习(四) — CLIP in Medical ImagingCLIP系列学习(二) — BLIP & BLIP 2
Loading...
Yixin Huang
Yixin Huang
一个热爱生活的算法工程师
Latest posts
时间序列论文阅读 — TimeCMA(AAAI 2025)
2025-4-23
时间序列论文阅读-ChatTime: A Unified Multimodal Time Series Foundation Model Bridging
2025-4-23
VLM系列论文阅读-Mixed Preference Optimization (MPO)
2025-2-6
VLM系列论文阅读 — Flamingo
2025-2-6
认识你自己,才是这件事的最终乐趣 — 抄录
2025-2-5
用GPT4学量化投资 — Junior Level - Unit 1: Introduction to Stock Markets and Data Handling
2025-1-23
Announcement
🎉NotionNext 4.5已经上线🎉
-- 感谢您的支持 ---
👏欢迎更新体验👏