File size: 2,418 Bytes
404ee20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
license: mit
tags:
- pytorch
- onnx
- flow-matching
- generative-art
- face-generation
pipeline_tag: image-to-image
---

# Alosha Painter

**Alosha Painter** is a generative computer vision model designed to draw and generate human faces using a custom **Flow Matching UNet** (`FlowMatchingUNet`). The model was trained on synthetic facial datasets collected by scraping [ThisPersonDoesNotExist.com](https://thispersondoesnotexist.com).

This repository contains the full model definition, training scripts, PyTorch EMA checkpoints, optimized ONNX exports (FP32, FP16, and INT8), and a local FastAPI demo server for quick image generation testing.

---

## Repository Structure

```text
.
β”œβ”€β”€ run.py                 # FastAPI demo server (PyTorch runtime)
β”œβ”€β”€ run_onnx.py            # FastAPI demo server (ONNX Runtime)
β”œβ”€β”€ scrape.py             # Data collection script for ThisPersonDoesNotExist
β”œβ”€β”€ train.py              # FlowMatchingUNet architecture & training pipeline
β”œβ”€β”€ data/
β”‚   └── faces/            # Scraped training dataset
└── weights/
    β”œβ”€β”€ checkpoint_latest.pth  # PyTorch EMA model checkpoint
    β”œβ”€β”€ unface.onnx            # Standard FP32 ONNX export
    β”œβ”€β”€ unface_fp16.onnx       # FP16 precision ONNX model (GPU)
    └── unface_int8.onnx       # Quantized INT8 ONNX model (CPU)
```

---

## Running the Demo Server

A lightweight FastAPI server is provided in `run.py` and `run_onnx.py` as a demo to test generation outputs via HTTP GET requests.

### 1. PyTorch Runtime Demo

```bash
python run.py
```

### 2. ONNX Runtime Demo

```bash
python run_onnx.py
```

Once running, access `http://localhost:8000/` in a web browser or run:

```bash
curl http://localhost:8000/ --output generated_face.png
```

Each request runs the flow-matching ODE sampler (`steps=20`), applies 2x bicubic upsampling, and returns a PNG image.

---

## Technical Details

* **Architecture:** Custom Flow Matching UNet (`FlowMatchingUNet`)
* **Sampling:** ODE vector-field integration
* **Checkpointing:** Exponential Moving Average (EMA) weights (`ckpt["ema"]`)
* **ONNX Exports:** Pre-compiled FP32, FP16, and INT8 quantized binaries for fast CPU/GPU deployment without PyTorch overhead.

---

## Dataset & Training

1. **Scrape Training Dataset:**
   ```bash
   python scrape.py
   ```
2. **Train Model:**
   ```bash
   python train.py
   ```