Spaces:
Running
on
Zero
Running
on
Zero
add try off
Browse files- .gitignore +3 -0
- README.md +34 -4
- example/tryoff_result/restored_garment1.png +0 -0
- example/tryoff_result/restored_garment2.png +0 -0
- example/tryoff_result/restored_garment3.png +0 -0
- example/tryoff_result/restored_garment4.png +0 -0
- example/tryoff_result/restored_garment5.png +0 -0
- example/tryoff_result/restored_garment6.png +0 -0
- requirements.txt +1 -0
- test.png +0 -0
- tryoff.sh +7 -0
- tryoff_inference.py +117 -0
- tryon.sh +7 -0
.gitignore
CHANGED
@@ -53,3 +53,6 @@ Thumbs.db
|
|
53 |
|
54 |
# Gradio cache
|
55 |
.gradio/example/github.mp4
|
|
|
|
|
|
|
|
53 |
|
54 |
# Gradio cache
|
55 |
.gradio/example/github.mp4
|
56 |
+
|
57 |
+
aws/
|
58 |
+
checkpoints/
|
README.md
CHANGED
@@ -22,6 +22,9 @@ Running it now on website: [CATVTON-FLUX-TRY-ON](https://huggingface.co/spaces/x
|
|
22 |
---
|
23 |
**Latest Achievement**
|
24 |
|
|
|
|
|
|
|
25 |
(2024/12/1):
|
26 |
- Community comfyui support [here](https://github.com/lujiazho/ComfyUI-CatvtonFluxWrapper). Thanks to [lujiazho](https://github.com/lujiazho)
|
27 |
|
@@ -43,17 +46,31 @@ Running it now on website: [CATVTON-FLUX-TRY-ON](https://huggingface.co/spaces/x
|
|
43 |
---
|
44 |
|
45 |
## Showcase
|
|
|
|
|
46 |
| Original | Garment | Result |
|
47 |
|----------|---------|---------|
|
48 |
| ![Original](example/person/1.jpg) | ![Garment](example/garment/00035_00.jpg) | ![Result](example/result/1.png) |
|
49 |
| ![Original](example/person/1.jpg) | ![Garment](example/garment/04564_00.jpg) | ![Result](example/result/2.png) |
|
50 |
| ![Original](example/person/00008_00.jpg) | ![Garment](example/garment/00034_00.jpg) | ![Result](example/result/3.png) |
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
## Model Weights
|
|
|
53 |
Fine-tuning weights in Hugging Face: 🤗 [catvton-flux-alpha](https://huggingface.co/xiaozaa/catvton-flux-alpha)
|
54 |
-
|
55 |
LORA weights in Hugging Face: 🤗 [catvton-flux-lora-alpha](https://huggingface.co/xiaozaa/catvton-flux-lora-alpha)
|
56 |
|
|
|
|
|
|
|
|
|
57 |
The model weights are trained on the [VITON-HD](https://github.com/shadow2496/VITON-HD) dataset.
|
58 |
|
59 |
## Prerequisites
|
@@ -69,6 +86,19 @@ huggingface-cli login
|
|
69 |
|
70 |
## Usage
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
Run the following command to try on an image:
|
73 |
|
74 |
LORA version:
|
@@ -104,7 +134,7 @@ python app_no_lora.py
|
|
104 |
```
|
105 |
|
106 |
Gradio demo:
|
107 |
-
|
108 |
<!-- Option 2: Using a thumbnail linked to the video -->
|
109 |
[![Demo](example/github.jpg)](https://upcdn.io/FW25b7k/raw/uploads/github.mp4)
|
110 |
|
@@ -114,8 +144,8 @@ Gradio demo:
|
|
114 |
- [x] Add gradio demo
|
115 |
- [x] Release updated weights with better performance
|
116 |
- [x] Train a smaller model
|
117 |
-
- [
|
118 |
-
|
119 |
## Citation
|
120 |
|
121 |
```bibtex
|
|
|
22 |
---
|
23 |
**Latest Achievement**
|
24 |
|
25 |
+
(2024/12/6):
|
26 |
+
- Released a new weights for tryoff. The model named [cat-tryoff-flux](https://huggingface.co/xiaozaa/cat-tryoff-flux) can extract and reconstruct the front view of clothing items from images of people wearing them.
|
27 |
+
|
28 |
(2024/12/1):
|
29 |
- Community comfyui support [here](https://github.com/lujiazho/ComfyUI-CatvtonFluxWrapper). Thanks to [lujiazho](https://github.com/lujiazho)
|
30 |
|
|
|
46 |
---
|
47 |
|
48 |
## Showcase
|
49 |
+
|
50 |
+
### Try-on examples
|
51 |
| Original | Garment | Result |
|
52 |
|----------|---------|---------|
|
53 |
| ![Original](example/person/1.jpg) | ![Garment](example/garment/00035_00.jpg) | ![Result](example/result/1.png) |
|
54 |
| ![Original](example/person/1.jpg) | ![Garment](example/garment/04564_00.jpg) | ![Result](example/result/2.png) |
|
55 |
| ![Original](example/person/00008_00.jpg) | ![Garment](example/garment/00034_00.jpg) | ![Result](example/result/3.png) |
|
56 |
|
57 |
+
### Try-off examples
|
58 |
+
| Original clothed model | Restored garment result |
|
59 |
+
|------------------------|------------------------|
|
60 |
+
| ![Original](example/person/00055_00.jpg) | ![Restored garment result](example/tryoff_result/restored_garment2.png) |
|
61 |
+
| ![Original](example/person/00064_00.jpg) | ![Restored garment result](example/tryoff_result/restored_garment4.png) |
|
62 |
+
| ![Original](example/person/00069_00.jpg) | ![Restored garment result](example/tryoff_result/restored_garment6.png) |
|
63 |
+
|
64 |
+
|
65 |
## Model Weights
|
66 |
+
### Tryon
|
67 |
Fine-tuning weights in Hugging Face: 🤗 [catvton-flux-alpha](https://huggingface.co/xiaozaa/catvton-flux-alpha)
|
|
|
68 |
LORA weights in Hugging Face: 🤗 [catvton-flux-lora-alpha](https://huggingface.co/xiaozaa/catvton-flux-lora-alpha)
|
69 |
|
70 |
+
### Tryoff
|
71 |
+
Fine-tuning weights in Hugging Face: 🤗 [cat-tryoff-flux](https://huggingface.co/xiaozaa/cat-tryoff-flux)
|
72 |
+
|
73 |
+
### Dataset
|
74 |
The model weights are trained on the [VITON-HD](https://github.com/shadow2496/VITON-HD) dataset.
|
75 |
|
76 |
## Prerequisites
|
|
|
86 |
|
87 |
## Usage
|
88 |
|
89 |
+
### Tryoff
|
90 |
+
Run the following command to restore the front side of the garment from the clothed model image:
|
91 |
+
```bash
|
92 |
+
python tryoff_inference.py \
|
93 |
+
--image ./example/person/00069_00.jpg \
|
94 |
+
--mask ./example/person/00069_00_mask.png \
|
95 |
+
--seed 41 \
|
96 |
+
--output_tryon test_original.png \
|
97 |
+
--output_garment restored_garment6.png \
|
98 |
+
--steps 30
|
99 |
+
```
|
100 |
+
|
101 |
+
### Tryon
|
102 |
Run the following command to try on an image:
|
103 |
|
104 |
LORA version:
|
|
|
134 |
```
|
135 |
|
136 |
Gradio demo:
|
137 |
+
Hugging Face: 🤗 [CATVTON-FLUX-TRY-ON](https://huggingface.co/spaces/xiaozaa/catvton-flux-try-on)
|
138 |
<!-- Option 2: Using a thumbnail linked to the video -->
|
139 |
[![Demo](example/github.jpg)](https://upcdn.io/FW25b7k/raw/uploads/github.mp4)
|
140 |
|
|
|
144 |
- [x] Add gradio demo
|
145 |
- [x] Release updated weights with better performance
|
146 |
- [x] Train a smaller model
|
147 |
+
- [x] Support comfyui
|
148 |
+
- [x] Release tryoff weights
|
149 |
## Citation
|
150 |
|
151 |
```bibtex
|
example/tryoff_result/restored_garment1.png
ADDED
example/tryoff_result/restored_garment2.png
ADDED
example/tryoff_result/restored_garment3.png
ADDED
example/tryoff_result/restored_garment4.png
ADDED
example/tryoff_result/restored_garment5.png
ADDED
example/tryoff_result/restored_garment6.png
ADDED
requirements.txt
CHANGED
@@ -11,3 +11,4 @@ sentencepiece
|
|
11 |
peft==0.13.2
|
12 |
huggingface-hub
|
13 |
spaces
|
|
|
|
11 |
peft==0.13.2
|
12 |
huggingface-hub
|
13 |
spaces
|
14 |
+
protobuf
|
test.png
DELETED
Binary file (337 kB)
|
|
tryoff.sh
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
python tryoff_inference.py \
|
2 |
+
--image ./example/person/00069_00.jpg \
|
3 |
+
--mask ./example/person/00069_00_mask.png \
|
4 |
+
--seed 41 \
|
5 |
+
--output_tryon test_original.png \
|
6 |
+
--output_garment restored_garment6.png \
|
7 |
+
--steps 30
|
tryoff_inference.py
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
import torch
|
3 |
+
from diffusers.utils import load_image, check_min_version
|
4 |
+
from diffusers import FluxPriorReduxPipeline, FluxFillPipeline
|
5 |
+
from diffusers import FluxTransformer2DModel
|
6 |
+
import numpy as np
|
7 |
+
from torchvision import transforms
|
8 |
+
|
9 |
+
def run_inference(
|
10 |
+
image_path,
|
11 |
+
mask_path,
|
12 |
+
size=(576, 768),
|
13 |
+
num_steps=50,
|
14 |
+
guidance_scale=30,
|
15 |
+
seed=42,
|
16 |
+
pipe=None
|
17 |
+
):
|
18 |
+
# Build pipeline
|
19 |
+
if pipe is None:
|
20 |
+
transformer = FluxTransformer2DModel.from_pretrained(
|
21 |
+
"xiaozaa/cat-tryoff-flux",
|
22 |
+
torch_dtype=torch.bfloat16
|
23 |
+
)
|
24 |
+
pipe = FluxFillPipeline.from_pretrained(
|
25 |
+
"black-forest-labs/FLUX.1-dev",
|
26 |
+
transformer=transformer,
|
27 |
+
torch_dtype=torch.bfloat16
|
28 |
+
).to("cuda")
|
29 |
+
else:
|
30 |
+
pipe.to("cuda")
|
31 |
+
|
32 |
+
pipe.transformer.to(torch.bfloat16)
|
33 |
+
|
34 |
+
# Add transform
|
35 |
+
transform = transforms.Compose([
|
36 |
+
transforms.ToTensor(),
|
37 |
+
transforms.Normalize([0.5], [0.5]) # For RGB images
|
38 |
+
])
|
39 |
+
mask_transform = transforms.Compose([
|
40 |
+
transforms.ToTensor()
|
41 |
+
])
|
42 |
+
|
43 |
+
# Load and process images
|
44 |
+
# print("image_path", image_path)
|
45 |
+
image = load_image(image_path).convert("RGB").resize(size)
|
46 |
+
mask = load_image(mask_path).convert("RGB").resize(size)
|
47 |
+
|
48 |
+
# Transform images using the new preprocessing
|
49 |
+
image_tensor = transform(image)
|
50 |
+
mask_tensor = mask_transform(mask)[:1] # Take only first channel
|
51 |
+
garment_tensor = torch.zeros_like(image_tensor)
|
52 |
+
image_tensor = image_tensor * mask_tensor
|
53 |
+
|
54 |
+
# Create concatenated images
|
55 |
+
inpaint_image = torch.cat([garment_tensor, image_tensor], dim=2) # Concatenate along width
|
56 |
+
garment_mask = torch.zeros_like(mask_tensor)
|
57 |
+
extended_mask = torch.cat([1 - garment_mask, garment_mask], dim=2)
|
58 |
+
|
59 |
+
prompt = f"The pair of images highlights a clothing and its styling on a model, high resolution, 4K, 8K; " \
|
60 |
+
f"[IMAGE1] Detailed product shot of a clothing" \
|
61 |
+
f"[IMAGE2] The same cloth is worn by a model in a lifestyle setting."
|
62 |
+
|
63 |
+
generator = torch.Generator(device="cuda").manual_seed(seed)
|
64 |
+
|
65 |
+
result = pipe(
|
66 |
+
height=size[1],
|
67 |
+
width=size[0] * 2,
|
68 |
+
image=inpaint_image,
|
69 |
+
mask_image=extended_mask,
|
70 |
+
num_inference_steps=num_steps,
|
71 |
+
generator=generator,
|
72 |
+
max_sequence_length=512,
|
73 |
+
guidance_scale=guidance_scale,
|
74 |
+
prompt=prompt,
|
75 |
+
).images[0]
|
76 |
+
|
77 |
+
# Split and save results
|
78 |
+
width = size[0]
|
79 |
+
garment_result = result.crop((0, 0, width, size[1]))
|
80 |
+
tryon_result = result.crop((width, 0, width * 2, size[1]))
|
81 |
+
|
82 |
+
return garment_result, tryon_result
|
83 |
+
|
84 |
+
def main():
|
85 |
+
parser = argparse.ArgumentParser(description='Run FLUX virtual try-on inference')
|
86 |
+
parser.add_argument('--image', required=True, help='Path to the model image')
|
87 |
+
parser.add_argument('--mask', required=True, help='Path to the agnostic mask')
|
88 |
+
parser.add_argument('--output_garment', default='flux_inpaint_garment.png', help='Output path for garment result')
|
89 |
+
parser.add_argument('--output_tryon', default='flux_inpaint_tryon.png', help='Output path for try-on result')
|
90 |
+
parser.add_argument('--steps', type=int, default=50, help='Number of inference steps')
|
91 |
+
parser.add_argument('--guidance_scale', type=float, default=30, help='Guidance scale')
|
92 |
+
parser.add_argument('--seed', type=int, default=0, help='Random seed')
|
93 |
+
parser.add_argument('--width', type=int, default=576, help='Width')
|
94 |
+
parser.add_argument('--height', type=int, default=768, help='Height')
|
95 |
+
|
96 |
+
args = parser.parse_args()
|
97 |
+
|
98 |
+
check_min_version("0.30.2")
|
99 |
+
|
100 |
+
garment_result, tryon_result = run_inference(
|
101 |
+
image_path=args.image,
|
102 |
+
mask_path=args.mask,
|
103 |
+
num_steps=args.steps,
|
104 |
+
guidance_scale=args.guidance_scale,
|
105 |
+
seed=args.seed,
|
106 |
+
size=(args.width, args.height)
|
107 |
+
)
|
108 |
+
output_tryon_path=args.output_tryon
|
109 |
+
output_garment_path=args.output_garment
|
110 |
+
|
111 |
+
tryon_result.save(output_tryon_path)
|
112 |
+
garment_result.save(output_garment_path)
|
113 |
+
|
114 |
+
print("Successfully saved garment and try-on images")
|
115 |
+
|
116 |
+
if __name__ == "__main__":
|
117 |
+
main()
|
tryon.sh
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
python tryon_inference.py \
|
2 |
+
--image ./example/person/00008_00.jpg \
|
3 |
+
--mask ./example/person/00008_00_mask.png \
|
4 |
+
--garment ./example/garment/00034_00.jpg \
|
5 |
+
--seed 42 \
|
6 |
+
--output_tryon test.png \
|
7 |
+
--steps 30
|