# pillow-1/xsyn architecture

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

- Interactive diagram: https://gitdiagram.com/pillow-1/xsyn
- Repository: https://github.com/pillow-1/xsyn

## Overview

Xsyn generates synthetic X-ray security images through GLIGEN-based text-grounded inpainting, with training on PIDray-style data and inference outputs that include refined annotations and visualizations. Training starts in main.py, which constructs Trainer; inference is launched separately by gligen_inference.py. The tree and excerpts support the model, sampler, data, and annotation branches, but do not expose every inference-stage call or the implementation of all grounding modalities, so some documented capability nodes have no asserted runtime links.

Main entry points: [`gligen_inference.py`](https://github.com/pillow-1/xsyn/blob/main/gligen_inference.py) (Inference runner), [`trainer.py`](https://github.com/pillow-1/xsyn/blob/main/trainer.py) (Trainer), [`ldm/models/diffusion/ldm.py`](https://github.com/pillow-1/xsyn/blob/main/ldm/models/diffusion/ldm.py) (GLIGEN diffusion), [`ldm/modules/diffusionmodules/openaimodel.py`](https://github.com/pillow-1/xsyn/blob/main/ldm/modules/diffusionmodules/openaimodel.py) (Grounding U-Net)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_training["Training"]
  node_main["Training entry<br/>[main.py]"]
  node_trainer["Trainer<br/>[trainer.py]"]
end

subgraph group_data["Data preparation"]
  node_dataset["Dataset assembly<br/>[concat_dataset.py]"]
  node_pidray["PIDray samples<br/>[pidray_dataset.py]"]
  node_tsvprep["TSV preparation<br/>[mydata_to_tsv.py]"]
  node_tsv["TSV reader<br/>[tsv.py]"]
end

subgraph group_generation["Inpainting generation"]
  node_inference["Inference runner"]
  node_mask["Inpainting masks"]
  node_groundinginput["Grounding inputs"]
  node_samplerddim["DDIM sampler<br/>[ddim.py]"]
  node_samplerplms["PLMS sampler<br/>[plms.py]"]
end

subgraph group_model["Diffusion model"]
  node_diffusion["GLIGEN diffusion<br/>[ldm.py]"]
  node_unet["Grounding U-Net<br/>[openaimodel.py]"]
  node_groundingnets["Grounding networks"]
  node_attention["Attention layers<br/>[attention.py]"]
  node_autoencoder["Latent autoencoder<br/>[autoencoder.py]"]
end

subgraph group_results["Annotations and evaluation"]
  node_annotation["Annotation refinement<br/>[gen_anno.py]"]
  node_outputs["Generated images and annotations"]
  node_detector["Downstream detector"]
end

node_user(("Research user"))

node_user -->|"starts training"| node_main
node_main -->|"creates and starts"| node_trainer
node_trainer -->|"loads batches"| node_dataset
node_dataset -.->|"assembles dataset"| node_pidray
node_tsvprep -->|"writes TSV"| node_tsv
node_user -->|"runs generation"| node_inference
node_inference -->|"imports sampler"| node_samplerddim
node_inference -->|"imports sampler"| node_samplerplms
node_inference -->|"uses masks"| node_mask
node_trainer -->|"imports sampler"| node_samplerddim
node_trainer -->|"imports sampler"| node_samplerplms
node_samplerddim -->|"predicts noise"| node_diffusion
node_diffusion -.->|"uses network"| node_unet
node_unet -.->|"uses grounding modules"| node_groundingnets
node_unet -.->|"uses attention"| node_attention
node_diffusion -.->|"encodes and decodes"| node_autoencoder
node_inference -->|"saves results"| node_outputs
node_inference -.->|"constructs annotations"| node_annotation
node_annotation -.->|"refines annotations"| node_outputs
node_outputs -->|"evaluated downstream"| node_detector

click node_main "https://github.com/pillow-1/xsyn/blob/main/main.py"
click node_trainer "https://github.com/pillow-1/xsyn/blob/main/trainer.py"
click node_dataset "https://github.com/pillow-1/xsyn/blob/main/dataset/concat_dataset.py"
click node_pidray "https://github.com/pillow-1/xsyn/blob/main/dataset/pidray_dataset.py"
click node_tsvprep "https://github.com/pillow-1/xsyn/blob/main/DATA/mydata_to_tsv.py"
click node_tsv "https://github.com/pillow-1/xsyn/blob/main/DATA/tsv.py"
click node_inference "https://github.com/pillow-1/xsyn/blob/main/gligen_inference.py"
click node_mask "https://github.com/pillow-1/xsyn/blob/main/inpaint_mask_func.py"
click node_groundinginput "https://github.com/pillow-1/xsyn/tree/main/grounding_input"
click node_samplerddim "https://github.com/pillow-1/xsyn/blob/main/ldm/models/diffusion/ddim.py"
click node_samplerplms "https://github.com/pillow-1/xsyn/blob/main/ldm/models/diffusion/plms.py"
click node_diffusion "https://github.com/pillow-1/xsyn/blob/main/ldm/models/diffusion/ldm.py"
click node_unet "https://github.com/pillow-1/xsyn/blob/main/ldm/modules/diffusionmodules/openaimodel.py"
click node_groundingnets "https://github.com/pillow-1/xsyn/tree/main/ldm/modules/diffusionmodules"
click node_attention "https://github.com/pillow-1/xsyn/blob/main/ldm/modules/attention.py"
click node_autoencoder "https://github.com/pillow-1/xsyn/blob/main/ldm/models/autoencoder.py"
click node_annotation "https://github.com/pillow-1/xsyn/blob/main/gen_anno.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_main,node_trainer,node_user toneBlue
class node_dataset,node_pidray,node_tsvprep,node_tsv toneAmber
class node_inference,node_mask,node_groundinginput,node_samplerddim,node_samplerplms toneMint
class node_diffusion,node_unet,node_groundingnets,node_attention,node_autoencoder toneRose
class node_annotation,node_outputs,node_detector toneIndigo
```

## Components

### Training

- [Training entry](https://github.com/pillow-1/xsyn/blob/main/main.py): `main.py`
- [Trainer](https://github.com/pillow-1/xsyn/blob/main/trainer.py): `trainer.py`

### Data preparation

- [Dataset assembly](https://github.com/pillow-1/xsyn/blob/main/dataset/concat_dataset.py): `dataset/concat_dataset.py`
- [PIDray samples](https://github.com/pillow-1/xsyn/blob/main/dataset/pidray_dataset.py): `dataset/pidray_dataset.py`
- [TSV preparation](https://github.com/pillow-1/xsyn/blob/main/DATA/mydata_to_tsv.py): `DATA/mydata_to_tsv.py`
- [TSV reader](https://github.com/pillow-1/xsyn/blob/main/DATA/tsv.py): `DATA/tsv.py`

### Inpainting generation

- [Inference runner](https://github.com/pillow-1/xsyn/blob/main/gligen_inference.py): `gligen_inference.py`
- [Inpainting masks](https://github.com/pillow-1/xsyn/blob/main/inpaint_mask_func.py): `inpaint_mask_func.py`
- [Grounding inputs](https://github.com/pillow-1/xsyn/tree/main/grounding_input): `grounding_input`
- [DDIM sampler](https://github.com/pillow-1/xsyn/blob/main/ldm/models/diffusion/ddim.py): `ldm/models/diffusion/ddim.py`
- [PLMS sampler](https://github.com/pillow-1/xsyn/blob/main/ldm/models/diffusion/plms.py): `ldm/models/diffusion/plms.py`

### Diffusion model

- [GLIGEN diffusion](https://github.com/pillow-1/xsyn/blob/main/ldm/models/diffusion/ldm.py): `ldm/models/diffusion/ldm.py`
- [Grounding U-Net](https://github.com/pillow-1/xsyn/blob/main/ldm/modules/diffusionmodules/openaimodel.py): `ldm/modules/diffusionmodules/openaimodel.py`
- [Grounding networks](https://github.com/pillow-1/xsyn/tree/main/ldm/modules/diffusionmodules): `ldm/modules/diffusionmodules`
- [Attention layers](https://github.com/pillow-1/xsyn/blob/main/ldm/modules/attention.py): `ldm/modules/attention.py`
- [Latent autoencoder](https://github.com/pillow-1/xsyn/blob/main/ldm/models/autoencoder.py): `ldm/models/autoencoder.py`

### Annotations and evaluation

- [Annotation refinement](https://github.com/pillow-1/xsyn/blob/main/gen_anno.py): `gen_anno.py`
- **Generated images and annotations**
- **Downstream detector**

### Other components

- **Research user**

## Connections

- Research user → Training entry: starts training (evidence: `main.py`)
- Training entry → Trainer: creates and starts (evidence: `main.py`)
- Trainer → Dataset assembly: loads batches (evidence: `trainer.py`)
- Dataset assembly → PIDray samples: assembles dataset
- TSV preparation → TSV reader: writes TSV (evidence: `DATA/mydata_to_tsv.py`)
- Research user → Inference runner: runs generation (evidence: `README.md`)
- Inference runner → DDIM sampler: imports sampler (evidence: `gligen_inference.py`)
- Inference runner → PLMS sampler: imports sampler (evidence: `gligen_inference.py`)
- Inference runner → Inpainting masks: uses masks (evidence: `gligen_inference.py`)
- Trainer → DDIM sampler: imports sampler (evidence: `trainer.py`)
- Trainer → PLMS sampler: imports sampler (evidence: `trainer.py`)
- DDIM sampler → GLIGEN diffusion: predicts noise (evidence: `ldm/models/diffusion/ddim.py`)
- GLIGEN diffusion → Grounding U-Net: uses network
- Grounding U-Net → Grounding networks: uses grounding modules
- Grounding U-Net → Attention layers: uses attention
- GLIGEN diffusion → Latent autoencoder: encodes and decodes
- Inference runner → Generated images and annotations: saves results (evidence: `README.md`)
- Inference runner → Annotation refinement: constructs annotations (evidence: `README.md`)
- Annotation refinement → Generated images and annotations: refines annotations
- Generated images and annotations → Downstream detector: evaluated downstream (evidence: `README.md`)
