Cub Bird | Market-HQ Exchange |
---|---|
3D Magic Mirror: Clothing Reconstruction from a Single Image via a Causal Perspective, arXiv preprint arXiv:2204.13096, 2022.
Zhedong Zheng, Jiayin Zhu, Wei Ji, Yi Yang, Tat-Seng Chua
- We will release a new arXiv recently. We fix the stability problem. The results in paper are averaged with at least three runs.
We have supported:
- Train and test on 3 datasets: CUB, ATR, Market
- Generate all figures in the paper
- Linux
- Python >= 3.7
- CUDA >= 11 (with
nvcc
installed)
If you use CUDA 10, please download the corresponding pytorch and kaolin 0.9 to match.
- Clone this repo:
$ git clone https://github.com/layumi/3D-Magic-Mirror.git
$ cd 3D-Magic-Mirror/
- Install requirements
$ conda create --name magic --file spec-file.txt
$ conda activate magic
$ pip install pytorch_msssim
- gcc is needed by kaolin. If you have gcc about 7.3.0 - 9.5.0 (latest gcc may not work as well), please skip this step. (Update your gcc as follows if your gcc is too old (<=7.3) and you do not have sudo rights.)
$ conda config --add channels conda-forge # add conda forge channel
#$ conda install gcc_linux-64=9.4.0 gcc_impl_linux-64=9.4.0 gxx_linux-64=9.4.0 gxx_impl_linux-64=9.4.0 # I have included in spec-file.txt
$ ln x86_64-conda-linux-gnu-gcc gcc # cd your_anaconda/envs/magic/bin
$ ln x86_64-conda-linux-gnu-g++ g++
- install Kaolin Library (You need to mute/comment some warning like cython to install it.)
$ git clone --recursive https://github.com/NVIDIAGameWorks/kaolin
$ git checkout v0.12.0
$ python setup.py develop
- Others: tqdm, trimesh, imageio, etc.
Our code is tested on PyTorch 1.9.0+ and torchvision 0.10.0+.
Download tool:
$ pip install gdown
$ pip install --upgrade gdown #!!important!!
OR
Install gdrive for fast download the dataset from Google Driver. It is good for all command line users. (https://github.com/prasmussen/gdrive/releases/tag/2.1.1 )
wget https://github.com/prasmussen/gdrive/releases/download/2.1.1/gdrive_2.1.1_linux_386.tar.gz
tar -xzvf gdrive_2.1.1_linux_386.tar.gz
Download the dataset:
Download the processed data from Google Drive. Or use the gdrive tool to download:
gdown https://drive.google.com/uc?id=10gNi3n8Iny4O4MOZRs5dNFICfj8ri9eW
OR
gdrive download 10gNi3n8Iny4O4MOZRs5dNFICfj8ri9eW
- Market-Seg-HMR (We deploy smoothed HMR results as foreground marks. We found human parsing results are sensitive to input domain, such as illumination.)
Download the processed data from Google Drive. Or use the gdrive tool to download:
gdown https://drive.google.com/uc?id=1JwQTQA4F9WOqLAc7fhQN0DTYwnv6XrAR
OR
gdrive download 1JwQTQA4F9WOqLAc7fhQN0DTYwnv6XrAR
- CUB
Download the processed data from Google Drive. Or use the gdrive tool to download:
gdown https://drive.google.com/uc?id=1SkX_FWUfLOaTr371TBkQnDH9oDJ5Khwc
OR
gdrive download 1SkX_FWUfLOaTr371TBkQnDH9oDJ5Khwc
- ATR
Download the processed data from Google Drive. Or use the gdrive tool to download:
gdown https://drive.google.com/uc?id=1kpsMDrbM4FQqtP7Y1nKslp4OlRKNvbaL
OR
gdrive download 1kpsMDrbM4FQqtP7Y1nKslp4OlRKNvbaL
Before prepare, the folder is like:
├── 3D-Magic-Mirror/
| |-- data/
| |-- CUB_Data/
├── kaolin/
├── Market/
│ ├── hq/
| |-- seg_hmr/
|-- ATR/
| |-- humanparsing/
Only Market dataset requires preparation, and other datasets are ready to run after download.
This code will calculate the ratio of foreground against background.
During training, we will drop few wrong masks or ill-detected person.
Note to modify the dataset path to your own path.
python prepare_market.py
python prepare_ATR.py
python prepare_cub.py
- Trained model
You may download it from GoogleDrive-Market, GoogleDrive-CUB and move it to the log
.
Or directly use the following code:
gdown 1-eqnnFt3D7-jUelJ5uj_4QcFv-TMok8c #Market model
gdown 1urxUeaULn2DNM-4XAcZ2_OmtGJuCSeYO #CUB model
├── log/
│ ├── CamN2_MKT_wgan_b48_lr0.5_em7_update-1_lpl_reg0.1_data2_m2_flat20_depthR0.15_drop220_gap2_beta0.95_clean67/
| |-- ckpts/
│ ├──CUB_wgan_b48_ic1_hard_bg_L1_ganW0_lr0.7_em7_update-1_chf_lpl_reg0.1_data2_depthC0.1_flat10_drop220_gap2_beta0.95_bn_restart1_contour0.1/
| |-- ckpts/
- Visualization
python show_rainbow2.py --name CamN2_MKT_wgan_b48_lr0.5_em7_update-1_lpl_reg0.1_data2_m2_flat20_depthR0.15_drop220_gap2_beta0.95_clean67
It will generate the five gif animations in the log/your_model_name/
.
(We manually select some hard index to show the result.)
current_rainbow.gif
: Swapping appearnce.
current_rotation.gif
: Rotation via azumith.
current_rotation_ele.gif
: Rotation via elevation.
current_rotation_dist.gif
: Change distance to the camera.
current_rotation_XY.gif
: Shift the camera in X-axis and Y-axis.
- Test Flops, maskIoU and SSIM
python test.py --name CamN2_MKT_wgan_b48_lr0.5_em7_update-1_lpl_reg0.1_data2_m2_flat20_depthR0.15_drop220_gap2_beta0.95_clean67
or
python test.py --name ATR2_wgan_b48_ganW0_lr0.55_em7_update-1_chf_lpl_reg0.1_m2_recon2_flat10_depthR0.15_data2_drop222_gap2_beta0.95_s96_clean1826
or
python test.py --name CUB_wgan_b48_ic1_hard_bg_L1_ganW0_lr0.7_em7_update-1_chf_lpl_reg0.1_data2_depthC0.1_flat10_drop220_gap2_beta0.95_bn_restart1_contour0.1
Please make sure the dataset name in your model. We use model name to set the test dataset.
- Training on Market (64*128)
python train_market.py --name CamN2_MKT_wgan_b48_lr0.5_em7_update-1_lpl_reg0.1_data2_m2_flat20_depthR0.15_drop220_gap2_beta0.95_clean67 --clean 0.36,0.49 --imageSize 64 --batch 48 --gan_type wgan --bg --L1 --ganw 0 --hard --lr 5e-5 --em 7 --update_shape -1 --lambda_data 2 --unmask 2 --lambda_flat 0.02 --lambda_depthR 0.15 --drop 0.2,0.2,0 --em_gap 2 --beta1 0.95 --pretrainc none
- Training on CUB (128*128)
python train.py --name CUB_wgan_b48_ic1_hard_bg_L1_ganW0_lr0.7_em7_update-1_chf_lpl_reg0.1_data2_depthC0.1_flat10_drop220_gap2_beta0.95_bn_restart1_contour0.1 --drop 0.2,0.2,0 --imageSize 128 --batch 48 --gan_type wgan --bg --L1 --ganw 0 --hard --lr 7e-5 --em 7 --update_shape -1 --lambda_data 2 --lambda_depthC 0.1 --lambda_flat 0.01 --unmask 2 --em_gap 2 --beta1 0.95 --update_bn --gamma 0.1 --scheduler restart1 --lambda_contour 0.1
- Training on ATR (96*160) We suggest to run this dataset on A100 or A5000, instead of P5000 or R5000. The result is more stable on A series GPUs. It may be due to the float accuracy.
python train_ATR2.py --name ATR2_wgan_b48_ganW0_lr0.55_em7_update-1_chf_lpl_reg0.1_m2_recon2_flat10_depthR0.15_data2_drop222_gap2_beta0.95_s96_clean1826 --imageSize 96 --batch 48 --gan_type wgan --bg --L1 --ganw 0 --hard --lr 5.5e-5 --em 7 --update_shape -1 --unmask 2 --lambda_data 2 --lambda_flat 0.01 --lambda_depthR 0.15 --drop 0.2,0.2,0.2 --em_gap 2 --beta1 0.95 --ratio 1.666666 --clean 0.18,0.26 --pretrainc none
-
em
is for the accumulated template update. If we set smooth=6, the movement will be the neighbor move. If we set smooth=7, the movement will be the smooth over neighbors again. by default 7 -
clip
is to truncate the movement. by default 0.05 -
em_step
is the initial moving speed, which is decay by 0.99 during training. by default 0.1
Please cite this paper if it helps your research:
@article{zheng2022magic,
title={3D Magic Mirror: Clothing Reconstruction from a Single Image via a Causal Perspective},
author={Zheng, Zhedong and Zhu, Jiayin and Ji, Wei and Yang, Yi and Chua, Tat-Seng},
journal={arXiv preprint arXiv:2204.13096},
year={2022}
}
We would like to thank to the great projects in SMR and UMR.
The person re-identification part is from Pytorch re-ID
Copyright (C) 2022 NExT++ Lab. All rights reserved. Licensed under the MIT. The code is released for academic research use only. For commercial use, please contact zdzheng@nus.edu.sg.