Architecture chapter

Siamese model architecture

Shared encoder path, embedding projection, comparison logic, and output scoring.

Module boundary

`model.py` owns the whole similarity function

The repository keeps all model definition logic inside `model.py`. The `Siamese` class exposes `forward_one` for single-branch feature extraction and `forward` for pairwise scoring.

Encoder path

Shared convolution tower

Convolution blocks

The encoder applies four convolution stages with intermittent max pooling. This progressively reduces spatial resolution while expanding channel depth.

Weight sharing

Both input images pass through the same `self.conv` and `self.liner` modules, ensuring that similarity is measured in a common embedding space.

Control flow

From `forward_one` to final logit

1. `forward_one`

Each branch image is encoded by the convolution stack, flattened, and projected into a 4096-dimensional embedding with sigmoid activation.

2. Absolute difference

`forward` computes `torch.abs(out1 - out2)`, which is the central similarity comparison primitive in this implementation.

3. Output layer

The difference vector is passed to `self.out`, producing a single logit for binary same-class vs different-class classification.

Current limitations

Implementation tradeoffs in this repo

Single-file ownership

The architecture is compact and easy to read, but the file does not separate encoder, projection, and scoring into independently testable modules.

Minimal output head

The model returns logits directly and leaves probability calibration to the loss function and downstream evaluation code.