paligemma2-detection

Paligemma-2 Closed-Set Object Detection

As discussed earlier, Paligemma-2 models can be naturally used as open class detectors. In this part we discuss an approach that allows to fine-tune Paligemma-2 models in the closed-set detection style.

Making a closed-set detector out of Paligemma-2

Natural language typically comprises an extremely large and complex set of dependencies. In order to adequately embrace this complexity language models typically consist of a huge amount of parameters.

Imposing a certain structure on the model’s input and output often allows us to efficiently leverage its pattern recognition capabilities in a partially known domain. Our approach is inspired by transfer learning examples from the Paligemma-2 paper and by Pix2seq framework.

It consists of two major steps:

<unusedXX> tokens

Adding new tokens to a pre-trained language model can be problematic. It is highly likely that such a surgery would break its inherent structures, dependencies not to mention performance degradation.

The authors of the PaliGemma-2 model family included a set of “unused tokens” within the model’s architecture, which are reserved and integrated into the model structure, even though they have not been assigned any specific semantic meaning.

These tokens are numbered from 7 to 105 inclusive and take the form <unused0>, <unused1>, <unused2>…<unused98>.

In this work, we use 81 of them: tokens numbered 7 through 87 (corresponding to <unused0> through <unused80>). The first 80 are used to represent the 80 COCO classes, while the last one (<unused80>) represents the so-called “noise token”.

Model Input and Output Structure

The structure of the model’s input and output is as follows:

This structure uses a limited number of tokens and eliminates the diversity of natural language, simplifies dependencies and allows for fine-tuning of the model for detecting a fixed set of classes.

During Training

Input: <image>detect all classes\n

(Tokenized) Output: <locAAAA_1><locBBBB_1><locCCCC_1><locDDDD_1><unusedXX_1><locAAAA_2><locBBBB_2><locCCCC_2><locDDDD_2><unusedXX_2>...<locAAAA_51><locBBBB_51><locCCCC_51><locDDDD_51><unusedXX_51><eos>

During Inference

Training

The model paligemma2-10b-pt-448 is fine-tuned with a LoRA adapter and an effective batch size of 32. Training employs the AdamW optimizer along with a cosine learning rate scheduler, with the learning rate ranging from 1e-6 to 1e-5.

The data pipeline is implemented with Ray Data, while distributed training uses Ray Train, which internally leverages the Accelerate library.

learning curve

validation

Results

COCO benchmark

The fine-tuned paligemma2-10b-pt-448 model achieves a COCO2017_val mAP@[IoU=0.50:0.95] of 0.296, which is an improvement of more than 7 percentage points over the open-set configuration value.

Score distribution

Score distribution

Detections number distribution

number of detections distribution

Detection size distribution

Detection size distribution