ICON / app.py
Yuliang's picture
change pytorch verision to avoid OOM error
a3f1f2c
raw
history blame
5.16 kB
# install
import glob
import gradio as gr
import os, random
import subprocess
if os.getenv('SYSTEM') == 'spaces':
subprocess.run('pip install pyembree'.split())
subprocess.run('pip install rembg'.split())
subprocess.run(
'pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html'.split())
subprocess.run(
'pip install git+https://github.com/YuliangXiu/kaolin.git'.split())
subprocess.run('pip install --no-index --no-cache-dir pytorch3d -f https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/py38_cu113_pyt1110/download.html'.split())
subprocess.run(
'pip install git+https://github.com/Project-Splinter/human_det.git'.split())
subprocess.run(
'pip install git+https://github.com/YuliangXiu/neural_voxelization_layer.git'.split())
from apps.infer import generate_model
# running
description = '''
# ICON Clothed Human Digitization
### ICON: Implicit Clothed humans Obtained from Normals (CVPR 2022)
<table style="width:26%; padding:0; margin:0;">
<tr>
<th><iframe src="https://ghbtns.com/github-btn.html?user=yuliangxiu&repo=ICON&type=star&count=true&v=2&size=small" frameborder="0" scrolling="0" width="100" height="20"></iframe></th>
<th><img alt="Twitter Follow" src="https://img.shields.io/twitter/follow/yuliangxiu?style=social"></th>
<th><img alt="YouTube Video Views" src="https://img.shields.io/youtube/views/hZd6AYin2DE?style=social"></th>
</tr>
</table>
#### Acknowledgments:
- [StyleGAN-Human, ECCV 2022](https://stylegan-human.github.io/)
- [nagolinc/styleGanHuman_and_PIFu](https://huggingface.co/spaces/nagolinc/styleGanHuman_and_PIFu)
- [radames/PIFu-Clothed-Human-Digitization](https://huggingface.co/spaces/radames/PIFu-Clothed-Human-Digitization)
#### The reconstruction + refinement + video take about 80 seconds for single image.
<details>
<summary>More</summary>
#### Image Credits
* [Pinterest](https://www.pinterest.com/search/pins/?q=parkour&rs=sitelinks_searchbox)
* [Qianli Ma](https://qianlim.github.io/)
#### Related works
* [ICON @ MPI](https://icon.is.tue.mpg.de/)
* [MonoPort @ USC](https://xiuyuliang.cn/monoport)
* [Phorhum @ Google](https://phorhum.github.io/)
* [PIFuHD @ Meta](https://shunsukesaito.github.io/PIFuHD/)
* [PaMIR @ Tsinghua](http://www.liuyebin.com/pamir/pamir.html)
</details>
'''
def generate_image(seed, psi):
iface = gr.Interface.load("spaces/hysts/StyleGAN-Human")
img = iface(seed, psi)
return img
random.seed(1993)
model_types = ['icon-filter', 'pifu', 'pamir']
examples = [[item, random.choice(model_types)] for item in random.sample(sorted(glob.glob('examples/*.png')), 4)]
with gr.Blocks() as demo:
gr.Markdown(description)
out_lst = []
with gr.Row():
with gr.Column():
with gr.Row():
with gr.Column():
seed = gr.inputs.Slider(
0, 100, step=1, default=0, label='Seed (For Image Generation)')
psi = gr.inputs.Slider(
0, 2, step=0.05, default=0.7, label='Truncation psi (For Image Generation)')
radio_choice = gr.Radio(model_types, label='Method (For Reconstruction)', value='icon-filter')
inp = gr.Image(type="filepath", label="Input Image")
with gr.Row():
btn_sample = gr.Button("Sample Image")
btn_submit = gr.Button("Submit Image")
gr.Examples(examples=examples,
inputs=[inp, radio_choice],
cache_examples=True,
fn=generate_model,
outputs=out_lst)
out_vid_download = gr.File(label="Download Video, welcome share on Twitter with #ICON")
with gr.Column():
overlap_inp = gr.Image(type="filepath", label="Image Normal Overlap")
out_smpl = gr.Model3D(
clear_color=[0.0, 0.0, 0.0, 0.0], label="SMPL")
out_smpl_download = gr.File(label="Download SMPL mesh")
out_smpl_npy_download = gr.File(label="Download SMPL params")
out_recon = gr.Model3D(
clear_color=[0.0, 0.0, 0.0, 0.0], label="ICON")
out_recon_download = gr.File(label="Download clothed human mesh")
out_final = gr.Model3D(
clear_color=[0.0, 0.0, 0.0, 0.0], label="ICON++")
out_final_download = gr.File(label="Download refined clothed human mesh")
out_lst = [out_smpl, out_smpl_download, out_smpl_npy_download, out_recon, out_recon_download,
out_final, out_final_download, out_vid_download, overlap_inp]
btn_submit.click(fn=generate_model, inputs=[inp, radio_choice], outputs=out_lst)
btn_sample.click(fn=generate_image, inputs=[seed, psi], outputs=inp)
if __name__ == "__main__":
# demo.launch(debug=False, enable_queue=False,
# auth=(os.environ['USER'], os.environ['PASSWORD']),
# auth_message="Register at icon.is.tue.mpg.de to get HuggingFace username and password.")
demo.launch(debug=True, enable_queue=True)