# jiacongfang/petal architecture

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

- Interactive diagram: https://gitdiagram.com/jiacongfang/petal
- Repository: https://github.com/jiacongfang/petal

## Overview

PETAL is an image-to-image photographic style-transfer inference project. Its primary workflow pairs content and reference images by filename stem, encodes their LAB photographic characteristics, and uses the embeddings to guide an adaptive LUT model that produces stylized images. A separate PST50 workflow runs or reuses predictions and evaluates them against paired ground truth. The README documents both workflows; the supplied excerpts show inference and model internals, but not all benchmark wiring.

Main entry points: [`benchmark_pst50.py`](https://github.com/jiacongfang/petal/blob/master/benchmark_pst50.py) (PST50 runner), [`infer.py`](https://github.com/jiacongfang/petal/blob/master/infer.py) (Run transfer), [`models_style_encoder.py`](https://github.com/jiacongfang/petal/blob/master/models_style_encoder.py) (Style encoder), [`data/PST50/paired_gt`](https://github.com/jiacongfang/petal/tree/master/data/PST50/paired_gt) (Paired ground truth)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_inference["Inference workflow"]
  node_pairing["Pair images<br/>[infer.py]"]
  node_imageprep["Image preparation<br/>[infer.py]"]
  node_inference_run["Run transfer<br/>[infer.py]"]
  node_output["Stylized images<br/>[infer.py]"]
end

subgraph group_models["Transfer models"]
  node_style_encoder["Style encoder"]
  node_histogram["LAB histograms"]
  node_vit["ViT embedding"]
  node_lut["Adaptive LUT<br/>[models_lut.py]"]
end

subgraph group_layers["Transformer layers"]
  node_layers["ViT components"]
end

subgraph group_benchmark["PST50 evaluation"]
  node_benchmark["PST50 runner<br/>[benchmark_pst50.py]"]
  node_dataset["PST50 pairs"]
  node_predictions["Predictions<br/>[benchmark_pst50.py]"]
  node_metrics["Quality metrics<br/>[benchmark_pst50.py]"]
  node_ground_truth["Paired ground truth"]
end

node_user(("Image user"))
node_benchmark_user(("Benchmark user"))

node_user -->|"provides directories"| node_pairing
node_pairing -->|"pairs by stem"| node_imageprep
node_imageprep -->|"prepared images"| node_inference_run
node_inference_run -->|"encodes style"| node_style_encoder
node_style_encoder -->|"extracts statistics"| node_histogram
node_style_encoder -->|"produces embedding"| node_vit
node_vit -->|"uses components"| node_layers
node_inference_run -->|"guides transfer"| node_lut
node_inference_run -->|"writes images"| node_output
node_benchmark_user -->|"starts evaluation"| node_benchmark
node_benchmark -->|"reads pairs"| node_dataset
node_benchmark -->|"runs transfer"| node_inference_run
node_benchmark -->|"writes or reuses"| node_predictions
node_predictions -->|"evaluates against"| node_metrics
node_benchmark -->|"reads references"| node_ground_truth
node_ground_truth -->|"provides comparison"| node_metrics

click node_pairing "https://github.com/jiacongfang/petal/blob/master/infer.py"
click node_imageprep "https://github.com/jiacongfang/petal/blob/master/infer.py"
click node_inference_run "https://github.com/jiacongfang/petal/blob/master/infer.py"
click node_output "https://github.com/jiacongfang/petal/blob/master/infer.py"
click node_style_encoder "https://github.com/jiacongfang/petal/blob/master/models_style_encoder.py"
click node_histogram "https://github.com/jiacongfang/petal/blob/master/models_style_encoder.py"
click node_vit "https://github.com/jiacongfang/petal/blob/master/models_style_encoder.py"
click node_lut "https://github.com/jiacongfang/petal/blob/master/models_lut.py"
click node_layers "https://github.com/jiacongfang/petal/tree/master/layers"
click node_benchmark "https://github.com/jiacongfang/petal/blob/master/benchmark_pst50.py"
click node_dataset "https://github.com/jiacongfang/petal/tree/master/data/PST50"
click node_predictions "https://github.com/jiacongfang/petal/blob/master/benchmark_pst50.py"
click node_metrics "https://github.com/jiacongfang/petal/blob/master/benchmark_pst50.py"
click node_ground_truth "https://github.com/jiacongfang/petal/tree/master/data/PST50/paired_gt"

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_pairing,node_imageprep,node_inference_run,node_output,node_user,node_benchmark_user toneBlue
class node_style_encoder,node_histogram,node_vit,node_lut toneAmber
class node_layers toneMint
class node_benchmark,node_dataset,node_predictions,node_metrics,node_ground_truth toneRose
```

## Components

### Inference workflow

- [Pair images](https://github.com/jiacongfang/petal/blob/master/infer.py): `infer.py`
- [Image preparation](https://github.com/jiacongfang/petal/blob/master/infer.py): `infer.py`
- [Run transfer](https://github.com/jiacongfang/petal/blob/master/infer.py): `infer.py`
- [Stylized images](https://github.com/jiacongfang/petal/blob/master/infer.py): `infer.py`

### Transfer models

- [Style encoder](https://github.com/jiacongfang/petal/blob/master/models_style_encoder.py): `models_style_encoder.py`
- [LAB histograms](https://github.com/jiacongfang/petal/blob/master/models_style_encoder.py): `models_style_encoder.py`
- [ViT embedding](https://github.com/jiacongfang/petal/blob/master/models_style_encoder.py): `models_style_encoder.py`
- [Adaptive LUT](https://github.com/jiacongfang/petal/blob/master/models_lut.py): `models_lut.py`

### Transformer layers

- [ViT components](https://github.com/jiacongfang/petal/tree/master/layers): `layers`

### PST50 evaluation

- [PST50 runner](https://github.com/jiacongfang/petal/blob/master/benchmark_pst50.py): `benchmark_pst50.py`
- [PST50 pairs](https://github.com/jiacongfang/petal/tree/master/data/PST50): `data/PST50`
- [Predictions](https://github.com/jiacongfang/petal/blob/master/benchmark_pst50.py): `benchmark_pst50.py`
- [Quality metrics](https://github.com/jiacongfang/petal/blob/master/benchmark_pst50.py): `benchmark_pst50.py`
- [Paired ground truth](https://github.com/jiacongfang/petal/tree/master/data/PST50/paired_gt): `data/PST50/paired_gt`

### Other components

- **Image user**
- **Benchmark user**

## Connections

- Image user → Pair images: provides directories
- Pair images → Image preparation: pairs by stem
- Image preparation → Run transfer: prepared images
- Run transfer → Style encoder: encodes style
- Style encoder → LAB histograms: extracts statistics
- Style encoder → ViT embedding: produces embedding
- ViT embedding → ViT components: uses components
- Run transfer → Adaptive LUT: guides transfer
- Run transfer → Stylized images: writes images
- Benchmark user → PST50 runner: starts evaluation
- PST50 runner → PST50 pairs: reads pairs
- PST50 runner → Run transfer: runs transfer
- PST50 runner → Predictions: writes or reuses
- Predictions → Quality metrics: evaluates against
- PST50 runner → Paired ground truth: reads references
- Paired ground truth → Quality metrics: provides comparison
