GLIP

Grouded Language-Image Pre-training[1]

作者是来自UCLA、Microsoft Reserach、UW等机构的Liunian Harold Li, Pengchuan Zhang等人。论文引用[1]:Li, Liunian Harold et al. “Grounded Language-Image Pre-training.” 2022 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) (2021): 10955-10965.

Time

  • 2022.Jun

Key words

  • object-level represetation
  • 一句话总结:GLIP将detection转化为一个grounding tasks,通过将每个region/box和text prompt的phrases进行对齐,GLIP联合训练image和language encoder,来预测正确地regions/words的pairings。同时增加了两个modalities之间的fusion,来学习language-aware visual representation

总结:

  1. 论文提出了一个grounded language-image pretraining model,用于学习object-level, language-aware和semantic-rich visual representations。GLIP统一了object detection和phrase grounding for pretraining。这个统一带来了两个好处: 1. 使得GLIP能够从detection和grounding data中学习,提高tasks和bootstrap a good grounding model. 2.GLIP通过self-training的方式,产生grounding boxes,能够利用大量的imag-text pairs,使得学习到的representations semantic-rich
  1. visual recognition model通常被训练用来预测预先定义好的、固定的object categories,限制了它们在真实世界中的应用,应为需要额外的labeled data来泛化到新的visual concepts和domains。CLIP展示了,可以在大量的raw image-text pairs上,可以学习到有效的visual representations。因为paired texts包含比预先定义的concept pool更广的visual concepts,CLIP因此semantically rich,能够很容易地迁移到下游的image classification和text-image retrieval tasks in zero-shot settings。然而,为了得到fine-grained understanding of images,例如很多tasks要求的,例如object detection, segmentation, pose estimation等,object-level visual representations是希望得到的. 在本文中,作者展示了phrase grounding,是一个识别phrases in a sentence和objects(regions) in an image之间的fine-grained 对应关系的任务,是一个有效的、可扩展的预训练任务,能够学习object-level, language-aware, semantic-rich的visual representation,提出了Grounded Language-Image Pre-training(GLIP)。作者的方法统一了phrase grounding和object detection tasks,这里,object detection可以被描述为一个context-free phrase grounding,同时phrase grounding可以被视为一个contextualized object detection task

    • 通过将object detection reformulate为一个phrase grouding,统一detection和grounding,这个reformulation改变了detection model的输入:它的输入不仅是一个image,还有一个text prompt,描述了detection task中的所有candidate categories。例如,COCO object detection的text prompt是一个包含80 phrases的text string,任何一个object detection model可以通过将box classifier中的object classification logits替换成world-region alignment scores,被转换成一个grounding model。language features是通过language model来计算,new detection model是一个dual-encoer 结构,不同于CLIP,其仅在最后的dot product layer上融合vision和language,作者展示了GLIP用的deep cross-modality fusion,对于学习high-quality language-aware visual representation是重要的。detection和grounding的统一,使得能够用两种类型的data来进行pretrain,对两种任务都有好处。在detection上,visual concepts由于grounding data极大地丰富了。在grounding上,detection data引入了更多的bbox annotation,帮助训练一个新的SOTA phrase grounding model.

    • Scaling up visual concepts with massive image-text data:给定一个grounding model,可以通过产生grounding boxes,增强GLIP pretraining data。在这样semantic-rich data上训练,得到一个semantic-rich student model,相比之下,先前的在scaling detection data上的工作愈能预测teacher model预定义的vocabulary之外的concepts。这个研究中,作者展示了这个简单的扩充grounding data的策略,是有效的,在很多任务上都带来了提升。

    • Transfer Learning with GLIP: One model for all:grounding reformulation和semantic-rich pretraining促进了domain transfer,GLIP能够transfer到多个其它的任务上,需要很少的human annotations。另外,当task-specific annotations是available的时候,不同于tuning整个model,只需要tuning task-specific prompt embedding,同时保持model parameters 不变。在这样的prompt tunning setting下,一个GLIP model可以同时在所有的下游任务上表现很好,降低了fine-tuning和deployment的成本。

  2. 标准的object detection是在crowd-labeled datasets上被训练,用来定位预定义的、固定set的object classes,这样的human-annotated data扩展起来成本很高。GLIP通过将object detection reformulate为一个phrase grounding问题,提出了一个affordable solution,这利用了grounding和massive image-text-paired data,尽管当前的implementation是建立在Dynamic Head上的,作者的统一的formulation可以被泛化到任何的object detection systems。 最近,也有针对visual recognition问题的vision-and-language 方法,vision models用free-form language supervision进行训练,例如CLIP和ALIGN在大量的image-text pairs上进行cross-modal的contrastive learning,直接进行open-vocabulary image classification。通过将CLIP/ALIGN model蒸馏到一个two-stage detector, ViLD被提出来了,提高了zero-shot object detection,另外,MDETR在现有的multi-modal datasets训练了一个端到端的model,在phrases in text和objects in image之间有显式的对齐。作者的GLIP继承了这个研究方向的semantic-rich和language-aware的特点,实现了SOTA,提高了迁移到下游任务的能力。

    这个paper聚焦于domain transfer,用于object detection,目标是构建一个pretrained model,能够无缝地迁移到多个tasks和domains in a zero-shto or few-shot manner。作者的setting不同于zero-shot detection,作者期望GLIP在rare categories上表现良好,但是没有显式地exclude any categories from training set,因为grounding data是semantic rich,期望它们能够cover 很多rare categories,这像一个setting in open-vocabulary object detection,期望raw image-text data来cover rare categories。这个方向的工作将构建一个open-world object proposal module,能够propose novel object at test time作为key challenge。GLIP提供了一个新的perspective:model不需要提出possible novel objects from an open set,只需要propose objects mentioned in the text prompt,detectio branch is conditioned on the prompt.

    除了在rare categories上的性能之外,作者也考虑了在真实世界中的transfer cost,如何用少量的data、training budget和depolyment cost实现最好的性能。特别地,作者也展示了GLIP支持prompt tuning,和full fine-tuning的性能相匹配,但是只tunes一部分的model parameters。作者也展示了一个novel finding: 在object detection中,prompt tuning是对于有deep vision-language fusion的model是最有效的,同时对于shallow-fused models是没有那么有效。这个和最近的、仅对shallow-fused vision-language models进行prompt tuning的工作形成了对比。

  3. Grounded Language Image Pre-training: 概念上,object detection和phrase grounding有很大的相似之处。都是来localized objects,然后将它们和semantic concepts对齐。这个协同作用motivates作者,将经典的object detection tasks变成一个grounding 问题,提出了一个unified formulation,作者进一步提出来在image和text之间增加deep fusion,使得dtection model language-aware,变成一个strong grounding model,有了这个reformulation和deep fusion,可以在scalable 和semantic-rich的grounding data上pretrain CLIP。

  4. Unified Formulation:一个典型的detection model将一个input image给到visual encoder \(Enc_I\),用CNN或者Transformer作为一个backbone,提取region/box features \(O\),每个 region/box features然后给到两个prediction heads, box classifier 和box regressor,分别用cls loss和localization loss进行训练。 在两阶段的detector中,一个单独的region proposal network with RPN loss用来区分foreground和background和refine anchors,因为 \(L_{rpn}\) 没有用semantic information of object classes,将它们merge到 localization loss \(L_{loc}\) 中,在one-stage detector中,localization loss \(L_{loc}\) 也可能包含centerness loss。

    • Object detection as phrase grounding:不同于将每个region/box分为 \(c\) classes,作者将detection reformulate为一个grounding task,通过将每个region grounding/aligning到 text prompt中的 \(c\) phrases,如何设计一个text prompt for a detection task? 给定一个object classes:[person, bicycle, car, ..., toothbrush],一个简单的方式是: Prompt = "Detect: person, bicycle, car, ..., toothbrush" 每个cls name是作为要被grounded的candidate phrase。通过提供更扶风的descriptions或这利用pretrained language model的preference,可以设计更好的prompts。例如:预训练的BERT model用来初始化language encoder \(Enc_L\), prompt "person, bicycle, car" 比human-friendly prompt 表现更好。

    在一个grounding model中,计算image region和prompt words厚葬的alignment scores \(S_{ground}\):

    \(O = \text{Enc}_I(\text{Img}), \quad P = \text{Enc}_L(\text{Prompt}), \quad S_{\text{ground}} = OP^\top,\)

    \(P\) 是来自language encoder的contextual word/token features,和weight matrix \(W\) 是类似的作用。这个grounding model,包含image encoder \(Enc_I\) 和language encoder \(Enc_L\),通过最小化loss,来进行端到端的训练用region-word alignment scores \(S_{\text{ground}}\) 来替换cls logits \(S_{cls}\)

    然而,现在又logits \(S_{ground}\) h和target \(T\),(sub)-word tokens \(M\)的数量通常比 text prompt中的phrases \(c\)的数量大,是由于以下四个原因:1. 一些phrases包含多个words; 2. 一些single word phrases分成多个sub-words tokens,例如 toothbrush; 3. 一些是增加的tokens,例如Detect; 4. [NoObj]加在了tokenized sequence的末尾。当loss是一个binary sigmoid loss,作者将原始的target matrix \(T\) 扩为 \(T`\),通过使所有的sub-words positive match,如果一个phrase使positive match,所有的added tokens和所有的image features是negative match。有了这个chagne, \(loss(S_{ground};T')\) 保持相同。在推理的时候,将所有的token的概率进行平均,作为phrase probability。

    • Equivalence between detection and grounding: 有了以上的reformulation,将任何detection model转换为一个grounding model和two views,detection和grounding,对于training和inference是理论上equivalent的。有了这个reformulation,一个pretrained phrase grounding model可以直接用在任何object detection task上,由于language encoder的输入的free-form,使得将GLIP model有可能以zero-shot的方式,迁移到任意的detection tasks上。
    • Related work: grounding formulation是受MDETR的启发,作者的grounding loss和MDETR的fine-grained contrastive loss有相同的思路。作者找到了一个有效的方式,将detection reformulate为一个grounding和简单的unified loss 用于detection和grounding tasks,作者的grounding model类似于zero-shot detection。Bansal的工作是一个detection model用pretrained Glove word embedding,进行zero-shot detection。最近,从pretrained deep language models提出来的phrase features引入到了open-vocabulary detection中,GLIP不同于zero-shot detection的地方在于,GLIP提供了一个unified view of detection and grounding,使得两个重要的因素, language-aware deep fusion和scaling up with image-text data.
  5. Language-Aware Deep Fusion:image和text通过不同的encoders进行encode,只在最后进行fuse,来得到alignment scores,作者称这样的models为late-fusion models,在vision-language literature中, visual和language feautres的deep fusion是必要的,来学习一个performant phrase grounding model,作者在image和language encoders之间引入了deep fusion,在最后的几个encoding layer中如何image和text information,具体来说,用了DyHead作为image encoder, BERT作为text encoder,deep-fused encoder如下:

    \[O_{2i}^j, P_{i2}^i = \text{X-MHA}(O^i, P^i), \quad i \in \{0, 1, \dots, L-1\}\]

    \(L\) 是DyHeadModules 的数量,BERTLayer是在pretrained BERT的新加的BERT layers,cross-modality是通过cross-modality multi-head attention module来实现的。不需要context vectors,model变为了\(late-fusion\) model。在cross-modality multi-head attention module中,每个head计算one modality的context vectors,通过attending to the other modality: \[\begin{aligned} O^{(q)} &= O W^{(q, I)}, \quad P^{(q)} = P W^{(q, L)}, \quad \text{Attn} = O^{(q)} (P^{(q)})^\top / \sqrt{d}, \\ P^{(v)} &= P W^{(v, L)}, \quad O_{t2i} = \text{SoftMax}(Attn) P^{(v)} W^{(out, I)}, \\ O^{(v)} &= O W^{(v, I)}, \quad P_{i2t} = \text{SoftMax}(Attn^\top) O^{(v)} W^{(out, L)}, \end{aligned}\]

    \(W^{symbol,I/L}: symbol \in {q,v,out}\) 是可训练的parameters,和MHA中的query、value和output linear layers的作用类似。

    deep-fused encoder有两个好处:1. 提高了phrase grounding performance; 2. 使得学习到的visual features language-aware,因此,models的prediction是以text prompt为条件的,这对于实现一个model服务所有的下游detection tasks至关重要

  6. Pre-training with Scalable Semantic-Rich Data: 大量的工作用来搜集语义丰富的数据,然而,human annotations是成本高和有限的,先前的工作以self-training的方式进行scale up,它们用一个teacher从raw images中预测boxes,来产生pseudo detection labels,来训练一个student model,大那是generated data仍然受限于concept pool的大小,因为teacher只能预测concept pool中定义的labels,相比之下,作者的model可以在detection和grounding data上进行训练。作者展示了grounding data可以提供丰富的semantics,促进localication,可以以self-training的方式进行scale up. grounding data比现有的deteciton data有更多的visual concepts。作者用gold detection和grounding data来预训练一个teacher GLIP,然后用这个teacher model来预测web-collected image-text data,用NLP parser检测到的noun phrases,最后,一个student model用gold data和产生的pseudo grounding data来训练一个student model,一个teacher能够产生accurate box for semantically rich entities为什么student model能够超越teacher model,在visual grounding中,作者假设teacher model利用language context和language generalization能力精确地ground concepts。当训练student model的时候,teacher model的 educated guess变成了一个supervised signal,使得student model能够学习一定的概念

Framework \(Fig.1^{[1]}\) GLIP联合训练一个image encoder和一个language encoder,来与regions和words的正确的pairings,进一步增加了cross-modality deep fusion,来融合两个模态的information,来学习language-aware visual representation