Home

Awesome

License: MIT Python 3.7 Language grade: Python

3D Magic Mirror: Clothing Reconstruction from a Single Image via a Causal Perspective

Cub BirdMarket-HQ Exchange

[Project] [Code] [Paper]

3D Magic Mirror: Clothing Reconstruction from a Single Image via a Causal Perspective, arXiv preprint arXiv:2204.13096, 2022.<br>Zhedong Zheng, Jiayin Zhu, Wei Ji, Yi Yang, Tat-Seng Chua

<meta name="og:image" content="https://github.com/layumi/3D-Magic-Mirror/blob/master/doc/current_rainbow_github.gif?raw=true">

Table of contents

News

Features

We have supported:

Prerequisites

If you use CUDA 10, please download the corresponding pytorch and kaolin 0.9 to match.

Getting Started

Installation

$ git clone https://github.com/layumi/3D-Magic-Mirror.git
$ cd 3D-Magic-Mirror/
$ conda create --name magic --file spec-file.txt
$ conda activate magic
$ pip install pytorch_msssim
$ 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++ 
$ git clone --recursive https://github.com/NVIDIAGameWorks/kaolin
$ git checkout v0.12.0
$ python setup.py develop

Our code is tested on PyTorch 1.9.0+ and torchvision 0.10.0+.

Dataset Preparation

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

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

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

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

Preparation:

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

Testing

Download the 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/
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.

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

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
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
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  

Illustrations.

Citation

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}
}

Related Work

We would like to thank to the great projects in SMR and UMR.

The person re-identification part is from Pytorch re-ID

License

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.