# postech-minjaelee/pr-magic architecture

> Architecture diagram of the GitHub repository postech-minjaelee/pr-magic, 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/postech-minjaelee/pr-magic
- Repository: https://github.com/postech-minjaelee/pr-magic

## Overview

PR-MaGIC is a training-free test-time prompt-refinement framework for in-context segmentation, integrating with PerSAM-F and Matcher. A user supplies support examples and query images; the selected baseline computes prompts and masks, PR-MaGIC iteratively refines the query embedding using mask-decoder gradient flow, then ranks candidate masks by support–query similarity. The graph also captures the DINOv2 and SAM components and the documented benchmark evaluation branch. Relationships follow README statements and the source index; unsampled implementation details are not inferred.

Main entry points: [`Matcher/pr_magic_for_matcher.py`](https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/pr_magic_for_matcher.py) (Matcher PR Runner), [`Matcher/matcher/Matcher_PR.py`](https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/matcher/Matcher_PR.py) (Prompt Refinement), [`Matcher/dinov2/models/vision_transformer.py`](https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/dinov2/models/vision_transformer.py) (DINOv2 Encoder), [`Personalize-SAM/pr_magic_for_persam.py`](https://github.com/postech-minjaelee/pr-magic/blob/main/Personalize-SAM/pr_magic_for_persam.py) (PerSAM-F PR Runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["PR-MaGIC Workflow"]
  node_matcher_runner["Matcher PR Runner"]
  node_persam_runner["PerSAM-F PR Runner"]
  node_refinement["Prompt Refinement<br/>[Matcher_PR.py]"]
  node_candidate_selection["Top-1 Selection<br/>[Matcher_PR.py]"]
end

subgraph group_matcher["Matcher Baseline"]
  node_matcher_core["Matcher Segmentation<br/>[Matcher.py]"]
  node_matcher_masks["Automatic Mask Generation"]
end

subgraph group_persam["PerSAM-F Baseline"]
  node_persam_core["Personalized SAM<br/>[sam.py]"]
  node_persam_predictor["SAM Predictor<br/>[predictor.py]"]
end

subgraph group_backbones["Model Components"]
  node_dino_encoder["DINOv2 Encoder"]
  node_dino_layers["Transformer Blocks<br/>[block.py]"]
  node_dino_data["Image Transforms<br/>[transforms.py]"]
  node_ssl_training["Self-Supervised Training<br/>[ssl_meta_arch.py]"]
  node_ssl_losses["DINOv2 Losses<br/>[ibot_patch_loss.py]"]
end

subgraph group_evaluation["Data and Evaluation"]
  node_benchmark_data[("Benchmark Datasets<br/>[dataset.py]")]
  node_benchmark_eval["Segmentation Evaluation<br/>[evaluation.py]"]
  node_persam_benchmarks[("PerSAM Datasets<br/>[dataset.py]")]
  node_video_data[("DAVIS Video Data<br/>[davis.py]")]
  node_video_eval["Video Evaluation<br/>[evaluation.py]"]
end

node_user(("Researcher"))

node_user -->|"runs"| node_matcher_runner
node_user -->|"runs"| node_persam_runner
node_matcher_runner -->|"uses baseline"| node_matcher_core
node_matcher_runner -->|"loads benchmarks"| node_benchmark_data
node_matcher_runner -->|"evaluates masks"| node_benchmark_eval
node_matcher_runner -->|"runs refinement"| node_refinement
node_persam_runner -->|"uses baseline"| node_persam_core
node_persam_runner -->|"loads benchmarks"| node_persam_benchmarks
node_matcher_core -->|"integrates with"| node_refinement
node_refinement -->|"ranks candidates"| node_candidate_selection
node_refinement -->|"uses embeddings"| node_dino_encoder
node_refinement -.->|"uses mask candidates"| node_matcher_masks
node_persam_runner -.->|"predicts masks"| node_persam_predictor
node_persam_core -->|"provides model"| node_persam_predictor
node_dino_encoder -->|"uses blocks"| node_dino_layers
node_matcher_core -->|"uses features"| node_dino_encoder
node_dino_data -.->|"prepares images"| node_dino_encoder
node_ssl_training -->|"builds backbone"| node_dino_encoder
node_ssl_training -->|"computes loss"| node_ssl_losses
node_candidate_selection -.->|"returns masks"| node_benchmark_eval
node_video_data -->|"supplies sequences"| node_video_eval

click node_matcher_runner "https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/pr_magic_for_matcher.py"
click node_persam_runner "https://github.com/postech-minjaelee/pr-magic/blob/main/Personalize-SAM/pr_magic_for_persam.py"
click node_refinement "https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/matcher/Matcher_PR.py"
click node_candidate_selection "https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/matcher/Matcher_PR.py"
click node_matcher_core "https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/matcher/Matcher.py"
click node_matcher_masks "https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/segment_anything/automatic_mask_generator.py"
click node_persam_core "https://github.com/postech-minjaelee/pr-magic/blob/main/Personalize-SAM/per_segment_anything/modeling/sam.py"
click node_persam_predictor "https://github.com/postech-minjaelee/pr-magic/blob/main/Personalize-SAM/per_segment_anything/predictor.py"
click node_dino_encoder "https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/dinov2/models/vision_transformer.py"
click node_dino_layers "https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/dinov2/layers/block.py"
click node_dino_data "https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/dinov2/data/transforms.py"
click node_ssl_training "https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/dinov2/train/ssl_meta_arch.py"
click node_ssl_losses "https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/dinov2/loss/ibot_patch_loss.py"
click node_benchmark_data "https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/matcher/data/dataset.py"
click node_benchmark_eval "https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/matcher/common/evaluation.py"
click node_persam_benchmarks "https://github.com/postech-minjaelee/pr-magic/blob/main/Personalize-SAM/datasets/dataset.py"
click node_video_data "https://github.com/postech-minjaelee/pr-magic/blob/main/Personalize-SAM/davis2017/davis.py"
click node_video_eval "https://github.com/postech-minjaelee/pr-magic/blob/main/Personalize-SAM/davis2017/evaluation.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_matcher_runner,node_persam_runner,node_refinement,node_candidate_selection toneBlue
class node_matcher_core,node_matcher_masks toneAmber
class node_persam_core,node_persam_predictor toneMint
class node_dino_encoder,node_dino_layers,node_dino_data,node_ssl_training,node_ssl_losses toneRose
class node_benchmark_data,node_benchmark_eval,node_persam_benchmarks,node_video_data,node_video_eval,node_user toneIndigo
```

## Components

### PR-MaGIC Workflow

- [Matcher PR Runner](https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/pr_magic_for_matcher.py): `Matcher/pr_magic_for_matcher.py`
- [PerSAM-F PR Runner](https://github.com/postech-minjaelee/pr-magic/blob/main/Personalize-SAM/pr_magic_for_persam.py): `Personalize-SAM/pr_magic_for_persam.py`
- [Prompt Refinement](https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/matcher/Matcher_PR.py): `Matcher/matcher/Matcher_PR.py`
- [Top-1 Selection](https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/matcher/Matcher_PR.py): `Matcher/matcher/Matcher_PR.py`

### Matcher Baseline

- [Matcher Segmentation](https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/matcher/Matcher.py): `Matcher/matcher/Matcher.py`
- [Automatic Mask Generation](https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/segment_anything/automatic_mask_generator.py): `Matcher/segment_anything/automatic_mask_generator.py`

### PerSAM-F Baseline

- [Personalized SAM](https://github.com/postech-minjaelee/pr-magic/blob/main/Personalize-SAM/per_segment_anything/modeling/sam.py): `Personalize-SAM/per_segment_anything/modeling/sam.py`
- [SAM Predictor](https://github.com/postech-minjaelee/pr-magic/blob/main/Personalize-SAM/per_segment_anything/predictor.py): `Personalize-SAM/per_segment_anything/predictor.py`

### Model Components

- [DINOv2 Encoder](https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/dinov2/models/vision_transformer.py): `Matcher/dinov2/models/vision_transformer.py`
- [Transformer Blocks](https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/dinov2/layers/block.py): `Matcher/dinov2/layers/block.py`
- [Image Transforms](https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/dinov2/data/transforms.py): `Matcher/dinov2/data/transforms.py`
- [Self-Supervised Training](https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/dinov2/train/ssl_meta_arch.py): `Matcher/dinov2/train/ssl_meta_arch.py`
- [DINOv2 Losses](https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/dinov2/loss/ibot_patch_loss.py): `Matcher/dinov2/loss/ibot_patch_loss.py`

### Data and Evaluation

- [Benchmark Datasets](https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/matcher/data/dataset.py): `Matcher/matcher/data/dataset.py`
- [Segmentation Evaluation](https://github.com/postech-minjaelee/pr-magic/blob/main/Matcher/matcher/common/evaluation.py): `Matcher/matcher/common/evaluation.py`
- [PerSAM Datasets](https://github.com/postech-minjaelee/pr-magic/blob/main/Personalize-SAM/datasets/dataset.py): `Personalize-SAM/datasets/dataset.py`
- [DAVIS Video Data](https://github.com/postech-minjaelee/pr-magic/blob/main/Personalize-SAM/davis2017/davis.py): `Personalize-SAM/davis2017/davis.py`
- [Video Evaluation](https://github.com/postech-minjaelee/pr-magic/blob/main/Personalize-SAM/davis2017/evaluation.py): `Personalize-SAM/davis2017/evaluation.py`

### Other components

- **Researcher**

## Connections

- Researcher → Matcher PR Runner: runs (evidence: `README.md`)
- Researcher → PerSAM-F PR Runner: runs (evidence: `README.md`)
- Matcher PR Runner → Matcher Segmentation: uses baseline (evidence: `Matcher/pr_magic_for_matcher.py`)
- Matcher PR Runner → Benchmark Datasets: loads benchmarks (evidence: `Matcher/pr_magic_for_matcher.py`)
- Matcher PR Runner → Segmentation Evaluation: evaluates masks (evidence: `Matcher/pr_magic_for_matcher.py`)
- Matcher PR Runner → Prompt Refinement: runs refinement (evidence: `Matcher/pr_magic_for_matcher.py`)
- PerSAM-F PR Runner → Personalized SAM: uses baseline (evidence: `Personalize-SAM/pr_magic_for_persam.py`)
- PerSAM-F PR Runner → PerSAM Datasets: loads benchmarks (evidence: `Personalize-SAM/pr_magic_for_persam.py`)
- Matcher Segmentation → Prompt Refinement: integrates with
- Prompt Refinement → Top-1 Selection: ranks candidates (evidence: `README.md`)
- Prompt Refinement → DINOv2 Encoder: uses embeddings (evidence: `Matcher/matcher/Matcher_PR.py`)
- Prompt Refinement → Automatic Mask Generation: uses mask candidates
- PerSAM-F PR Runner → SAM Predictor: predicts masks
- Personalized SAM → SAM Predictor: provides model (evidence: `Personalize-SAM/per_segment_anything/predictor.py`)
- DINOv2 Encoder → Transformer Blocks: uses blocks (evidence: `Matcher/dinov2/models/vision_transformer.py`)
- Matcher Segmentation → DINOv2 Encoder: uses features
- Image Transforms → DINOv2 Encoder: prepares images
- Self-Supervised Training → DINOv2 Encoder: builds backbone (evidence: `Matcher/dinov2/train/ssl_meta_arch.py`)
- Self-Supervised Training → DINOv2 Losses: computes loss (evidence: `Matcher/dinov2/train/ssl_meta_arch.py`)
- Top-1 Selection → Segmentation Evaluation: returns masks
- DAVIS Video Data → Video Evaluation: supplies sequences
