# tinyaway/manet architecture

> Architecture diagram of the GitHub repository tinyaway/manet, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tinyaway/manet
- Repository: https://github.com/tinyaway/manet

## Overview

This is a PyTorch few-shot semantic-segmentation implementation of MANet, with an additional Hypercorrelation Squeeze Network (HSNet) implementation. The main workflow samples query/support episodes from Pascal or COCO, runs MANet, computes segmentation loss and intersection-over-union metrics, then updates and logs training results. The model uses a ResNet backbone and combines query/support features into mask and category predictions. HSNet’s correlation-based architecture is represented as a separate capability; the shown training loop imports it but does not instantiate it. Some dataset and model internals are only partially excerpted.

Main entry points: [`train.py`](https://github.com/tinyaway/manet/blob/main/train.py) (Train / validate loop), [`model.py`](https://github.com/tinyaway/manet/blob/main/model.py) (MANet), [`dataset.py`](https://github.com/tinyaway/manet/blob/main/dataset.py) (Episode datasets), [`evaluation.py`](https://github.com/tinyaway/manet/blob/main/evaluation.py) (IoU evaluation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Episode data"]
  node_episode_data["Episode datasets<br/>[dataset.py]"]
  node_episode_loader["Episode loader<br/>[dataset.py]"]
end

subgraph group_models["Segmentation models"]
  node_manet["MANet<br/>[model.py]"]
  node_backbone["ResNet backbone<br/>[resnet.py]"]
  node_manet_heads["Mask and category heads<br/>[model.py]"]
  node_hsnet["Hypercorr network<br/>[HSNet.py]"]
  node_loss["Segmentation objective<br/>[model.py]"]
end

subgraph group_training["Training and evaluation"]
  node_train_loop["Train / validate loop<br/>[train.py]"]
  node_metrics["IoU evaluation<br/>[evaluation.py]"]
  node_optimizer["Adam optimizer<br/>[train.py]"]
end

subgraph group_support["Runtime support"]
  node_metric_aggregation["Metric aggregation<br/>[logger.py]"]
  node_run_utils["Seed and device helpers<br/>[utils.py]"]
  node_run_logger["Run logging and checkpoints<br/>[logger.py]"]
end

node_user(("Experiment operator"))
node_images[("Pascal / COCO data")]

node_user -->|"starts run"| node_train_loop
node_train_loop -->|"initializes datasets"| node_episode_data
node_episode_data -->|"reads images and masks"| node_images
node_train_loop -->|"builds loaders"| node_episode_loader
node_episode_loader -->|"batches episodes"| node_episode_data
node_train_loop -->|"predicts masks"| node_manet
node_manet -->|"constructs backbone"| node_backbone
node_manet -->|"computes predictions"| node_manet_heads
node_train_loop -->|"computes loss"| node_loss
node_train_loop -->|"updates parameters"| node_optimizer
node_train_loop -->|"scores predictions"| node_metrics
node_metrics -->|"updates IoU totals"| node_metric_aggregation
node_train_loop -->|"sets seeds and device"| node_run_utils
node_train_loop -->|"logs and saves model"| node_run_logger

click node_episode_data "https://github.com/tinyaway/manet/blob/main/dataset.py"
click node_episode_loader "https://github.com/tinyaway/manet/blob/main/dataset.py"
click node_manet "https://github.com/tinyaway/manet/blob/main/model.py"
click node_backbone "https://github.com/tinyaway/manet/blob/main/resnet.py"
click node_manet_heads "https://github.com/tinyaway/manet/blob/main/model.py"
click node_hsnet "https://github.com/tinyaway/manet/blob/main/HSNet.py"
click node_train_loop "https://github.com/tinyaway/manet/blob/main/train.py"
click node_loss "https://github.com/tinyaway/manet/blob/main/model.py"
click node_metrics "https://github.com/tinyaway/manet/blob/main/evaluation.py"
click node_metric_aggregation "https://github.com/tinyaway/manet/blob/main/logger.py"
click node_run_utils "https://github.com/tinyaway/manet/blob/main/utils.py"
click node_run_logger "https://github.com/tinyaway/manet/blob/main/logger.py"
click node_optimizer "https://github.com/tinyaway/manet/blob/main/train.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_episode_data,node_episode_loader toneBlue
class node_manet,node_backbone,node_manet_heads,node_hsnet,node_loss,node_images toneAmber
class node_train_loop,node_metrics,node_optimizer toneMint
class node_metric_aggregation,node_run_utils,node_run_logger toneRose
class node_user toneIndigo
```

## Components

### Episode data

- [Episode datasets](https://github.com/tinyaway/manet/blob/main/dataset.py): `dataset.py`
- [Episode loader](https://github.com/tinyaway/manet/blob/main/dataset.py): `dataset.py`

### Segmentation models

- [MANet](https://github.com/tinyaway/manet/blob/main/model.py): `model.py`
- [ResNet backbone](https://github.com/tinyaway/manet/blob/main/resnet.py): `resnet.py`
- [Mask and category heads](https://github.com/tinyaway/manet/blob/main/model.py): `model.py`
- [Hypercorr network](https://github.com/tinyaway/manet/blob/main/HSNet.py): `HSNet.py`
- [Segmentation objective](https://github.com/tinyaway/manet/blob/main/model.py): `model.py`

### Training and evaluation

- [Train / validate loop](https://github.com/tinyaway/manet/blob/main/train.py): `train.py`
- [IoU evaluation](https://github.com/tinyaway/manet/blob/main/evaluation.py): `evaluation.py`
- [Adam optimizer](https://github.com/tinyaway/manet/blob/main/train.py): `train.py`

### Runtime support

- [Metric aggregation](https://github.com/tinyaway/manet/blob/main/logger.py): `logger.py`
- [Seed and device helpers](https://github.com/tinyaway/manet/blob/main/utils.py): `utils.py`
- [Run logging and checkpoints](https://github.com/tinyaway/manet/blob/main/logger.py): `logger.py`

### Other components

- **Experiment operator**
- **Pascal / COCO data**

## Connections

- Experiment operator → Train / validate loop: starts run (evidence: `train.py`)
- Train / validate loop → Episode datasets: initializes datasets (evidence: `train.py`)
- Episode datasets → Pascal / COCO data: reads images and masks (evidence: `dataset.py`)
- Train / validate loop → Episode loader: builds loaders (evidence: `train.py`)
- Episode loader → Episode datasets: batches episodes (evidence: `dataset.py`)
- Train / validate loop → MANet: predicts masks (evidence: `train.py`)
- MANet → ResNet backbone: constructs backbone (evidence: `model.py`)
- MANet → Mask and category heads: computes predictions (evidence: `model.py`)
- Train / validate loop → Segmentation objective: computes loss (evidence: `train.py`)
- Train / validate loop → Adam optimizer: updates parameters (evidence: `train.py`)
- Train / validate loop → IoU evaluation: scores predictions (evidence: `train.py`)
- IoU evaluation → Metric aggregation: updates IoU totals (evidence: `train.py`)
- Train / validate loop → Seed and device helpers: sets seeds and device (evidence: `train.py`)
- Train / validate loop → Run logging and checkpoints: logs and saves model (evidence: `train.py`)
