Grounding DINO t

Click a block to read its description, or select it with Tab and Enter.

Grounding DINO tOpen-vocabulary detection, 800 × 800 square image, 16 text tokens, 900 object queries. Tensor sizes exclude batch.LibreYOLOGrounding DINO tOpen-vocabulary detection, 800 × 800 square image, 16 text tokens, 900 object queries. Tensor sizes exclude batch.Image backbone and feature projectionImage3 × 800 × 800Swin patch embedding4×4 /4 Conv, channel LayerNormSwin stage 1200 × 200 × 96, n=2Swin stage 2100 × 100 × 192, n=2Swin stage 350 × 50 × 384, n=6Swin stage 425 × 25 × 768, n=2Three 1×1 projections + GroupNorm192/384/768 to 256; groups=32Fourth level from raw stage 4Conv3×3 /2, 768 to256; GroupNorm32Flatten and concat image levels13,294 × 256Sine position + learned level embedding13,294 × 256Feature sizes: 100×100, 50×50, 25×25, 13×13.BERT text backboneInput IDs + token types + phrase position IDs16 tokens; vocabulary 30,522Sum word, position and token-type embeddings16 × 768LayerNorm16 × 768BERT encoder blocks, repeats=12768 width, 12 heads, MLP 3,072Linear text projection768 to 256Native phrase-mask values are added as 0/1 biasinside this BERT path, preserving library behavior.Padding and token masks are carried separately.Multimodal encoder and decoderImage and projected text states13,294 × 256 and 16 × 256Encoder layer, repeats=6Bidirectional fusion; parallel text enhancement and deformable vision layerLinear + LayerNorm proposal features13,294 × 256Contrastive token scoring13,294 × 16, padded to256 token slotsTop 900 by max valid-token score900 proposal indicesProposal box MLP + grid box logits13,294 × 4Gather selected boxes, sigmoid900 × 4 initial reference boxesLearned query content900 × 256Decoder layer, repeats=6Query self-attention, text cross-attention, deformable image attention, MLPFinal-layer contrastive logits and refined boxes900 × 256 token logits; 900 × 4 normalized cxcywhBox deltas refine inverse-sigmoid references at every decoder layer.Postprocess applies sigmoid, threshold and phrase-to-class alignment.No NMS in the learned detector.Bidirectional vision-text fusionLayerNorm vision13,294 × 256LayerNorm text16 × 256Linear vision values VV256 to 1,024VV: 4 × 13,294 × 256Linear text values TV256 to 1,024TV: 4 × 16 × 256Linear vision Q256 to 1,024; 4 heads × 256; scale 1/16Linear text K256 to 1,024; 4 heads × 256MatMul vision Q × text K-transpose4 × 13,294 × 16Subtract max and clampClamp [-50,000,50,000]Mask text padding, softmax over text4 × 13,294 × 16Transpose, stabilize, mask vision, softmax4 × 16 × 13,294MatMul vision probabilities × TVTV is the text-value projection shown aboveMatMul text probabilities × VVVV is the vision-value projection shown aboveLinear output1,024 to 256Multiply learned channel scale256 weights, initialized 1e-4+Residual starts at the normalized vision input.Linear output1,024 to 256Multiply learned channel scale256 weights, initialized 1e-4+Residual starts at the normalized text input.Text enhancerInput 16 × 256Self-attention4 heads, 256 channels+LayerNorm16 × 256Linear256 to 1024ReLU16 × 1024Linear1024 to 256+LayerNorm16 × 256Deformable vision layerInput 13294 × 256Multi-scale deformable attention8 heads, 256 channels+LayerNorm13294 × 256Linear256 to 2048ReLU13294 × 2048Linear2048 to 256+LayerNorm13294 × 256Decoder layerQuery self-attentionQ/K/V=900+LayerNorm900 × 256Text cross-attentionQ=900, K/V=16+LayerNorm900 × 256Deformable image attentionQ=900, four image levels+LayerNorm900 × 256Linear256 to 2,048ReLU900 × 2,048Linear2,048 to 256+LayerNorm900 × 256Query self-attentionQuery input900 × 256Key/value input900 × 256Linear Q256 to 256Reshape heads8 × 900 × 32Linear K256 to 256Reshape heads8 × 900 × 32Linear V256 to 256Reshape heads8 × 900 × 32MatMul Q K-transpose8 × 900 × 900ScaleDivide by sqrt(32)Softmax over keys8 × 900 × 900MatMul attention × V8 × 900 × 32Merge heads900 × 256Linear output256 to 256Query-to-text attentionQuery input900 × 256Key/value input16 × 256Linear Q256 to 256Reshape heads8 × 900 × 32Linear K256 to 256Reshape heads8 × 16 × 32Linear V256 to 256Reshape heads8 × 16 × 32MatMul Q K-transpose8 × 900 × 16ScaleDivide by sqrt(32)Softmax over keys8 × 900 × 16MatMul attention × V8 × 900 × 32Merge heads900 × 256Linear output256 to 256Reference / box MLPsNormalized query state900 × 256Linear256 to256ReLU256Linear256 to256ReLU256Linear256 to4Add inverse-sigmoid reference900 ×4Sigmoid refined box900 ×4Proposal MLP uses the same 256/256/4 dimensions.Position MLP: sine-encoded box512,Linear512 to256, ReLU, Linear256 to256.Multi-scale deformable attentionQuery + positional embeddingEncoder 13,294 / decoder 900 queries × 256Value features13,294 × 256 from four image levelsReference coordinatesEncoder: normalized XY; decoder: normalized XYWHLinear sampling offsets256 to 256; 8 heads × 4 levels × 4 points × 2Linear attention weights256 to 128Softmax levels and points8 heads × 16 probabilities per queryLinear value projection256 to 256; reshape 13,294 × 8 × 32Compute sampling positionsXY reference + normalized offsets; decoder offsets scaled by box WHSplit values by four levels100×100, 50×50, 25×25 and 13×13, each 256 channelsBilinear grid_sample100 × 100 map; 4 samples per query/headValues: level 1; coordinates: level 1Multiply sample values × attention weights4 × 32 values per query/headWeights: level 1, four of the 16 probabilitiesBilinear grid_sample50 × 50 map; 4 samples per query/headValues: level 2; coordinates: level 2Multiply sample values × attention weights4 × 32 values per query/headWeights: level 2, four of the 16 probabilitiesBilinear grid_sample25 × 25 map; 4 samples per query/headValues: level 3; coordinates: level 3Multiply sample values × attention weights4 × 32 values per query/headWeights: level 3, four of the 16 probabilitiesBilinear grid_sample13 × 13 map; 4 samples per query/headValues: level 4; coordinates: level 4Multiply sample values × attention weights4 × 32 values per query/headWeights: level 4, four of the 16 probabilitiesSum all four levels and four sample points8 heads × 32 channels; merge to 256Linear output projection256 to 256BERT encoder blockInput 16 × 768Self-attention12 heads, 768 channels+LayerNorm16 × 768Linear768 to 3072GELU16 × 3072Linear3072 to 768+LayerNorm16 × 768BERT self-attentionQuery input16 × 768Key/value input16 × 768Linear Q768 to 768Reshape heads12 × 16 × 64Linear K768 to 768Reshape heads12 × 16 × 64Linear V768 to 768Reshape heads12 × 16 × 64MatMul Q K-transpose12 × 16 × 16ScaleDivide by sqrt(64)Phrase-mask bias12 × 16 × 16+Softmax over keys12 × 16 × 16MatMul attention × V12 × 16 × 64Merge heads16 × 768Linear output768 to 768Swin block and patch mergingLayerNormStage channels 96/192/384/768Pad to window multipleWindow 7; padding precedes shiftCyclic shift on even blocksShift -3 in H and WWindow self-attention49 tokens; heads 3/6/12/24Reverse window partitionRestore padded spatial gridReverse cyclic shiftShift +3 in H and WCrop paddingRestore stage H × W+LayerNormStage channels 96/192/384/768LinearOutputs 384/768/1536/3072GELUMLP channels 384/768/1536/3072LinearOutputs 96/192/384/768+Input for next Swin stage2×2 neighboring patchesReshape and concatenate neighborhoodFour times current channel widthLayerNormConcatenated neighborhood channelsLinear reduction (no bias)Neighborhood channels to next stage widthResolved merge widths:96 input; 384 concatenated; 192 output192 input; 768 concatenated; 384 output384 input; 1536 concatenated; 768 outputOutput grids: 100×100, 50×50, 25×25.Swin window self-attentionQuery input49 × 96/192/384/768Key/value input49 × 96/192/384/768Linear Q96/192/384/768 to 96/192/384/768Reshape heads3/6/12/24 × 49 × 32Linear K96/192/384/768 to 96/192/384/768Reshape heads3/6/12/24 × 49 × 32Linear V96/192/384/768 to 96/192/384/768Reshape heads3/6/12/24 × 49 × 32MatMul Q K-transpose3/6/12/24 × 49 × 49ScaleDivide by sqrt(32)Position bias3/6/12/24 × 49 × 49+Softmax over keys3/6/12/24 × 49 × 49MatMul attention × V3/6/12/24 × 49 × 32Merge heads49 × 96/192/384/768Linear output96/192/384/768 to 96/192/384/768Text-enhancer self-attentionQuery input16 × 256Key/value input16 × 256Linear Q256 to 256Reshape heads4 × 16 × 64Linear K256 to 256Reshape heads4 × 16 × 64Linear V256 to 256Reshape heads4 × 16 × 64MatMul Q K-transpose4 × 16 × 16ScaleDivide by sqrt(64)Position bias4 × 16 × 16+Softmax over keys4 × 16 × 16MatMul attention × V4 × 16 × 64Merge heads16 × 256Linear output256 to 256Variant valuestSwin channels: 96, 192, 384, 768Stage repeats: 2, 2, 6, 2; window 7Heads: 3, 6, 12, 24bSwin channels: 128, 256, 512, 1024Stage repeats: 2, 2, 18, 2; window 12Heads: 4, 8, 16, 32Both sizes: 256 model width, 6 encoder layers, 6 decoder layers, 900 queries.Deformable attention: 8 heads, 4 levels, 4 points per level.Vision/text fusion: 1,024 internal width, 4 heads; text enhancer: 4 heads, MLP1,024.Backbone input here is square 800px. Other aspect ratios change spatial token counts.Source: libreyolo/models/grounding_dino/nn.py. Revision a4d0ecc9e17f.libreyolo.com