# minivision-ai/photo2cartoon architecture

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

- Interactive diagram: https://gitdiagram.com/minivision-ai/photo2cartoon
- Repository: https://github.com/minivision-ai/photo2cartoon

## Overview

Photo2Cartoon converts aligned portrait faces into cartoon-style images and also provides model training and ONNX testing. The documented preparation workflow detects and aligns faces, crops them, and removes backgrounds; inference preprocesses a portrait, applies the trained generator, and saves an image. Training uses unpaired photo/cartoon datasets and combines adversarial, cycle, identity, attention, and face-ID objectives. Edges are limited to relationships visible in excerpts or stated in the README; ONNX internals were not sampled.

Main entry points: [`models/UGATIT_sadalin_hourglass.py`](https://github.com/minivision-ai/photo2cartoon/blob/master/models/UGATIT_sadalin_hourglass.py) (UGATIT trainer), [`predict.py`](https://github.com/minivision-ai/photo2cartoon/blob/master/predict.py) (Prediction entry), [`utils/preprocess.py`](https://github.com/minivision-ai/photo2cartoon/blob/master/utils/preprocess.py) (Face preprocessing), [`data_process.py`](https://github.com/minivision-ai/photo2cartoon/blob/master/data_process.py) (Dataset preparation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_preparation["Data preparation"]
  node_data_process["Dataset preparation<br/>[data_process.py]"]
  node_preprocess["Face preprocessing<br/>[preprocess.py]"]
  node_face_detect["Face alignment<br/>[face_detect.py]"]
  node_face_seg["Portrait segmentation<br/>[face_seg.py]"]
end

subgraph group_inference["Cartoon inference"]
  node_predict["Prediction entry<br/>[predict.py]"]
  node_inference_preprocess["Inference preprocessing<br/>[preprocess.py]"]
  node_output_image["Cartoon image"]
  node_onnx_test["ONNX model test<br/>[test_onnx.py]"]
end

subgraph group_training["Model training"]
  node_train_entry["Training entry<br/>[train.py]"]
  node_training_engine["UGATIT trainer"]
  node_image_dataset["Image dataset loader<br/>[dataset.py]"]
  node_checkpoint["Model weights"]
end

subgraph group_networks["Model components"]
  node_generator["Image generator<br/>[networks.py]"]
  node_face_features["Face ID features<br/>[face_features.py]"]
  node_mobilefacenet["MobileFaceNet<br/>[mobilefacenet.py]"]
end

node_user(("Portrait user"))
node_trainer(("Model trainer"))

node_trainer -->|"prepares data"| node_data_process
node_data_process -.->|"uses pipeline"| node_preprocess
node_preprocess -->|"aligns face"| node_face_detect
node_preprocess -->|"gets mask"| node_face_seg
node_user -->|"submits portrait"| node_predict
node_predict -->|"preprocesses image"| node_inference_preprocess
node_predict -->|"runs inference"| node_generator
node_predict -->|"writes result"| node_output_image
node_user -->|"runs ONNX test"| node_onnx_test
node_trainer -->|"starts training"| node_train_entry
node_train_entry -->|"builds and trains"| node_training_engine
node_training_engine -->|"loads images"| node_image_dataset
node_training_engine -->|"constructs networks"| node_generator
node_training_engine -->|"computes face loss"| node_face_features
node_face_features -->|"extracts features"| node_mobilefacenet
node_training_engine -->|"saves weights"| node_checkpoint

click node_data_process "https://github.com/minivision-ai/photo2cartoon/blob/master/data_process.py"
click node_preprocess "https://github.com/minivision-ai/photo2cartoon/blob/master/utils/preprocess.py"
click node_face_detect "https://github.com/minivision-ai/photo2cartoon/blob/master/utils/face_detect.py"
click node_face_seg "https://github.com/minivision-ai/photo2cartoon/blob/master/utils/face_seg.py"
click node_predict "https://github.com/minivision-ai/photo2cartoon/blob/master/predict.py"
click node_inference_preprocess "https://github.com/minivision-ai/photo2cartoon/blob/master/utils/preprocess.py"
click node_onnx_test "https://github.com/minivision-ai/photo2cartoon/blob/master/test_onnx.py"
click node_train_entry "https://github.com/minivision-ai/photo2cartoon/blob/master/train.py"
click node_training_engine "https://github.com/minivision-ai/photo2cartoon/blob/master/models/UGATIT_sadalin_hourglass.py"
click node_image_dataset "https://github.com/minivision-ai/photo2cartoon/blob/master/dataset.py"
click node_checkpoint "https://github.com/minivision-ai/photo2cartoon/tree/master/models"
click node_generator "https://github.com/minivision-ai/photo2cartoon/blob/master/models/networks.py"
click node_face_features "https://github.com/minivision-ai/photo2cartoon/blob/master/models/face_features.py"
click node_mobilefacenet "https://github.com/minivision-ai/photo2cartoon/blob/master/models/mobilefacenet.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_data_process,node_preprocess,node_face_detect,node_face_seg,node_user toneBlue
class node_predict,node_inference_preprocess,node_output_image,node_onnx_test toneAmber
class node_train_entry,node_training_engine,node_image_dataset,node_checkpoint toneMint
class node_generator,node_face_features,node_mobilefacenet toneRose
class node_trainer toneIndigo
```

## Components

### Data preparation

- [Dataset preparation](https://github.com/minivision-ai/photo2cartoon/blob/master/data_process.py): `data_process.py`
- [Face preprocessing](https://github.com/minivision-ai/photo2cartoon/blob/master/utils/preprocess.py): `utils/preprocess.py`
- [Face alignment](https://github.com/minivision-ai/photo2cartoon/blob/master/utils/face_detect.py): `utils/face_detect.py`
- [Portrait segmentation](https://github.com/minivision-ai/photo2cartoon/blob/master/utils/face_seg.py): `utils/face_seg.py`

### Cartoon inference

- [Prediction entry](https://github.com/minivision-ai/photo2cartoon/blob/master/predict.py): `predict.py`
- [Inference preprocessing](https://github.com/minivision-ai/photo2cartoon/blob/master/utils/preprocess.py): `utils/preprocess.py`
- **Cartoon image**
- [ONNX model test](https://github.com/minivision-ai/photo2cartoon/blob/master/test_onnx.py): `test_onnx.py`

### Model training

- [Training entry](https://github.com/minivision-ai/photo2cartoon/blob/master/train.py): `train.py`
- [UGATIT trainer](https://github.com/minivision-ai/photo2cartoon/blob/master/models/UGATIT_sadalin_hourglass.py): `models/UGATIT_sadalin_hourglass.py`
- [Image dataset loader](https://github.com/minivision-ai/photo2cartoon/blob/master/dataset.py): `dataset.py`
- [Model weights](https://github.com/minivision-ai/photo2cartoon/tree/master/models): `models`

### Model components

- [Image generator](https://github.com/minivision-ai/photo2cartoon/blob/master/models/networks.py): `models/networks.py`
- [Face ID features](https://github.com/minivision-ai/photo2cartoon/blob/master/models/face_features.py): `models/face_features.py`
- [MobileFaceNet](https://github.com/minivision-ai/photo2cartoon/blob/master/models/mobilefacenet.py): `models/mobilefacenet.py`

### Other components

- **Portrait user**
- **Model trainer**

## Connections

- Model trainer → Dataset preparation: prepares data (evidence: `README.md`)
- Dataset preparation → Face preprocessing: uses pipeline
- Face preprocessing → Face alignment: aligns face (evidence: `utils/preprocess.py`)
- Face preprocessing → Portrait segmentation: gets mask (evidence: `utils/preprocess.py`)
- Portrait user → Prediction entry: submits portrait (evidence: `predict.py`)
- Prediction entry → Inference preprocessing: preprocesses image (evidence: `predict.py`)
- Prediction entry → Image generator: runs inference (evidence: `predict.py`)
- Prediction entry → Cartoon image: writes result (evidence: `predict.py`)
- Portrait user → ONNX model test: runs ONNX test (evidence: `README.md`)
- Model trainer → Training entry: starts training (evidence: `README.md`)
- Training entry → UGATIT trainer: builds and trains (evidence: `train.py`)
- UGATIT trainer → Image dataset loader: loads images (evidence: `models/UGATIT_sadalin_hourglass.py`)
- UGATIT trainer → Image generator: constructs networks (evidence: `models/UGATIT_sadalin_hourglass.py`)
- UGATIT trainer → Face ID features: computes face loss (evidence: `models/UGATIT_sadalin_hourglass.py`)
- Face ID features → MobileFaceNet: extracts features (evidence: `models/face_features.py`)
- UGATIT trainer → Model weights: saves weights (evidence: `models/UGATIT_sadalin_hourglass.py`)
