Spaces:
Sleeping
Sleeping
20240706
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitignore +57 -0
- app.py +394 -0
- assets/sample_input/demo/back/armor.png +0 -0
- assets/sample_input/demo/back/bird.png +0 -0
- assets/sample_input/demo/back/bird_brownblue.png +0 -0
- assets/sample_input/demo/back/bird_rainbow.png +0 -0
- assets/sample_input/demo/back/bird_whitered.png +0 -0
- assets/sample_input/demo/back/boy_astronaut.png +0 -0
- assets/sample_input/demo/back/boy_blue.png +0 -0
- assets/sample_input/demo/back/boy_chinese_style.png +0 -0
- assets/sample_input/demo/back/boy_grey_clothes.png +0 -0
- assets/sample_input/demo/back/house.png +0 -0
- assets/sample_input/demo/back/kunkun_law.png +0 -0
- assets/sample_input/demo/back/lego_astronaut.png +0 -0
- assets/sample_input/demo/back/lego_green.png +0 -0
- assets/sample_input/demo/back/lego_red.png +0 -0
- assets/sample_input/demo/back/lego_wizard.png +0 -0
- assets/sample_input/demo/back/loopy.png +0 -0
- assets/sample_input/demo/back/mario.png +0 -0
- assets/sample_input/demo/back/marvel_captain.png +0 -0
- assets/sample_input/demo/back/marvel_ironman.png +0 -0
- assets/sample_input/demo/back/marvel_spiderman.png +0 -0
- assets/sample_input/demo/back/marvel_superman.png +0 -0
- assets/sample_input/demo/back/penguin.png +0 -0
- assets/sample_input/demo/back/sofa.png +0 -0
- assets/sample_input/demo/front/armor.png +0 -0
- assets/sample_input/demo/front/bird.png +0 -0
- assets/sample_input/demo/front/bird_brownblue.png +0 -0
- assets/sample_input/demo/front/bird_rainbow.png +0 -0
- assets/sample_input/demo/front/bird_whitered.png +0 -0
- assets/sample_input/demo/front/boy_astronaut.png +0 -0
- assets/sample_input/demo/front/boy_blue.png +0 -0
- assets/sample_input/demo/front/boy_chinese_style.png +0 -0
- assets/sample_input/demo/front/boy_grey_clothes.png +0 -0
- assets/sample_input/demo/front/house.png +0 -0
- assets/sample_input/demo/front/kunkun_law.png +0 -0
- assets/sample_input/demo/front/lego_astronaut.png +0 -0
- assets/sample_input/demo/front/lego_green.png +0 -0
- assets/sample_input/demo/front/lego_red.png +0 -0
- assets/sample_input/demo/front/lego_wizard.png +0 -0
- assets/sample_input/demo/front/loopy.png +0 -0
- assets/sample_input/demo/front/mario.png +0 -0
- assets/sample_input/demo/front/marvel_captain.png +0 -0
- assets/sample_input/demo/front/marvel_ironman.png +0 -0
- assets/sample_input/demo/front/marvel_spiderman.png +0 -0
- assets/sample_input/demo/front/marvel_superman.png +0 -0
- assets/sample_input/demo/front/penguin.png +0 -0
- assets/sample_input/demo/front/sofa.png +0 -0
- configs/accelerate-train-4gpus.yaml +17 -0
- configs/accelerate-train.yaml +17 -0
.gitignore
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Ignore Python cache files
|
2 |
+
**/__pycache__
|
3 |
+
|
4 |
+
# Ignore compiled Python files
|
5 |
+
*.pyc
|
6 |
+
|
7 |
+
# Ignore editor-specific files
|
8 |
+
.vscode/
|
9 |
+
.idea/
|
10 |
+
|
11 |
+
# Ignore operating system files
|
12 |
+
.DS_Store
|
13 |
+
Thumbs.db
|
14 |
+
|
15 |
+
# Ignore log files
|
16 |
+
*.log
|
17 |
+
|
18 |
+
# Ignore temporary and cache files
|
19 |
+
*.tmp
|
20 |
+
*.cache
|
21 |
+
|
22 |
+
# Ignore build artifacts
|
23 |
+
/build/
|
24 |
+
/dist/
|
25 |
+
|
26 |
+
# Ignore virtual environment files
|
27 |
+
/venv/
|
28 |
+
/.venv/
|
29 |
+
|
30 |
+
# Ignore package manager files
|
31 |
+
/node_modules/
|
32 |
+
/yarn.lock
|
33 |
+
/package-lock.json
|
34 |
+
|
35 |
+
# Ignore database files
|
36 |
+
*.db
|
37 |
+
*.sqlite
|
38 |
+
|
39 |
+
# Ignore secret files
|
40 |
+
*.secret
|
41 |
+
|
42 |
+
# Ignore compiled binaries
|
43 |
+
*.exe
|
44 |
+
*.dll
|
45 |
+
*.so
|
46 |
+
*.dylib
|
47 |
+
|
48 |
+
# Ignore backup files
|
49 |
+
*.bak
|
50 |
+
*.swp
|
51 |
+
*.swo
|
52 |
+
*.~*
|
53 |
+
|
54 |
+
|
55 |
+
# Ignore exp result files
|
56 |
+
dumps/
|
57 |
+
exps/
|
app.py
ADDED
@@ -0,0 +1,394 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (c) 2023-2024, Zexin He
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
|
15 |
+
|
16 |
+
import os
|
17 |
+
from PIL import Image
|
18 |
+
import numpy as np
|
19 |
+
import gradio as gr
|
20 |
+
|
21 |
+
|
22 |
+
def assert_input_image(input_front_image, input_back_image):
|
23 |
+
if input_front_image is None:
|
24 |
+
raise gr.Error("No front image selected or uploaded!")
|
25 |
+
if input_back_image is None:
|
26 |
+
raise gr.Error("No back image selected or uploaded!")
|
27 |
+
|
28 |
+
def prepare_working_dir():
|
29 |
+
import tempfile
|
30 |
+
working_dir = tempfile.TemporaryDirectory()
|
31 |
+
return working_dir
|
32 |
+
|
33 |
+
def init_preprocessor():
|
34 |
+
from openlrm.utils.preprocess import Preprocessor
|
35 |
+
global preprocessor
|
36 |
+
preprocessor = Preprocessor()
|
37 |
+
|
38 |
+
def preprocess_fn(image_in_front: np.ndarray, image_in_back: np.ndarray, remove_bg: bool, recenter: bool, working_dir):
|
39 |
+
# save front image first
|
40 |
+
image_raw_front = os.path.join(working_dir.name, "raw_front.png")
|
41 |
+
with Image.fromarray(image_in_front) as img:
|
42 |
+
img.save(image_raw_front)
|
43 |
+
image_out_front = os.path.join(working_dir.name, "front/rembg_front.png")
|
44 |
+
|
45 |
+
# save back image first
|
46 |
+
image_raw_back = os.path.join(working_dir.name, "raw_back.png")
|
47 |
+
with Image.fromarray(image_in_back) as img:
|
48 |
+
img.save(image_raw_back)
|
49 |
+
image_out_back = os.path.join(working_dir.name, "back/rembg_back.png")
|
50 |
+
|
51 |
+
# process the front and back image.
|
52 |
+
success_front = preprocessor.preprocess(image_path=image_raw_front, save_path=image_out_front, rmbg=remove_bg, recenter=recenter)
|
53 |
+
success_back = preprocessor.preprocess(image_path=image_raw_back, save_path=image_out_back, rmbg=remove_bg, recenter=recenter)
|
54 |
+
assert success_front and success_back, f"Failed under preprocess_fn!"
|
55 |
+
return image_out_front, image_out_back
|
56 |
+
|
57 |
+
|
58 |
+
def demo_openlrm(infer_impl):
|
59 |
+
|
60 |
+
def core_fn(image_front: str, image_back: str, source_cam_dist: float, working_dir):
|
61 |
+
dump_video_path = os.path.join(working_dir.name, "output.mp4")
|
62 |
+
dump_mesh_path = os.path.join(working_dir.name, "output.ply")
|
63 |
+
infer_impl(
|
64 |
+
image_path=image_front,
|
65 |
+
source_cam_dist=source_cam_dist,
|
66 |
+
export_video=True,
|
67 |
+
export_mesh=False,
|
68 |
+
dump_video_path=dump_video_path,
|
69 |
+
dump_mesh_path=dump_mesh_path,
|
70 |
+
image_path_back=image_back,
|
71 |
+
)
|
72 |
+
return dump_video_path
|
73 |
+
|
74 |
+
def example_fn(input_front_image: np.ndarray, input_back_image: np.ndarray):
|
75 |
+
from gradio.utils import get_cache_folder
|
76 |
+
working_dir = get_cache_folder()
|
77 |
+
processed_front_image, processed_back_image = preprocess_fn(
|
78 |
+
image_in_front=input_front_image,
|
79 |
+
image_in_back=input_back_image,
|
80 |
+
remove_bg=True,
|
81 |
+
recenter=True,
|
82 |
+
working_dir=working_dir,
|
83 |
+
)
|
84 |
+
video = core_fn(
|
85 |
+
image_front=processed_front_image,
|
86 |
+
image_back=processed_back_image,
|
87 |
+
source_cam_dist=2.0,
|
88 |
+
working_dir=working_dir,
|
89 |
+
)
|
90 |
+
return processed_front_image, processed_back_image, video
|
91 |
+
|
92 |
+
_TITLE = '''🔥 🔥 🔥 Tailor3D: Customized 3D Assets Editing and Generation with Dual-Side Images'''
|
93 |
+
|
94 |
+
_DESCRIPTION = '''
|
95 |
+
<div>
|
96 |
+
<a style="display:inline-block" href='https://github.com/Qi-Zhangyang/Tailor3D'><img src='https://img.shields.io/github/stars/Qi-Zhangyang/Tailor3D?style=social'/></a>
|
97 |
+
<a style="display:inline-block; margin-left: .5em" href="https://huggingface.co/alexzyqi"><img src='https://img.shields.io/badge/Model-Weights-blue'/></a>
|
98 |
+
</div>
|
99 |
+
We propose Tailor3D, a novel pipeline creating customized 3D assets from editable dual-side images and feed-forward reconstruction methods.
|
100 |
+
|
101 |
+
Here we show the final step of Tailor3D. That is given the edited front and beck view of the object. We can produce the 3D object with several seconds.
|
102 |
+
|
103 |
+
<strong>Disclaimer:</strong> This demo uses `Tailor3D-base-1.1` model with 288x288 rendering resolution here for a quick demonstration.
|
104 |
+
'''
|
105 |
+
|
106 |
+
with gr.Blocks(analytics_enabled=False) as demo:
|
107 |
+
|
108 |
+
# HEADERS
|
109 |
+
with gr.Row():
|
110 |
+
with gr.Column(scale=1):
|
111 |
+
gr.Markdown('# ' + _TITLE)
|
112 |
+
with gr.Row():
|
113 |
+
gr.Markdown(_DESCRIPTION)
|
114 |
+
|
115 |
+
# DISPLAY
|
116 |
+
with gr.Row():
|
117 |
+
gr.Markdown(
|
118 |
+
"""
|
119 |
+
## 🖼️ Input: This is the input front and back images.
|
120 |
+
"""
|
121 |
+
)
|
122 |
+
with gr.Row():
|
123 |
+
with gr.Column(variant='panel', scale=0.2):
|
124 |
+
with gr.Tabs(elem_id="tailor3d_input_front_image"):
|
125 |
+
with gr.TabItem('Input Front-view Image'):
|
126 |
+
with gr.Row():
|
127 |
+
input_front_image = gr.Image(label="Input Front Image", image_mode="RGBA", width="auto", sources="upload", type="numpy", elem_id="content_image")
|
128 |
+
|
129 |
+
with gr.Column(variant='panel', scale=0.2):
|
130 |
+
with gr.Tabs(elem_id="tailor3d_input_back_image"):
|
131 |
+
with gr.TabItem('Input Back-view Image'):
|
132 |
+
with gr.Row():
|
133 |
+
input_back_image = gr.Image(label="Input Back Image", image_mode="RGBA", width="auto", sources="upload", type="numpy", elem_id="content_image")
|
134 |
+
with gr.Row():
|
135 |
+
gr.Markdown(
|
136 |
+
"""
|
137 |
+
## 🛠️ Preprocess: Remove the background and center the object.
|
138 |
+
"""
|
139 |
+
)
|
140 |
+
with gr.Row():
|
141 |
+
with gr.Column(variant='panel', scale=0.2):
|
142 |
+
with gr.Tabs(elem_id="tailor3d_processed_image"):
|
143 |
+
with gr.TabItem('Processed Front-view Image'):
|
144 |
+
with gr.Row():
|
145 |
+
processed_front_image = gr.Image(label="Processed Image", image_mode="RGBA", type="filepath", elem_id="processed_image", width="auto", interactive=False)
|
146 |
+
with gr.Column(variant='panel', scale=0.2):
|
147 |
+
with gr.Tabs(elem_id="tailor3d_processed_image"):
|
148 |
+
with gr.TabItem('Processed Back-view Image'):
|
149 |
+
with gr.Row():
|
150 |
+
processed_back_image = gr.Image(label="Processed Image", image_mode="RGBA", type="filepath", elem_id="processed_image", width="auto", interactive=False)
|
151 |
+
with gr.Row():
|
152 |
+
gr.Markdown(
|
153 |
+
"""
|
154 |
+
## 🚀 Output: The rendering video of the 3D object.
|
155 |
+
Note that the output is the 3D mesh, for convience, we showcase it through a video that circles around.
|
156 |
+
"""
|
157 |
+
)
|
158 |
+
with gr.Row():
|
159 |
+
with gr.Column(variant='panel', scale=0.2):
|
160 |
+
with gr.Tabs(elem_id="tailor3d_render_video"):
|
161 |
+
with gr.TabItem('Rendered Video'):
|
162 |
+
with gr.Row():
|
163 |
+
output_video = gr.Video(label="Rendered Video", format="mp4", width="auto", autoplay=True)
|
164 |
+
|
165 |
+
# SETTING
|
166 |
+
with gr.Row():
|
167 |
+
with gr.Column(variant='panel', scale=1):
|
168 |
+
with gr.Tabs(elem_id="openlrm_attrs"):
|
169 |
+
with gr.TabItem('Settings'):
|
170 |
+
with gr.Column(variant='panel'):
|
171 |
+
gr.Markdown(
|
172 |
+
"""
|
173 |
+
<strong>Best Practice</strong>:
|
174 |
+
Centered objects in reasonable sizes. Try adjusting source camera distances.
|
175 |
+
"""
|
176 |
+
)
|
177 |
+
checkbox_rembg = gr.Checkbox(True, label='Remove background')
|
178 |
+
checkbox_recenter = gr.Checkbox(True, label='Recenter the object')
|
179 |
+
slider_cam_dist = gr.Slider(1.0, 3.5, value=2.0, step=0.1, label="Source Camera Distance")
|
180 |
+
submit = gr.Button('Generate', elem_id="openlrm_generate", variant='primary')
|
181 |
+
|
182 |
+
# EXAMPLES
|
183 |
+
with gr.Row():
|
184 |
+
gr.Markdown(
|
185 |
+
"""
|
186 |
+
## Example in the paper.
|
187 |
+
### A. 3D Style Transfer
|
188 |
+
Here we keep the object ID and just transfer the style. <br>
|
189 |
+
|
190 |
+
**Line 1: A pop-mart boy with astronaut, blue, traditional Chinese and grey style.**
|
191 |
+
"""
|
192 |
+
)
|
193 |
+
with gr.Row():
|
194 |
+
examples = [
|
195 |
+
['assets/sample_input/demo/front/boy_astronaut.png', 'assets/sample_input/demo/back/boy_astronaut.png'],
|
196 |
+
['assets/sample_input/demo/front/boy_blue.png', 'assets/sample_input/demo/back/boy_blue.png'],
|
197 |
+
['assets/sample_input/demo/front/boy_chinese_style.png', 'assets/sample_input/demo/back/boy_chinese_style.png'],
|
198 |
+
['assets/sample_input/demo/front/boy_grey_clothes.png', 'assets/sample_input/demo/back/boy_grey_clothes.png'],
|
199 |
+
]
|
200 |
+
|
201 |
+
for example in examples:
|
202 |
+
with gr.Column(scale=1):
|
203 |
+
gr.Examples(
|
204 |
+
examples=[example],
|
205 |
+
inputs=[input_front_image, input_back_image],
|
206 |
+
outputs=[processed_front_image, processed_back_image, output_video],
|
207 |
+
fn=example_fn,
|
208 |
+
cache_examples=bool(os.getenv('SPACE_ID')),
|
209 |
+
examples_per_page=3,
|
210 |
+
)
|
211 |
+
|
212 |
+
# # EXAMPLES
|
213 |
+
# with gr.Row():
|
214 |
+
# gr.Markdown(
|
215 |
+
# """
|
216 |
+
# **Line 2: A LEGO model featuring an astronaut, green and red elements, and a wizard theme.**
|
217 |
+
# """
|
218 |
+
# )
|
219 |
+
# with gr.Row():
|
220 |
+
# examples = [
|
221 |
+
# ['assets/sample_input/demo/front/lego_astronaut.png', 'assets/sample_input/demo/back/lego_astronaut.png'],
|
222 |
+
# ['assets/sample_input/demo/front/lego_green.png', 'assets/sample_input/demo/back/lego_green.png'],
|
223 |
+
# ['assets/sample_input/demo/front/lego_red.png', 'assets/sample_input/demo/front/lego_red.png'],
|
224 |
+
# ['assets/sample_input/demo/front/lego_wizard.png', 'assets/sample_input/demo/back/lego_wizard.png'],
|
225 |
+
# ]
|
226 |
+
|
227 |
+
# for example in examples:
|
228 |
+
# with gr.Column(scale=0.3):
|
229 |
+
# gr.Examples(
|
230 |
+
# examples=[example],
|
231 |
+
# inputs=[input_front_image, input_back_image],
|
232 |
+
# outputs=None, # [processed_image, output_video],
|
233 |
+
# fn=None, # example_fn,
|
234 |
+
# cache_examples=bool(os.getenv('SPACE_ID')),
|
235 |
+
# examples_per_page=3,
|
236 |
+
# )
|
237 |
+
# with gr.Row():
|
238 |
+
# gr.Markdown(
|
239 |
+
# """
|
240 |
+
# **Line 3: A marvel boy featuring an Captain America, Ironman and Spiderman, and a Superman theme.**
|
241 |
+
# """
|
242 |
+
# )
|
243 |
+
# with gr.Row():
|
244 |
+
# examples = [
|
245 |
+
# ['assets/sample_input/demo/front/marvel_captain.png', 'assets/sample_input/demo/back/marvel_captain.png'],
|
246 |
+
# ['assets/sample_input/demo/front/marvel_ironman.png', 'assets/sample_input/demo/front/marvel_ironman.png'],
|
247 |
+
# ['assets/sample_input/demo/front/marvel_spiderman.png', 'assets/sample_input/demo/back/marvel_spiderman.png'],
|
248 |
+
# ['assets/sample_input/demo/front/marvel_superman.png', 'assets/sample_input/demo/back/marvel_superman.png'],
|
249 |
+
# ]
|
250 |
+
|
251 |
+
# for example in examples:
|
252 |
+
# with gr.Column(scale=0.3):
|
253 |
+
# gr.Examples(
|
254 |
+
# examples=[example],
|
255 |
+
# inputs=[input_front_image, input_back_image],
|
256 |
+
# outputs=None, # [processed_image, output_video],
|
257 |
+
# fn=None, # example_fn,
|
258 |
+
# cache_examples=bool(os.getenv('SPACE_ID')),
|
259 |
+
# examples_per_page=3,
|
260 |
+
# )
|
261 |
+
# # EXAMPLES
|
262 |
+
# with gr.Row():
|
263 |
+
# gr.Markdown(
|
264 |
+
# """
|
265 |
+
# ### B. 3D Generative Geometry or Pattern Fill
|
266 |
+
|
267 |
+
# Here, we start with a simple object and gradually add various accessories, costumes, or patterns step by step. We only showcase the final effect after multiple rounds of decoration. <br>
|
268 |
+
|
269 |
+
# **Line 4: Initial object: sofa, dog, penguin, house.**
|
270 |
+
# """
|
271 |
+
# )
|
272 |
+
# with gr.Row():
|
273 |
+
# examples = [
|
274 |
+
# ['assets/sample_input/demo/front/sofa.png', 'assets/sample_input/demo/back/sofa.png'],
|
275 |
+
# ['assets/sample_input/demo/front/penguin.png', 'assets/sample_input/demo/back/penguin.png'],
|
276 |
+
# ['assets/sample_input/demo/front/house.png', 'assets/sample_input/demo/back/house.png'],
|
277 |
+
# ]
|
278 |
+
|
279 |
+
# for example in examples:
|
280 |
+
# with gr.Column(scale=0.3):
|
281 |
+
# gr.Examples(
|
282 |
+
# examples=[example],
|
283 |
+
# inputs=[input_front_image, input_back_image],
|
284 |
+
# outputs=None, # [processed_image, output_video],
|
285 |
+
# fn=None, # example_fn,
|
286 |
+
# cache_examples=bool(os.getenv('SPACE_ID')),
|
287 |
+
# examples_per_page=3,
|
288 |
+
# )
|
289 |
+
|
290 |
+
# with gr.Row():
|
291 |
+
# gr.Markdown(
|
292 |
+
# """
|
293 |
+
# ### C. 3D Style Fusion
|
294 |
+
|
295 |
+
# We will maintain a consistent front style of the object while continuously changing the back style, blending the two different styles into one object.<br>
|
296 |
+
|
297 |
+
# **Line 5: A bird with different back styles.**
|
298 |
+
# """
|
299 |
+
# )
|
300 |
+
# with gr.Row():
|
301 |
+
# examples = [
|
302 |
+
# ['assets/sample_input/demo/front/bird.png', 'assets/sample_input/demo/back/bird.png'],
|
303 |
+
# ['assets/sample_input/demo/front/bird_brownblue.png', 'assets/sample_input/demo/back/bird_brownblue.png'],
|
304 |
+
# ['assets/sample_input/demo/front/bird_rainbow.png', 'assets/sample_input/demo/back/bird_rainbow.png'],
|
305 |
+
# ['assets/sample_input/demo/front/bird_whitered.png', 'assets/sample_input/demo/back/bird_whitered.png'],
|
306 |
+
# ]
|
307 |
+
|
308 |
+
# for example in examples:
|
309 |
+
# with gr.Column(scale=0.3):
|
310 |
+
# gr.Examples(
|
311 |
+
# examples=[example],
|
312 |
+
# inputs=[input_front_image, input_back_image],
|
313 |
+
# outputs=None, # [processed_image, output_video],
|
314 |
+
# fn=None, # example_fn,
|
315 |
+
# cache_examples=bool(os.getenv('SPACE_ID')),
|
316 |
+
# examples_per_page=3,
|
317 |
+
# )
|
318 |
+
|
319 |
+
# with gr.Row():
|
320 |
+
# gr.Markdown(
|
321 |
+
# """
|
322 |
+
# ### Others
|
323 |
+
# I vote for kunkun forever, I am really an I-kUN and have heard many of his songs.
|
324 |
+
# """
|
325 |
+
# )
|
326 |
+
# with gr.Row():
|
327 |
+
# examples = [
|
328 |
+
# ['assets/sample_input/demo/front/loopy.png', 'assets/sample_input/demo/back/loopy.png'],
|
329 |
+
# ['assets/sample_input/demo/front/mario.png', 'assets/sample_input/demo/back/mario.png'],
|
330 |
+
# ['assets/sample_input/demo/front/armor.png', 'assets/sample_input/demo/back/armor.png'],
|
331 |
+
# ['assets/sample_input/demo/front/kunkun_law.png', 'assets/sample_input/demo/back/kunkun_law.png'],
|
332 |
+
# ]
|
333 |
+
|
334 |
+
# for example in examples:
|
335 |
+
# with gr.Column(scale=0.3):
|
336 |
+
# gr.Examples(
|
337 |
+
# examples=[example],
|
338 |
+
# inputs=[input_front_image, input_back_image],
|
339 |
+
# outputs=None, # [processed_image, output_video],
|
340 |
+
# fn=None, # example_fn,
|
341 |
+
# cache_examples=bool(os.getenv('SPACE_ID')),
|
342 |
+
# examples_per_page=3,
|
343 |
+
# )
|
344 |
+
|
345 |
+
working_dir = gr.State()
|
346 |
+
submit.click(
|
347 |
+
fn=assert_input_image,
|
348 |
+
inputs=[input_front_image, input_back_image],
|
349 |
+
queue=False,
|
350 |
+
).success(
|
351 |
+
fn=prepare_working_dir,
|
352 |
+
outputs=[working_dir],
|
353 |
+
queue=False,
|
354 |
+
).success(
|
355 |
+
fn=preprocess_fn,
|
356 |
+
inputs=[input_front_image, input_back_image, checkbox_rembg, checkbox_recenter, working_dir],
|
357 |
+
outputs=[processed_front_image, processed_back_image],
|
358 |
+
).success(
|
359 |
+
fn=core_fn,
|
360 |
+
inputs=[processed_front_image, processed_back_image, slider_cam_dist, working_dir],
|
361 |
+
outputs=[output_video],
|
362 |
+
)
|
363 |
+
|
364 |
+
demo.queue()
|
365 |
+
demo.launch()
|
366 |
+
|
367 |
+
|
368 |
+
def launch_gradio_app():
|
369 |
+
|
370 |
+
os.environ.update({
|
371 |
+
"APP_ENABLED": "1",
|
372 |
+
"APP_MODEL_NAME": "alexzyqi/Tailor3D-Base-1.0",
|
373 |
+
"APP_PRETRAIN_MODEL_NAME": "zxhezexin/openlrm-mix-base-1.1",
|
374 |
+
"APP_INFER": "./configs/infer-gradio-base.yaml",
|
375 |
+
"APP_TYPE": "infer.lrm",
|
376 |
+
"NUMBA_THREADING_LAYER": 'omp',
|
377 |
+
})
|
378 |
+
|
379 |
+
from openlrm.runners import REGISTRY_RUNNERS
|
380 |
+
from openlrm.runners.infer.base_inferrer import Inferrer
|
381 |
+
InferrerClass : Inferrer = REGISTRY_RUNNERS[os.getenv("APP_TYPE")]
|
382 |
+
with InferrerClass() as inferrer:
|
383 |
+
init_preprocessor()
|
384 |
+
if not bool(os.getenv('SPACE_ID')):
|
385 |
+
from openlrm.utils.proxy import no_proxy
|
386 |
+
demo = no_proxy(demo_openlrm)
|
387 |
+
else:
|
388 |
+
demo = demo_openlrm
|
389 |
+
demo(infer_impl=inferrer.infer_single)
|
390 |
+
|
391 |
+
|
392 |
+
if __name__ == '__main__':
|
393 |
+
|
394 |
+
launch_gradio_app()
|
assets/sample_input/demo/back/armor.png
ADDED
assets/sample_input/demo/back/bird.png
ADDED
assets/sample_input/demo/back/bird_brownblue.png
ADDED
assets/sample_input/demo/back/bird_rainbow.png
ADDED
assets/sample_input/demo/back/bird_whitered.png
ADDED
assets/sample_input/demo/back/boy_astronaut.png
ADDED
assets/sample_input/demo/back/boy_blue.png
ADDED
assets/sample_input/demo/back/boy_chinese_style.png
ADDED
assets/sample_input/demo/back/boy_grey_clothes.png
ADDED
assets/sample_input/demo/back/house.png
ADDED
assets/sample_input/demo/back/kunkun_law.png
ADDED
assets/sample_input/demo/back/lego_astronaut.png
ADDED
assets/sample_input/demo/back/lego_green.png
ADDED
assets/sample_input/demo/back/lego_red.png
ADDED
assets/sample_input/demo/back/lego_wizard.png
ADDED
assets/sample_input/demo/back/loopy.png
ADDED
assets/sample_input/demo/back/mario.png
ADDED
assets/sample_input/demo/back/marvel_captain.png
ADDED
assets/sample_input/demo/back/marvel_ironman.png
ADDED
assets/sample_input/demo/back/marvel_spiderman.png
ADDED
assets/sample_input/demo/back/marvel_superman.png
ADDED
assets/sample_input/demo/back/penguin.png
ADDED
assets/sample_input/demo/back/sofa.png
ADDED
assets/sample_input/demo/front/armor.png
ADDED
assets/sample_input/demo/front/bird.png
ADDED
assets/sample_input/demo/front/bird_brownblue.png
ADDED
assets/sample_input/demo/front/bird_rainbow.png
ADDED
assets/sample_input/demo/front/bird_whitered.png
ADDED
assets/sample_input/demo/front/boy_astronaut.png
ADDED
assets/sample_input/demo/front/boy_blue.png
ADDED
assets/sample_input/demo/front/boy_chinese_style.png
ADDED
assets/sample_input/demo/front/boy_grey_clothes.png
ADDED
assets/sample_input/demo/front/house.png
ADDED
assets/sample_input/demo/front/kunkun_law.png
ADDED
assets/sample_input/demo/front/lego_astronaut.png
ADDED
assets/sample_input/demo/front/lego_green.png
ADDED
assets/sample_input/demo/front/lego_red.png
ADDED
assets/sample_input/demo/front/lego_wizard.png
ADDED
assets/sample_input/demo/front/loopy.png
ADDED
assets/sample_input/demo/front/mario.png
ADDED
assets/sample_input/demo/front/marvel_captain.png
ADDED
assets/sample_input/demo/front/marvel_ironman.png
ADDED
assets/sample_input/demo/front/marvel_spiderman.png
ADDED
assets/sample_input/demo/front/marvel_superman.png
ADDED
assets/sample_input/demo/front/penguin.png
ADDED
assets/sample_input/demo/front/sofa.png
ADDED
configs/accelerate-train-4gpus.yaml
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
compute_environment: LOCAL_MACHINE
|
2 |
+
debug: false
|
3 |
+
distributed_type: MULTI_GPU
|
4 |
+
downcast_bf16: 'no'
|
5 |
+
# gpu_ids: all
|
6 |
+
machine_rank: 0
|
7 |
+
main_training_function: main
|
8 |
+
mixed_precision: bf16
|
9 |
+
num_machines: 1
|
10 |
+
num_processes: 4
|
11 |
+
rdzv_backend: static
|
12 |
+
same_network: true
|
13 |
+
tpu_env: []
|
14 |
+
tpu_use_cluster: false
|
15 |
+
tpu_use_sudo: false
|
16 |
+
use_cpu: false
|
17 |
+
main_process_port: 34567
|
configs/accelerate-train.yaml
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
compute_environment: LOCAL_MACHINE
|
2 |
+
debug: false
|
3 |
+
distributed_type: MULTI_GPU
|
4 |
+
downcast_bf16: 'no'
|
5 |
+
gpu_ids: all
|
6 |
+
machine_rank: 0
|
7 |
+
main_training_function: main
|
8 |
+
mixed_precision: bf16
|
9 |
+
num_machines: 1
|
10 |
+
num_processes: 8
|
11 |
+
rdzv_backend: static
|
12 |
+
same_network: true
|
13 |
+
tpu_env: []
|
14 |
+
tpu_use_cluster: false
|
15 |
+
tpu_use_sudo: false
|
16 |
+
use_cpu: false
|
17 |
+
main_process_port: 35567
|