You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Aging GAN is an unpaired image-to-image translation project for facial age transformation built on a CycleGAN-style framework. It provides end-to-end tooling—from data preprocessing to training, inference, and a live Gradio demo—while offering infrastructure utilities to simplify deployment on AWS. The model trains two ResNet‑style "encoder-residual-decoder" generators and two PatchGAN discriminators on the UTKFace dataset, split into **Young** and **Old** subsets. The generators learn to translate between these domains, effectively "aging" or "de-aging" a face image.
4
3
5
-
Aging GAN is a research project exploring facial age transformation with a CycleGAN‑style approach. The model trains two ResNet‑style "encoder–residual–decoder" generators and two PatchGAN discriminators on the UTKFace dataset, split into **Young** and **Old** subsets. The generators learn to translate between these domains, effectively "aging" or "de-aging" a face image.
6
-
7
-
This repository contains training scripts, helper utilities, and inference scripts.
4
+
This repository contains training scripts, helper utilities, inference scripts, and a Gradio app for demo purposes.
8
5
9
6
## Features
10
-
11
-
-**Unpaired Training Data** – splits the UTKFace dataset into *Young* (18‑28) and *Old* (40+) subsets and builds an unpaired `DataLoader`.
12
-
-**CycleGAN Architecture** – residual U‑Net generators and PatchGAN discriminators.
13
-
-**Training Utilities** – gradient clipping, separate generator/discriminator learning rates with linear decay, mixed precision via `accelerate`, and optional S3 checkpoint archiving.
14
-
-**Evaluation** – FID metric computation on the validation and test sets.
15
-
-**Weights & Biases Logging** – track losses and metrics during training.
16
-
-**Scriptable Workflows** – shell scripts for training and inference.
17
-
-**Sample Generation** – saves example outputs after each epoch.
7
+
-**CycleGAN Architecture** - ResNet‑style "encoder-residual-decoder" generators and PatchGAN discriminators.
8
+
-**Data Pipeline & Preprocessing** - Deterministic train/val/test splits, on-the-fly augmentations, unpaired DataLoader that pairs Young (18–28) and Old (40+) faces at each batch
9
+
-**Training Utilities, Efficiency, Stability** - gradient clipping to stabilize adversarial updates, separate generator/discriminator learning rates with linear decay for latter half of training, mixed precision via `accelerate` for 2× speed/memory improvements, and checkpoint archiving.
10
+
-**Evaluation** - FID (Frechet Inception Distance) evaluation on validation and test splits.
11
+
-**Weights & Biases Logging** - track losses and metrics during training.
12
+
-**Inference Utilities** - command-line interface for image generation on user input.
13
+
-**AWS Utilities** - When running on EC2, IAM-ready scripts to automatically sync `outputs/` to S3 when saving checkpoints and terminate the instance after training.
14
+
-**Gradio Demo** – ready-to-deploy web app for interactive predictions. Hosted on [Huggingface Spaces](https://huggingface.co/spaces/codinglabsong/Reddit-User-Mimic-Bot).
15
+
-**Scriptable Workflows** - shell scripts for training and inference.
16
+
-**Reproducible Workflows** - configuration-based training scripts and environment variables. Optionally set seed during training.
17
+
-**Developer Tools** - linting with ruff and black, plus unit tests.
18
18
19
19
## Installation
20
+
1. Clone this repository and install the core dependencies:
21
+
```bash
22
+
pip install -r requirements.txt
23
+
```
20
24
21
-
```bash
22
-
pip install -r requirements.txt
23
-
```
25
+
2. (Optional) Install development tools for linting and testing:
26
+
```bash
27
+
pip install -r requirements-dev.txt
28
+
pre-commit install
29
+
```
24
30
25
-
Optional development tools:
31
+
3. Install the package itself (runs `setup.py`):
26
32
27
-
```bash
28
-
pip install -r requirements-dev.txt
29
-
pre-commit install
30
-
```
33
+
```bash
34
+
# Standard install:
35
+
pip install .
31
36
32
-
The package itself can be installed with:
33
-
34
-
```bash
35
-
pip install -e .
36
-
```
37
+
# Or editable/development install:
38
+
pip install -e .
39
+
```
37
40
38
41
## Data
39
-
Place the aligned UTKFace images under `data/utkface_aligned_cropped/UTKFace`.
40
-
The `prepare_dataset` function builds deterministic train/val/test splits and applies random flipping, cropping and rotation for training.
41
-
Each split is divided into *Young* and *Old* subsets for unpaired training.
42
+
We leverage the UTKFace dataset—a public collection of over 20,000 face images with age annotations (0–116), then use the aligned and cropped version for consistency.
43
+
44
+
Place your data under:
45
+
> data/utkface_aligned_cropped/UTKFace
46
+
47
+
The prepare_dataset functionhandles:
48
+
- Age-based splits: thresholds at 18–28 for Young, 40+ for Old, ignoring mid-range ages.
49
+
- Deterministic shuffling: 80% train, 10% validation, 10% test with a fixed RNG seed.
50
+
- Augmentations (train only): random horizontal flips, resizing to img_size+50, center/random cropping to img_size, random rotations up to 80°, and normalization to [-1, 1].
51
+
- Evaluation transforms: resize → center crop → normalization (no randomness).
42
52
43
-
## Training
44
-
Run training with default hyper‑parameters:
53
+
This pipeline ensures both diversity (via augmentation) and reproducibility (fixed splits and RNG).
54
+
55
+
## Usage
56
+
### Training
57
+
Use the wrapper script to launch training with your preferred hyper‑parameters:
The script loads `outputs/checkpoints/best.pth` by default and saves the result beside the input.
63
76
64
-
## AWS Utilities
65
-
When running on EC2, pass `--archive_and_terminate_ec2` to automatically sync `outputs/` to S3 and terminate the instance after training.
66
-
67
77
## Results
68
78
*Results will be added here once experiments are complete.*
69
79
70
-
## Example Outputs
80
+
### Example Outputs
71
81
*Example images will be shown here in a future update.*
72
82
73
-
## Repository Structure
83
+
### Considerations for Improvements
84
+
This project intentionally focused more on the methods and pipeline than the actual results. In the case you have more time and resources to improve the model, good points to start are...
-`scripts/` – helper scripts for training and inference
77
-
-`notebooks/` – exploratory notebooks
86
+
- Increase the dataset size by scraping or adding high quality Q/A data.
87
+
- Upgrade the model architecture to Bart-Large.
88
+
- Increase the LoRA rank (r).
89
+
- Train for more epochs.
90
+
- Use a better evaluation metric like RougeL for early stopping.
78
91
79
-
## Requirements
92
+
## Running the Gradio Inference App
93
+
This project includes an interactive Gradio app for making predictions with the trained model.
94
+
95
+
1. **Obtain the Trained Model:**
96
+
- Ensure that a trained model directory (e.g., `outputs/bart-base-reddit-lora/`) is available in the project root.
97
+
- If you trained the model yourself, it should be saved automatically in the project root.
98
+
- Otherwise, you can download it from [Releases](https://github.com/codinglabsong/bart-reddit-lora/releases/tag/v1.0.0) and add it in the project root.
99
+
100
+
2. **Run the App Locally:**
101
+
```bash
102
+
python app.py
103
+
```
104
+
- Visit the printed URL (e.g., `http://127.0.0.1:7860`) to interact with the model.
105
+
106
+
> You can also access the hosted demo on [Huggingface Spaces](https://huggingface.co/spaces/codinglabsong/Reddit-User-Mimic-Bot)
- `scripts/` - helper scripts for training and inference
118
+
- `notebooks/` - exploratory notebooks
119
+
- `tests/` - simple unit tests
120
+
- `outputs/` - generated directory for model outputs including `checkpoints/`, `images/` (for generated images per epoch), `metrics/test_metrics.json` (for storing test metrics for`best.pth` during training)
80
121
122
+
## Requirements
81
123
- Python ≥ 3.10
82
-
- PyTorch
124
+
- PyTorch>= 2.6
83
125
- Additional packages listed in`requirements.txt`
84
126
85
127
## Contributing
86
-
87
128
Contributions are welcome! Feel free to open issues or submit pull requests.
88
129
89
-
## License
130
+
## Acknowledgements
131
+
- [Original GAN Paper](https://arxiv.org/abs/1406.2661)
0 commit comments