Skip to content

Commit 8551b3c

Browse files
[Feature] Support Style-Based Global Appearance Flow for Virtual Try-On (open-mmlab#1786)
* first commit * [Fix] fix bugs * [Enhancemnt] update README * Update README.md * [Fix] Fix lint * fix lint and update in dev branch * [Fix] Fix image display in README.md * [Fix] delete unused figures * Delete mmedit directory * update import init_model from mmagic and fix registry error --------- Co-authored-by: LeoXing1996 <[email protected]>
1 parent 031576d commit 8551b3c

File tree

12 files changed

+3424
-0
lines changed

12 files changed

+3424
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,7 @@ resources/
147147
# Slurm
148148
batchscript-*
149149
*.out
150+
151+
*.png
152+
*.jpg
153+
*.zip

projects/flow_style_vton/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.jpg
2+
*.zip

projects/flow_style_vton/README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Style-Based Global Appearance Flow for Virtual Try-On (CVPR 2022)
2+
3+
## Description
4+
5+
Awesome try-on desplays are like this:
6+
7+
![image1](examples/000010_0.png)
8+
9+
```
10+
Author: @FerryHuang.
11+
12+
This is an implementation of https://github.com/SenHe/Flow-Style-VTON adapting to mmediting. Only inference is supported so far.
13+
```
14+
15+
## Usage
16+
17+
### Setup Environment
18+
19+
Please refer to [Get Started](https://mmediting.readthedocs.io/en/latest/get_started/I.html) to install
20+
MMEditing.
21+
22+
At first, add the current folder to `PYTHONPATH`, so that Python can find your code. Run command in the current directory to add it.
23+
24+
> Please run it every time after you opened a new shell.
25+
26+
```shell
27+
export PYTHONPATH=`pwd`:$PYTHONPATH
28+
```
29+
30+
### Data Preparation
31+
32+
Please check the [official repo](https://github.com/SenHe/Flow-Style-VTON) and download test-set and pretrained checkpoints and put them under the folder projects/flow_style_vton
33+
34+
### Testing commands
35+
36+
**To test with single GPU:**
37+
38+
```bash
39+
cd projects/flow_style_vton
40+
python inference.py
41+
```
42+
43+
Expectedly, two folders will be made im_gar_flow_wg and our_t_results, containing the
44+
try-on procedures and the final results, respectively.
45+
46+
## Citation
47+
48+
<!-- Replace to the citation of the paper your project refers to. -->
49+
50+
```bibtex
51+
@inproceedings{he2022fs_vton,
52+
title={Style-Based Global Appearance Flow for Virtual Try-On},
53+
author={He, Sen and Song, Yi-Zhe and Xiang, Tao},
54+
booktitle={CVPR},
55+
year={2022}
56+
}
57+
```
58+
59+
## Checklist \[required\]
60+
61+
Here is a checklist of this project's progress. And you can ignore this part if you don't plan to contribute
62+
to MMediting projects.
63+
64+
- [ ] Milestone 1: PR-ready, and acceptable to be one of the `projects/`.
65+
66+
- [ ] Finish the code
67+
68+
<!-- The code's design shall follow existing interfaces and convention. For example, each model component should be registered into `mmedit.registry.MODELS` and configurable via a config file. -->
69+
70+
- [ ] Basic docstrings & proper citation
71+
72+
<!-- Each major class should contains a docstring, describing its functionality and arguments. If your code is copied or modified from other open-source projects, don't forget to cite the source project in docstring and make sure your behavior is not against its license. Typically, we do not accept any code snippet under GPL license. [A Short Guide to Open Source Licenses](https://medium.com/nationwide-technology/a-short-guide-to-open-source-licenses-cf5b1c329edd) -->
73+
74+
- [ ] Converted checkpoint and results (Only for reproduction)
75+
76+
<!-- If you are reproducing the result from a paper, make sure the model in the project can match that results. Also please provide checkpoint links or a checkpoint conversion script for others to get the pre-trained model. -->
77+
78+
- [ ] Milestone 2: Indicates a successful model implementation.
79+
80+
- [ ] Training results
81+
82+
<!-- If you are reproducing the result from a paper, train your model from scratch and verified that the final result can match the original result. -->
83+
84+
- [ ] Milestone 3: Good to be a part of our core package!
85+
86+
- [ ] Unit tests
87+
88+
<!-- Unit tests for the major module are required. [Example](https://github.com/open-mmlab/mmediting/blob/main/tests/test_models/test_backbones/test_vision_transformer.py) -->
89+
90+
- [ ] Code style
91+
92+
<!-- Refactor your code according to reviewer's comment. -->
93+
94+
- [ ] `metafile.yml` and `README.md`
95+
96+
<!-- It will used for mmediting to acquire your models. [Example](https://github.com/open-mmlab/mmediting/blob/main/configs/mvit/metafile.yml). In particular, you may have to refactor this README into a standard one. [Example](https://github.com/open-mmlab/mmediting/blob/main/configs/swin_transformer/README.md) -->
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
model = dict(
2+
type='FlowStyleVTON',
3+
warp_model=dict(type='AFWM', input_nc=3),
4+
gen_model=dict(
5+
type='ResUnetGenerator', input_nc=7, output_nc=4, num_downs=5),
6+
pretrained_cfgs=dict(
7+
warp_model=dict(ckpt_path='ckp/aug/PFAFN_warp_epoch_101.pth'),
8+
gen_model=dict(ckpt_path='ckp/aug/PFAFN_gen_epoch_101.pth')))
21.6 KB
Loading

projects/flow_style_vton/inference.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import os
2+
from argparse import ArgumentParser
3+
4+
import torch
5+
from mmengine.registry import init_default_scope
6+
from torch.utils.data import DataLoader
7+
from torchvision.utils import save_image
8+
from tqdm import tqdm
9+
from vton_dataset import AlignedDataset
10+
11+
from mmagic.apis.inferencers.inference_functions import init_model
12+
from projects.flow_style_vton.models import FlowStyleVTON
13+
14+
init_default_scope('mmedit')
15+
16+
config = 'configs/flow_style_vton_PFAFN_epoch_101.py'
17+
18+
parser = ArgumentParser()
19+
parser.add_argument('--gpu_id', type=int, default=0)
20+
parser.add_argument(
21+
'--loadSize', type=int, default=512, help='scale images to this size')
22+
parser.add_argument(
23+
'--fineSize', type=int, default=512, help='then crop to this size')
24+
parser.add_argument('--dataroot', type=str, default='VITON_test')
25+
parser.add_argument('--test_pairs', type=str, default='test_pairs.txt')
26+
parser.add_argument(
27+
'--resize_or_crop',
28+
type=str,
29+
default='scale_width',
30+
help='scaling and cropping of images at load time \
31+
[resize_and_crop|crop|scale_width|scale_width_and_crop]')
32+
parser.add_argument('--phase', type=str, default='test')
33+
parser.add_argument('--isTrain', default=False)
34+
parser.add_argument(
35+
'--no_flip',
36+
action='store_true',
37+
help='if specified, do not flip the images for data argumentation')
38+
parser.add_argument('--batch_size', type=int, default=1)
39+
parser.add_argument('--num_workers', type=int, default=4)
40+
41+
parser.add_argument('--output_dir', type=str, default='inference_results')
42+
opt = parser.parse_args()
43+
44+
dataset = AlignedDataset(opt)
45+
dataloader = DataLoader(dataset, opt.batch_size, num_workers=opt.num_workers)
46+
47+
device = torch.device(
48+
f'cuda:{opt.gpu_id}' if torch.cuda.is_available() else 'cpu')
49+
# pretrained is set inside the config
50+
model = init_model(config).to(device).eval()
51+
assert isinstance(model, FlowStyleVTON)
52+
53+
os.makedirs('our_t_results', exist_ok=True)
54+
os.makedirs('im_gar_flow_wg', exist_ok=True)
55+
for i, data in enumerate(tqdm(dataloader)):
56+
p_tryon, combine = model.infer(data)
57+
save_image(
58+
p_tryon,
59+
os.path.join('our_t_results', data['p_name'][0]),
60+
nrow=int(1),
61+
normalize=True,
62+
value_range=(-1, 1))
63+
save_image(
64+
combine,
65+
os.path.join('im_gar_flow_wg', data['p_name'][0]),
66+
nrow=int(1),
67+
normalize=True,
68+
range=(-1, 1),
69+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .afwm import AFWM
2+
from .flow_style_vton_model import FlowStyleVTON
3+
from .generator import ResUnetGenerator
4+
5+
__all__ = ['FlowStyleVTON', 'AFWM', 'ResUnetGenerator']

0 commit comments

Comments
 (0)