AI-powered virtual try-on system that generates realistic images of clothing on a user's body from a single photo.
Two modern API-based engines and one legacy GAN-based engine are available.
This repository contains components under different licenses.
- PASTA-GAN++ (legacy): Non-commercial research and educational purposes only. See License Notice below.
- Nano Banana / Vertex AI VTO (current): Commercial use allowed under Google API terms.
Please read the license section carefully before using any part of this project.
The simplest and most capable option. Uses Gemini API for virtual try-on.
pip install google-genai python-dotenv pillow- Go to Google AI Studio
- Create an API key
- Create
.envfile in the project root:
GEMINI_API_KEY=your-api-key-here# Clothing mode: product image -> person
python3 try_on_test.py --person test_data/person/woman_standing4.jpg \
--clothing test_data/clothing/red_dress.jpg
# Transfer mode: source person's clothes -> target person
python3 try_on_test.py --mode transfer \
--person test_data/person/woman_standing3.jpg \
--source test_data/person/woman_standing5.jpg
# With MediaPipe preprocessing (usually not needed for high-res images)
python3 try_on_test.py --mode transfer \
--person test_data/person/man_standing.jpg \
--source test_data/person/man_standing2.jpg \
--preprocessResults are saved to test_results/nano_banana/.
Google's dedicated virtual try-on model. Best for clothing product images (flat lay / white background).
pip install google-genai google-auth python-dotenv pillow-
Create a GCP project (or use an existing one) at Google Cloud Console
-
Enable Vertex AI API:
- Go to: https://console.cloud.google.com/apis/library/aiplatform.googleapis.com
- Click "Enable"
-
Create a Service Account:
- Go to: https://console.cloud.google.com/iam-admin/serviceaccounts
- Click "Create Service Account"
- Name: any name (e.g.,
vto-user) - Grant role: Vertex AI User (
roles/aiplatform.user)
-
Download JSON key:
- Click on the created service account
- Go to "Keys" tab -> "Add Key" -> "Create new key" -> JSON
- Save the downloaded JSON file to
configs/directory (gitignored)
-
Configure
.env:
GOOGLE_CLOUD_PROJECT=your-project-id
GOOGLE_CLOUD_LOCATION=us-central1
GOOGLE_APPLICATION_CREDENTIALS=configs/your-key-file.jsonNote: GCP offers $300 free credit for new accounts. Virtual Try-On costs approximately $0.02-0.04 per image.
Tip: If
gcloud auth application-default loginfails with scope errors (common with older gcloud versions), the service account method above is more reliable.
# Connection test
python3 test_vertex_vto.py
# Clothing mode (Vertex VTO's strength)
python3 test_vertex_vto.py test_data/person/woman_standing4.jpg test_data/clothing/red_dress.jpg
# Generate multiple samples (up to 4)
python3 test_vertex_vto.py test_data/person/man_standing.jpg test_data/clothing/hoodie.jpg 4Results are saved to test_results/vertex_vto/.
DEPRECATED: This is the legacy GAN-based approach. It is no longer actively maintained and no support is provided. The results are significantly inferior to Nano Banana / Vertex VTO. Included for research reference only.
LICENSE: PASTA-GAN++ and its dependencies (StyleGAN2, OpenPose) are non-commercial research only. Do NOT use for commercial purposes.
- NVIDIA GPU with CUDA support
- Docker with NVIDIA Container Toolkit
- Model weights (see below)
-
Download model weights (not included in this repo — download at your own responsibility):
Model File Download PASTA-GAN++ network-snapshot-004408.pklGoogle Drive (from official repo) OpenPose body_pose_model.pth(~209MB)HuggingFace Graphonomy inference.pth(~167MB)HuggingFace Note: These weights are provided by their respective authors. Please review each project's license before use.
-
Place weights in the following structure:
metafit/ └── weights/ ├── pasta-gan++/network-snapshot-004408.pkl ├── openpose/body_pose_model.pth └── graphonomy/inference.pth -
Prepare test data:
metafit/ └── test_datas/ ├── image/ (320x512px, white background images) ├── keypoints/ (OpenPose output, generated by test.py) ├── parsing/ (Graphonomy output, generated by test.py) └── test_pairs.txt- Place your test images in
test_datas/image/(must be 320x512px, full-length, white background) - Create
test_datas/test_pairs.txtwith space-separated pairs:target_person.jpg source_model.jpg keypoints/andparsing/are generated automatically if OpenPose/Graphonomy calls are uncommented intest.py
- Place your test images in
-
Build and run Docker:
make build && make run -
Run inference (inside Docker container):
python3 test.py --config configs/test_config.yaml
Note: OpenPose and Graphonomy preprocessing are currently commented out in
test.py. If you need to generatekeypoints/andparsing/from scratch, uncomment lines 28-40 intest.py.Results are saved to
test_results/full/.
Edit configs/test_config.yaml:
dataroot: test_datas
testtxt: test_pairs.txt
network: weights/pasta-gan++/network-snapshot-004408.pkl
outdir: test_results/full
batchsize: 1
testpart: full # full / upper / lower
use_sleeve_mask: false- Image size: 320x512 pixels (width x height)
- Full-length photo on white background
- Supported parts: full body, upper body, lower body
Various body types, poses, and genders for comprehensive testing. All images are from Unsplash (free for commercial use, no attribution required).
| File | Type | Source |
|---|---|---|
tshirt_black.png |
Black T-shirt | - |
sckirt.png |
Skirt | - |
red_dress.jpg |
Red dress | Unsplash |
denim_jacket.jpg |
Denim jacket | Unsplash |
hoodie.jpg |
Grey hoodie | Unsplash |
jeans.jpg |
Jeans | Unsplash |
striped_shirt.jpg |
Striped shirt | Unsplash |
suit_blazer.jpg |
Navy suit | Unsplash |
| Feature | PASTA-GAN++ (Legacy) | Nano Banana (Current) | Vertex AI VTO |
|---|---|---|---|
| Approach | GAN (local GPU) | Gemini API (cloud) | Dedicated VTO model (cloud) |
| Clothing mode (product -> person) | N/A | Good | Best (faithful reproduction) |
| Transfer mode (person -> person) | Poor | Best | Not supported |
| Body type diversity | Poor (slim bias) | Best (faithful) | Good |
| Complex patterns | Poor | Best | Good |
| Shoes | N/A | Poor | Best |
| Safety filter | None (local) | Strict (blocks exposed clothing) | Moderate (inconsistent) |
| Setup complexity | High (GPU + Docker) | Low (API key only) | Medium (GCP project) |
| Cost | Free (local) | Free tier available | ~$0.02-0.04/image |
| Commercial use | No | Yes | Yes |
The following components are included for research and educational purposes only. They MUST NOT be used for commercial purposes:
| Component | License | Repository |
|---|---|---|
| PASTA-GAN++ | Non-commercial research only | Try-on generation |
| StyleGAN2 (NVIDIA) | NVIDIA Source Code License-NC | Generator backbone |
| OpenPose (CMU) | CMU Academic Non-Commercial | Pose estimation |
Affected directories: torch_utils/, dnnlib/, training/, src/generate_keypoints.py, src/body.py
If you wish to use OpenPose commercially, a license is available through CMU FlintBox (~$25,000/year).
| Component | License | Usage |
|---|---|---|
| Graphonomy | MIT | Body segmentation |
| MediaPipe | Apache 2.0 | Face/Pose detection |
| PyTorch | BSD | ML framework |
| OpenCV | Apache 2.0 | Image processing |
| Pillow | MIT-like (HPND) | Image processing |
| Gemini API (Nano Banana) | Google API Terms | Try-on generation |
| Vertex AI VTO | Google Cloud Terms | Try-on generation |
If you plan to use this project commercially, use only the Nano Banana (try_on_test.py) and/or Vertex AI VTO (test_vertex_vto.py) pipelines. These do not depend on any non-commercial components.
Commercial-safe pipeline:
Photo -> Gemini API (Nano Banana) -> Try-on image OK
Photo -> Vertex AI VTO API -> Try-on image OK
NOT commercial-safe:
Photo -> OpenPose -> PASTA-GAN++ -> Try-on image NG