# amaralibey/bag-of-queries architecture

> Architecture diagram of the GitHub repository amaralibey/bag-of-queries, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amaralibey/bag-of-queries
- Repository: https://github.com/amaralibey/bag-of-queries

## Overview

##### Main Components

a) Input Processing Layer:
- Image input (320x320 or specified dimensions)
- Input transformation pipeline (normalization, resizing)

b) Backbone Networks:
- Support for multiple backbones (ResNet50, DinoV2)
- Local feature extraction component

c) BoQ Architecture:
- Multiple BoQ blocks in cascade
- Learnable queries component
- Cross-attention mechanisms
- Feature refinement paths

d) Output Processing:
- Feature concatenation
- Linear projection
- L2 normalization
- Final descriptor generation

**[Input Layer]**
- ↓
**[Backbone Network]**
- ↓
**[BoQ Blocks Layer]**
- ↓
**[Output Processing]**

##### Detailed Component Breakdown

a) Input Processing:
**[Raw Image] → [Resize] → [Normalize] → [Tensor Transform]**

b) Backbone Section:
**[Backbone Network (ResNet50/DinoV2)] → [Local Features]**

c) BoQ Block Section (repeat for each block):
**[Input Features] → [Feature Refinement] → [Cross-Attention]**
- ↑
- [Learnable Queries Bank]

d) Output Section:
**[Concatenate Outputs] → [Linear Projection] → [L2 Normalization]**

##### Implementation Details to Highlight

- Dimension transformations (e.g., 1024 → 512 channels)
- Number of queries (e.g., 32 queries)
- Number of attention heads (e.g., 8 heads)
- Final output dimension (16384 or 12288)

##### Technical Details

- Transformer encoder layers
- Self-attention mechanisms
- Normalization layers (LayerNorm)
- Feature projection paths

##### Integration Points

- How the model integrates with PyTorch Hub
- Data loading interfaces
- Evaluation endpoints

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        IMG[Image Input]
        RESIZE[Resize 320x320]
        NORM[Normalize]
        TENSOR[Tensor Transform]
        
        IMG --> RESIZE --> NORM --> TENSOR
    end
    
    subgraph Backbone
        BB[Backbone Network]:::backbone
        LF[Local Features]
        
        TENSOR --> BB --> LF
    end
    
    subgraph "BoQ Architecture"
        BQ[BoQ Blocks]:::boq
        
        subgraph "BoQ Block 1"
            FR1[Feature Refinement]
            LQ1[Learnable Queries]
            CA1[Cross-Attention]
            
            FR1 --> CA1
            LQ1 --> CA1
        end
        
        subgraph "BoQ Block 2"
            FR2[Feature Refinement]
            LQ2[Learnable Queries]
            CA2[Cross-Attention]
            
            FR2 --> CA2
            LQ2 --> CA2
        end
        
        LF --> FR1
        CA1 --> FR2
    end
    
    subgraph Output
        CONCAT[Concatenate Features]
        PROJ[Linear Projection]
        NORM2[L2 Normalization]
        DESC[Final Descriptor]
        
        CA2 --> CONCAT
        CONCAT --> PROJ
        PROJ --> NORM2
        NORM2 --> DESC
    end
    
    subgraph Integration
        HUB[PyTorch Hub]:::hub
        TRAIN[Training Pipeline]:::train
        EVAL[Evaluation]
        
        DESC --> HUB
        DESC --> TRAIN
        DESC --> EVAL
    end
    
    subgraph Datasets
        PITT[Pittsburgh Dataset]:::dataset
        MAP[Mapillary Dataset]:::dataset
        GSV[GSV Cities Dataset]:::dataset
    end
    
    PITT & MAP & GSV --> TRAIN
    
    %% Click events
    click BB "https://github.com/amaralibey/bag-of-queries/blob/main/src/backbones.py"
    click BQ "https://github.com/amaralibey/bag-of-queries/blob/main/src/boq.py"
    click DESC "https://github.com/amaralibey/bag-of-queries/blob/main/src/model.py"
    click IMG "https://github.com/amaralibey/bag-of-queries/blob/main/src/dataloaders/datamodule.py"
    click PITT "https://github.com/amaralibey/bag-of-queries/blob/main/src/dataloaders/pittsburgh.py"
    click MAP "https://github.com/amaralibey/bag-of-queries/blob/main/src/dataloaders/mapillary_sls.py"
    click GSV "https://github.com/amaralibey/bag-of-queries/blob/main/src/dataloaders/gsv_cities.py"
    click HUB "https://github.com/amaralibey/bag-of-queries/blob/main/hubconf.py"
    click TRAIN "https://github.com/amaralibey/bag-of-queries/blob/main/train.py"
    
    %% Styling
    classDef backbone fill:#90EE90
    classDef boq fill:#FFA500
    classDef dataset fill:#ADD8E6
    classDef hub fill:#DDA0DD
    classDef train fill:#FFB6C1
    
    %% Legend
    subgraph Legend
        L1[Backbone Network]:::backbone
        L2[BoQ Component]:::boq
        L3[Dataset]:::dataset
        L4[Hub Integration]:::hub
        L5[Training]:::train
    end
```
