Spaces:
Running
on
Zero
Running
on
Zero
update to v1.5
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- apps/examples/1.jpg +0 -0
- apps/examples/1_cute_girl.webp +0 -0
- apps/examples/bird.jpg +0 -0
- apps/examples/blue_monster.webp +0 -0
- apps/examples/boy2.webp +0 -0
- apps/examples/bulldog.webp +0 -0
- apps/examples/catman.webp +0 -0
- apps/examples/cyberpunk_man.webp +0 -0
- apps/examples/dinosaur_boy.webp +0 -0
- apps/examples/doraemon.webp +0 -0
- apps/examples/dragon.webp +0 -0
- apps/examples/dragontoy.jpg +0 -0
- apps/examples/girl1.webp +0 -0
- apps/examples/gun.webp +0 -0
- apps/examples/kunkun.webp +0 -0
- apps/examples/link.webp +0 -0
- apps/examples/mushroom1.webp +0 -0
- apps/examples/mushroom2.webp +0 -0
- apps/examples/phoenix.webp +0 -0
- apps/examples/robot.png +0 -0
- apps/examples/rose.webp +0 -0
- apps/examples/shoe.webp +0 -0
- apps/examples/sports_girl.webp +0 -0
- apps/examples/stone.webp +0 -0
- apps/examples/sweater.webp +0 -0
- apps/examples/sword.webp +0 -0
- apps/examples/teapot.webp +0 -0
- apps/examples/toy_bear.webp +0 -0
- apps/examples/toy_dog.webp +0 -0
- apps/examples/toy_pig.webp +0 -0
- apps/examples/toy_rabbit.webp +0 -0
- apps/examples/wiking.webp +0 -0
- apps/examples/wings.webp +0 -0
- apps/third_party/CRM/LICENSE +0 -21
- apps/third_party/CRM/README.md +0 -85
- apps/third_party/CRM/app.py +0 -228
- apps/third_party/CRM/configs/nf7_v3_SNR_rd_size_stroke.yaml +0 -21
- apps/third_party/CRM/configs/specs_objaverse_total.json +0 -57
- apps/third_party/CRM/configs/stage2-v2-snr.yaml +0 -25
- apps/third_party/CRM/imagedream/.DS_Store +0 -0
- apps/third_party/CRM/imagedream/__init__.py +0 -1
- apps/third_party/CRM/imagedream/__pycache__/__init__.cpython-310.pyc +0 -0
- apps/third_party/CRM/imagedream/__pycache__/__init__.cpython-38.pyc +0 -0
- apps/third_party/CRM/imagedream/__pycache__/camera_utils.cpython-310.pyc +0 -0
- apps/third_party/CRM/imagedream/__pycache__/camera_utils.cpython-38.pyc +0 -0
- apps/third_party/CRM/imagedream/__pycache__/model_zoo.cpython-310.pyc +0 -0
- apps/third_party/CRM/imagedream/__pycache__/model_zoo.cpython-38.pyc +0 -0
- apps/third_party/CRM/imagedream/camera_utils.py +0 -99
- apps/third_party/CRM/imagedream/configs/sd_v2_base_ipmv.yaml +0 -61
- apps/third_party/CRM/imagedream/configs/sd_v2_base_ipmv_ch8.yaml +0 -61
apps/examples/1.jpg
DELETED
Binary file (33.8 kB)
|
|
apps/examples/1_cute_girl.webp
DELETED
Binary file (38.4 kB)
|
|
apps/examples/bird.jpg
DELETED
Binary file (43.8 kB)
|
|
apps/examples/blue_monster.webp
DELETED
Binary file (52.5 kB)
|
|
apps/examples/boy2.webp
DELETED
Binary file (21 kB)
|
|
apps/examples/bulldog.webp
DELETED
Binary file (33.1 kB)
|
|
apps/examples/catman.webp
DELETED
Binary file (49 kB)
|
|
apps/examples/cyberpunk_man.webp
DELETED
Binary file (57 kB)
|
|
apps/examples/dinosaur_boy.webp
DELETED
Binary file (23.4 kB)
|
|
apps/examples/doraemon.webp
DELETED
Binary file (84.3 kB)
|
|
apps/examples/dragon.webp
DELETED
Binary file (65.8 kB)
|
|
apps/examples/dragontoy.jpg
DELETED
Binary file (16.6 kB)
|
|
apps/examples/girl1.webp
DELETED
Binary file (354 kB)
|
|
apps/examples/gun.webp
DELETED
Binary file (27.3 kB)
|
|
apps/examples/kunkun.webp
DELETED
Binary file (6.73 kB)
|
|
apps/examples/link.webp
DELETED
Binary file (41.3 kB)
|
|
apps/examples/mushroom1.webp
DELETED
Binary file (64.6 kB)
|
|
apps/examples/mushroom2.webp
DELETED
Binary file (11.3 kB)
|
|
apps/examples/phoenix.webp
DELETED
Binary file (14.6 kB)
|
|
apps/examples/robot.png
DELETED
Binary file (58.9 kB)
|
|
apps/examples/rose.webp
DELETED
Binary file (55.2 kB)
|
|
apps/examples/shoe.webp
DELETED
Binary file (75 kB)
|
|
apps/examples/sports_girl.webp
DELETED
Binary file (97.3 kB)
|
|
apps/examples/stone.webp
DELETED
Binary file (12.9 kB)
|
|
apps/examples/sweater.webp
DELETED
Binary file (119 kB)
|
|
apps/examples/sword.webp
DELETED
Binary file (111 kB)
|
|
apps/examples/teapot.webp
DELETED
Binary file (4 kB)
|
|
apps/examples/toy_bear.webp
DELETED
Binary file (5.92 kB)
|
|
apps/examples/toy_dog.webp
DELETED
Binary file (5.4 kB)
|
|
apps/examples/toy_pig.webp
DELETED
Binary file (7.18 kB)
|
|
apps/examples/toy_rabbit.webp
DELETED
Binary file (4.97 kB)
|
|
apps/examples/wiking.webp
DELETED
Binary file (12.2 kB)
|
|
apps/examples/wings.webp
DELETED
Binary file (102 kB)
|
|
apps/third_party/CRM/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1 |
-
MIT License
|
2 |
-
|
3 |
-
Copyright (c) 2024 TSAIL group
|
4 |
-
|
5 |
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 |
-
of this software and associated documentation files (the "Software"), to deal
|
7 |
-
in the Software without restriction, including without limitation the rights
|
8 |
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9 |
-
copies of the Software, and to permit persons to whom the Software is
|
10 |
-
furnished to do so, subject to the following conditions:
|
11 |
-
|
12 |
-
The above copyright notice and this permission notice shall be included in all
|
13 |
-
copies or substantial portions of the Software.
|
14 |
-
|
15 |
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16 |
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17 |
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18 |
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19 |
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20 |
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21 |
-
SOFTWARE.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apps/third_party/CRM/README.md
DELETED
@@ -1,85 +0,0 @@
|
|
1 |
-
# Convolutional Reconstruction Model
|
2 |
-
|
3 |
-
Official implementation for *CRM: Single Image to 3D Textured Mesh with Convolutional Reconstruction Model*.
|
4 |
-
|
5 |
-
**CRM is a feed-forward model which can generate 3D textured mesh in 10 seconds.**
|
6 |
-
|
7 |
-
## [Project Page](https://ml.cs.tsinghua.edu.cn/~zhengyi/CRM/) | [Arxiv](https://arxiv.org/abs/2403.05034) | [HF-Demo](https://huggingface.co/spaces/Zhengyi/CRM) | [Weights](https://huggingface.co/Zhengyi/CRM)
|
8 |
-
|
9 |
-
https://github.com/thu-ml/CRM/assets/40787266/8b325bc0-aa74-4c26-92e8-a8f0c1079382
|
10 |
-
|
11 |
-
## Try CRM 🍻
|
12 |
-
* Try CRM at [Huggingface Demo](https://huggingface.co/spaces/Zhengyi/CRM).
|
13 |
-
* Try CRM at [Replicate Demo](https://replicate.com/camenduru/crm). Thanks [@camenduru](https://github.com/camenduru)!
|
14 |
-
|
15 |
-
## Install
|
16 |
-
|
17 |
-
### Step 1 - Base
|
18 |
-
|
19 |
-
Install package one by one, we use **python 3.9**
|
20 |
-
|
21 |
-
```bash
|
22 |
-
pip install torch==1.13.0+cu117 torchvision==0.14.0+cu117 torchaudio==0.13.0 --extra-index-url https://download.pytorch.org/whl/cu117
|
23 |
-
pip install torch-scatter==2.1.1 -f https://data.pyg.org/whl/torch-1.13.1+cu117.html
|
24 |
-
pip install kaolin==0.14.0 -f https://nvidia-kaolin.s3.us-east-2.amazonaws.com/torch-1.13.1_cu117.html
|
25 |
-
pip install -r requirements.txt
|
26 |
-
```
|
27 |
-
|
28 |
-
besides, one by one need to install xformers manually according to the official [doc](https://github.com/facebookresearch/xformers?tab=readme-ov-file#installing-xformers) (**conda no need**), e.g.
|
29 |
-
|
30 |
-
```bash
|
31 |
-
pip install ninja
|
32 |
-
pip install -v -U git+https://github.com/facebookresearch/xformers.git@main#egg=xformers
|
33 |
-
```
|
34 |
-
|
35 |
-
### Step 2 - Nvdiffrast
|
36 |
-
|
37 |
-
Install nvdiffrast according to the official [doc](https://nvlabs.github.io/nvdiffrast/#installation), e.g.
|
38 |
-
|
39 |
-
```bash
|
40 |
-
pip install git+https://github.com/NVlabs/nvdiffrast
|
41 |
-
```
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
## Inference
|
46 |
-
|
47 |
-
We suggest gradio for a visualized inference.
|
48 |
-
|
49 |
-
```
|
50 |
-
gradio app.py
|
51 |
-
```
|
52 |
-
|
53 |
-
![image](https://github.com/thu-ml/CRM/assets/40787266/4354d22a-a641-4531-8408-c761ead8b1a2)
|
54 |
-
|
55 |
-
For inference in command lines, simply run
|
56 |
-
```bash
|
57 |
-
CUDA_VISIBLE_DEVICES="0" python run.py --inputdir "examples/kunkun.webp"
|
58 |
-
```
|
59 |
-
It will output the preprocessed image, generated 6-view images and CCMs and a 3D model in obj format.
|
60 |
-
|
61 |
-
**Tips:** (1) If the result is unsatisfatory, please check whether the input image is correctly pre-processed into a grey background. Otherwise the results will be unpredictable.
|
62 |
-
(2) Different from the [Huggingface Demo](https://huggingface.co/spaces/Zhengyi/CRM), this official implementation uses UV texture instead of vertex color. It has better texture than the online demo but longer generating time owing to the UV texturing.
|
63 |
-
|
64 |
-
## Todo List
|
65 |
-
- [x] Release inference code.
|
66 |
-
- [x] Release pretrained models.
|
67 |
-
- [ ] Optimize inference code to fit in low memery GPU.
|
68 |
-
- [ ] Upload training code.
|
69 |
-
|
70 |
-
## Acknowledgement
|
71 |
-
- [ImageDream](https://github.com/bytedance/ImageDream)
|
72 |
-
- [nvdiffrast](https://github.com/NVlabs/nvdiffrast)
|
73 |
-
- [kiuikit](https://github.com/ashawkey/kiuikit)
|
74 |
-
- [GET3D](https://github.com/nv-tlabs/GET3D)
|
75 |
-
|
76 |
-
## Citation
|
77 |
-
|
78 |
-
```
|
79 |
-
@article{wang2024crm,
|
80 |
-
title={CRM: Single Image to 3D Textured Mesh with Convolutional Reconstruction Model},
|
81 |
-
author={Zhengyi Wang and Yikai Wang and Yifei Chen and Chendong Xiang and Shuo Chen and Dajiang Yu and Chongxuan Li and Hang Su and Jun Zhu},
|
82 |
-
journal={arXiv preprint arXiv:2403.05034},
|
83 |
-
year={2024}
|
84 |
-
}
|
85 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apps/third_party/CRM/app.py
DELETED
@@ -1,228 +0,0 @@
|
|
1 |
-
# Not ready to use yet
|
2 |
-
import argparse
|
3 |
-
import numpy as np
|
4 |
-
import gradio as gr
|
5 |
-
from omegaconf import OmegaConf
|
6 |
-
import torch
|
7 |
-
from PIL import Image
|
8 |
-
import PIL
|
9 |
-
from pipelines import TwoStagePipeline
|
10 |
-
from huggingface_hub import hf_hub_download
|
11 |
-
import os
|
12 |
-
import rembg
|
13 |
-
from typing import Any
|
14 |
-
import json
|
15 |
-
import os
|
16 |
-
import json
|
17 |
-
import argparse
|
18 |
-
|
19 |
-
from model import CRM
|
20 |
-
from inference import generate3d
|
21 |
-
|
22 |
-
pipeline = None
|
23 |
-
rembg_session = rembg.new_session()
|
24 |
-
|
25 |
-
|
26 |
-
def expand_to_square(image, bg_color=(0, 0, 0, 0)):
|
27 |
-
# expand image to 1:1
|
28 |
-
width, height = image.size
|
29 |
-
if width == height:
|
30 |
-
return image
|
31 |
-
new_size = (max(width, height), max(width, height))
|
32 |
-
new_image = Image.new("RGBA", new_size, bg_color)
|
33 |
-
paste_position = ((new_size[0] - width) // 2, (new_size[1] - height) // 2)
|
34 |
-
new_image.paste(image, paste_position)
|
35 |
-
return new_image
|
36 |
-
|
37 |
-
def check_input_image(input_image):
|
38 |
-
if input_image is None:
|
39 |
-
raise gr.Error("No image uploaded!")
|
40 |
-
|
41 |
-
|
42 |
-
def remove_background(
|
43 |
-
image: PIL.Image.Image,
|
44 |
-
rembg_session = None,
|
45 |
-
force: bool = False,
|
46 |
-
**rembg_kwargs,
|
47 |
-
) -> PIL.Image.Image:
|
48 |
-
do_remove = True
|
49 |
-
if image.mode == "RGBA" and image.getextrema()[3][0] < 255:
|
50 |
-
# explain why current do not rm bg
|
51 |
-
print("alhpa channl not enpty, skip remove background, using alpha channel as mask")
|
52 |
-
background = Image.new("RGBA", image.size, (0, 0, 0, 0))
|
53 |
-
image = Image.alpha_composite(background, image)
|
54 |
-
do_remove = False
|
55 |
-
do_remove = do_remove or force
|
56 |
-
if do_remove:
|
57 |
-
image = rembg.remove(image, session=rembg_session, **rembg_kwargs)
|
58 |
-
return image
|
59 |
-
|
60 |
-
def do_resize_content(original_image: Image, scale_rate):
|
61 |
-
# resize image content wile retain the original image size
|
62 |
-
if scale_rate != 1:
|
63 |
-
# Calculate the new size after rescaling
|
64 |
-
new_size = tuple(int(dim * scale_rate) for dim in original_image.size)
|
65 |
-
# Resize the image while maintaining the aspect ratio
|
66 |
-
resized_image = original_image.resize(new_size)
|
67 |
-
# Create a new image with the original size and black background
|
68 |
-
padded_image = Image.new("RGBA", original_image.size, (0, 0, 0, 0))
|
69 |
-
paste_position = ((original_image.width - resized_image.width) // 2, (original_image.height - resized_image.height) // 2)
|
70 |
-
padded_image.paste(resized_image, paste_position)
|
71 |
-
return padded_image
|
72 |
-
else:
|
73 |
-
return original_image
|
74 |
-
|
75 |
-
def add_background(image, bg_color=(255, 255, 255)):
|
76 |
-
# given an RGBA image, alpha channel is used as mask to add background color
|
77 |
-
background = Image.new("RGBA", image.size, bg_color)
|
78 |
-
return Image.alpha_composite(background, image)
|
79 |
-
|
80 |
-
|
81 |
-
def preprocess_image(image, background_choice, foreground_ratio, backgroud_color):
|
82 |
-
"""
|
83 |
-
input image is a pil image in RGBA, return RGB image
|
84 |
-
"""
|
85 |
-
print(background_choice)
|
86 |
-
if background_choice == "Alpha as mask":
|
87 |
-
background = Image.new("RGBA", image.size, (0, 0, 0, 0))
|
88 |
-
image = Image.alpha_composite(background, image)
|
89 |
-
else:
|
90 |
-
image = remove_background(image, rembg_session, force_remove=True)
|
91 |
-
image = do_resize_content(image, foreground_ratio)
|
92 |
-
image = expand_to_square(image)
|
93 |
-
image = add_background(image, backgroud_color)
|
94 |
-
return image.convert("RGB")
|
95 |
-
|
96 |
-
|
97 |
-
def gen_image(input_image, seed, scale, step):
|
98 |
-
global pipeline, model, args
|
99 |
-
pipeline.set_seed(seed)
|
100 |
-
rt_dict = pipeline(input_image, scale=scale, step=step)
|
101 |
-
stage1_images = rt_dict["stage1_images"]
|
102 |
-
stage2_images = rt_dict["stage2_images"]
|
103 |
-
np_imgs = np.concatenate(stage1_images, 1)
|
104 |
-
np_xyzs = np.concatenate(stage2_images, 1)
|
105 |
-
|
106 |
-
glb_path, obj_path = generate3d(model, np_imgs, np_xyzs, args.device)
|
107 |
-
return Image.fromarray(np_imgs), Image.fromarray(np_xyzs), glb_path, obj_path
|
108 |
-
|
109 |
-
|
110 |
-
parser = argparse.ArgumentParser()
|
111 |
-
parser.add_argument(
|
112 |
-
"--stage1_config",
|
113 |
-
type=str,
|
114 |
-
default="configs/nf7_v3_SNR_rd_size_stroke.yaml",
|
115 |
-
help="config for stage1",
|
116 |
-
)
|
117 |
-
parser.add_argument(
|
118 |
-
"--stage2_config",
|
119 |
-
type=str,
|
120 |
-
default="configs/stage2-v2-snr.yaml",
|
121 |
-
help="config for stage2",
|
122 |
-
)
|
123 |
-
|
124 |
-
parser.add_argument("--device", type=str, default="cuda")
|
125 |
-
args = parser.parse_args()
|
126 |
-
|
127 |
-
crm_path = hf_hub_download(repo_id="Zhengyi/CRM", filename="CRM.pth")
|
128 |
-
specs = json.load(open("configs/specs_objaverse_total.json"))
|
129 |
-
model = CRM(specs).to(args.device)
|
130 |
-
model.load_state_dict(torch.load(crm_path, map_location = args.device), strict=False)
|
131 |
-
|
132 |
-
stage1_config = OmegaConf.load(args.stage1_config).config
|
133 |
-
stage2_config = OmegaConf.load(args.stage2_config).config
|
134 |
-
stage2_sampler_config = stage2_config.sampler
|
135 |
-
stage1_sampler_config = stage1_config.sampler
|
136 |
-
|
137 |
-
stage1_model_config = stage1_config.models
|
138 |
-
stage2_model_config = stage2_config.models
|
139 |
-
|
140 |
-
xyz_path = hf_hub_download(repo_id="Zhengyi/CRM", filename="ccm-diffusion.pth")
|
141 |
-
pixel_path = hf_hub_download(repo_id="Zhengyi/CRM", filename="pixel-diffusion.pth")
|
142 |
-
stage1_model_config.resume = pixel_path
|
143 |
-
stage2_model_config.resume = xyz_path
|
144 |
-
|
145 |
-
pipeline = TwoStagePipeline(
|
146 |
-
stage1_model_config,
|
147 |
-
stage2_model_config,
|
148 |
-
stage1_sampler_config,
|
149 |
-
stage2_sampler_config,
|
150 |
-
device=args.device,
|
151 |
-
dtype=torch.float16
|
152 |
-
)
|
153 |
-
|
154 |
-
with gr.Blocks() as demo:
|
155 |
-
gr.Markdown("# CRM: Single Image to 3D Textured Mesh with Convolutional Reconstruction Model")
|
156 |
-
with gr.Row():
|
157 |
-
with gr.Column():
|
158 |
-
with gr.Row():
|
159 |
-
image_input = gr.Image(
|
160 |
-
label="Image input",
|
161 |
-
image_mode="RGBA",
|
162 |
-
sources="upload",
|
163 |
-
type="pil",
|
164 |
-
)
|
165 |
-
processed_image = gr.Image(label="Processed Image", interactive=False, type="pil", image_mode="RGB")
|
166 |
-
with gr.Row():
|
167 |
-
with gr.Column():
|
168 |
-
with gr.Row():
|
169 |
-
background_choice = gr.Radio([
|
170 |
-
"Alpha as mask",
|
171 |
-
"Auto Remove background"
|
172 |
-
], value="Auto Remove background",
|
173 |
-
label="backgroud choice")
|
174 |
-
# do_remove_background = gr.Checkbox(label=, value=True)
|
175 |
-
# force_remove = gr.Checkbox(label=, value=False)
|
176 |
-
back_groud_color = gr.ColorPicker(label="Background Color", value="#7F7F7F", interactive=False)
|
177 |
-
foreground_ratio = gr.Slider(
|
178 |
-
label="Foreground Ratio",
|
179 |
-
minimum=0.5,
|
180 |
-
maximum=1.0,
|
181 |
-
value=1.0,
|
182 |
-
step=0.05,
|
183 |
-
)
|
184 |
-
|
185 |
-
with gr.Column():
|
186 |
-
seed = gr.Number(value=1234, label="seed", precision=0)
|
187 |
-
guidance_scale = gr.Number(value=5.5, minimum=3, maximum=10, label="guidance_scale")
|
188 |
-
step = gr.Number(value=50, minimum=30, maximum=100, label="sample steps", precision=0)
|
189 |
-
text_button = gr.Button("Generate 3D shape")
|
190 |
-
gr.Examples(
|
191 |
-
examples=[os.path.join("examples", i) for i in os.listdir("examples")],
|
192 |
-
inputs=[image_input],
|
193 |
-
)
|
194 |
-
with gr.Column():
|
195 |
-
image_output = gr.Image(interactive=False, label="Output RGB image")
|
196 |
-
xyz_ouput = gr.Image(interactive=False, label="Output CCM image")
|
197 |
-
|
198 |
-
output_model = gr.Model3D(
|
199 |
-
label="Output GLB",
|
200 |
-
interactive=False,
|
201 |
-
)
|
202 |
-
gr.Markdown("Note: The GLB model shown here has a darker lighting and enlarged UV seams. Download for correct results.")
|
203 |
-
output_obj = gr.File(interactive=False, label="Output OBJ")
|
204 |
-
|
205 |
-
inputs = [
|
206 |
-
processed_image,
|
207 |
-
seed,
|
208 |
-
guidance_scale,
|
209 |
-
step,
|
210 |
-
]
|
211 |
-
outputs = [
|
212 |
-
image_output,
|
213 |
-
xyz_ouput,
|
214 |
-
output_model,
|
215 |
-
output_obj,
|
216 |
-
]
|
217 |
-
|
218 |
-
|
219 |
-
text_button.click(fn=check_input_image, inputs=[image_input]).success(
|
220 |
-
fn=preprocess_image,
|
221 |
-
inputs=[image_input, background_choice, foreground_ratio, back_groud_color],
|
222 |
-
outputs=[processed_image],
|
223 |
-
).success(
|
224 |
-
fn=gen_image,
|
225 |
-
inputs=inputs,
|
226 |
-
outputs=outputs,
|
227 |
-
)
|
228 |
-
demo.queue().launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apps/third_party/CRM/configs/nf7_v3_SNR_rd_size_stroke.yaml
DELETED
@@ -1,21 +0,0 @@
|
|
1 |
-
config:
|
2 |
-
# others
|
3 |
-
seed: 1234
|
4 |
-
num_frames: 7
|
5 |
-
mode: pixel
|
6 |
-
offset_noise: true
|
7 |
-
# model related
|
8 |
-
models:
|
9 |
-
config: imagedream/configs/sd_v2_base_ipmv_zero_SNR.yaml
|
10 |
-
resume: models/pixel.pth
|
11 |
-
# sampler related
|
12 |
-
sampler:
|
13 |
-
target: libs.sample.ImageDreamDiffusion
|
14 |
-
params:
|
15 |
-
mode: pixel
|
16 |
-
num_frames: 7
|
17 |
-
camera_views: [1, 2, 3, 4, 5, 0, 0]
|
18 |
-
ref_position: 6
|
19 |
-
random_background: false
|
20 |
-
offset_noise: true
|
21 |
-
resize_rate: 1.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apps/third_party/CRM/configs/specs_objaverse_total.json
DELETED
@@ -1,57 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"Input": {
|
3 |
-
"img_num": 16,
|
4 |
-
"class": "all",
|
5 |
-
"camera_angle_num": 8,
|
6 |
-
"tet_grid_size": 80,
|
7 |
-
"validate_num": 16,
|
8 |
-
"scale": 0.95,
|
9 |
-
"radius": 3,
|
10 |
-
"resolution": [256, 256]
|
11 |
-
},
|
12 |
-
|
13 |
-
"Pretrain": {
|
14 |
-
"mode": null,
|
15 |
-
"sdf_threshold": 0.1,
|
16 |
-
"sdf_scale": 10,
|
17 |
-
"batch_infer": false,
|
18 |
-
"lr": 1e-4,
|
19 |
-
"radius": 0.5
|
20 |
-
},
|
21 |
-
|
22 |
-
"Train": {
|
23 |
-
"mode": "rnd",
|
24 |
-
"num_epochs": 500,
|
25 |
-
"grad_acc": 1,
|
26 |
-
"warm_up": 0,
|
27 |
-
"decay": 0.000,
|
28 |
-
"learning_rate": {
|
29 |
-
"init": 1e-4,
|
30 |
-
"sdf_decay": 1,
|
31 |
-
"rgb_decay": 1
|
32 |
-
},
|
33 |
-
"batch_size": 4,
|
34 |
-
"eva_iter": 80,
|
35 |
-
"eva_all_epoch": 10,
|
36 |
-
"tex_sup_mode": "blender",
|
37 |
-
"exp_uv_mesh": false,
|
38 |
-
"doub": false,
|
39 |
-
"random_bg": false,
|
40 |
-
"shift": 0,
|
41 |
-
"aug_shift": 0,
|
42 |
-
"geo_type": "flex"
|
43 |
-
},
|
44 |
-
|
45 |
-
"ArchSpecs": {
|
46 |
-
"unet_type": "diffusers",
|
47 |
-
"use_3D_aware": false,
|
48 |
-
"fea_concat": false,
|
49 |
-
"mlp_bias": true
|
50 |
-
},
|
51 |
-
|
52 |
-
"DecoderSpecs": {
|
53 |
-
"c_dim": 32,
|
54 |
-
"plane_resolution": 256
|
55 |
-
}
|
56 |
-
}
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apps/third_party/CRM/configs/stage2-v2-snr.yaml
DELETED
@@ -1,25 +0,0 @@
|
|
1 |
-
config:
|
2 |
-
# others
|
3 |
-
seed: 1234
|
4 |
-
num_frames: 6
|
5 |
-
mode: pixel
|
6 |
-
offset_noise: true
|
7 |
-
gd_type: xyz
|
8 |
-
# model related
|
9 |
-
models:
|
10 |
-
config: imagedream/configs/sd_v2_base_ipmv_chin8_zero_snr.yaml
|
11 |
-
resume: models/xyz.pth
|
12 |
-
|
13 |
-
# eval related
|
14 |
-
sampler:
|
15 |
-
target: libs.sample.ImageDreamDiffusionStage2
|
16 |
-
params:
|
17 |
-
mode: pixel
|
18 |
-
num_frames: 6
|
19 |
-
camera_views: [1, 2, 3, 4, 5, 0]
|
20 |
-
ref_position: null
|
21 |
-
random_background: false
|
22 |
-
offset_noise: true
|
23 |
-
resize_rate: 1.0
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apps/third_party/CRM/imagedream/.DS_Store
DELETED
Binary file (6.15 kB)
|
|
apps/third_party/CRM/imagedream/__init__.py
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
from .model_zoo import build_model
|
|
|
|
apps/third_party/CRM/imagedream/__pycache__/__init__.cpython-310.pyc
DELETED
Binary file (219 Bytes)
|
|
apps/third_party/CRM/imagedream/__pycache__/__init__.cpython-38.pyc
DELETED
Binary file (216 Bytes)
|
|
apps/third_party/CRM/imagedream/__pycache__/camera_utils.cpython-310.pyc
DELETED
Binary file (2.83 kB)
|
|
apps/third_party/CRM/imagedream/__pycache__/camera_utils.cpython-38.pyc
DELETED
Binary file (2.75 kB)
|
|
apps/third_party/CRM/imagedream/__pycache__/model_zoo.cpython-310.pyc
DELETED
Binary file (1.79 kB)
|
|
apps/third_party/CRM/imagedream/__pycache__/model_zoo.cpython-38.pyc
DELETED
Binary file (1.79 kB)
|
|
apps/third_party/CRM/imagedream/camera_utils.py
DELETED
@@ -1,99 +0,0 @@
|
|
1 |
-
import numpy as np
|
2 |
-
import torch
|
3 |
-
|
4 |
-
|
5 |
-
def create_camera_to_world_matrix(elevation, azimuth):
|
6 |
-
elevation = np.radians(elevation)
|
7 |
-
azimuth = np.radians(azimuth)
|
8 |
-
# Convert elevation and azimuth angles to Cartesian coordinates on a unit sphere
|
9 |
-
x = np.cos(elevation) * np.sin(azimuth)
|
10 |
-
y = np.sin(elevation)
|
11 |
-
z = np.cos(elevation) * np.cos(azimuth)
|
12 |
-
|
13 |
-
# Calculate camera position, target, and up vectors
|
14 |
-
camera_pos = np.array([x, y, z])
|
15 |
-
target = np.array([0, 0, 0])
|
16 |
-
up = np.array([0, 1, 0])
|
17 |
-
|
18 |
-
# Construct view matrix
|
19 |
-
forward = target - camera_pos
|
20 |
-
forward /= np.linalg.norm(forward)
|
21 |
-
right = np.cross(forward, up)
|
22 |
-
right /= np.linalg.norm(right)
|
23 |
-
new_up = np.cross(right, forward)
|
24 |
-
new_up /= np.linalg.norm(new_up)
|
25 |
-
cam2world = np.eye(4)
|
26 |
-
cam2world[:3, :3] = np.array([right, new_up, -forward]).T
|
27 |
-
cam2world[:3, 3] = camera_pos
|
28 |
-
return cam2world
|
29 |
-
|
30 |
-
|
31 |
-
def convert_opengl_to_blender(camera_matrix):
|
32 |
-
if isinstance(camera_matrix, np.ndarray):
|
33 |
-
# Construct transformation matrix to convert from OpenGL space to Blender space
|
34 |
-
flip_yz = np.array([[1, 0, 0, 0], [0, 0, -1, 0], [0, 1, 0, 0], [0, 0, 0, 1]])
|
35 |
-
camera_matrix_blender = np.dot(flip_yz, camera_matrix)
|
36 |
-
else:
|
37 |
-
# Construct transformation matrix to convert from OpenGL space to Blender space
|
38 |
-
flip_yz = torch.tensor(
|
39 |
-
[[1, 0, 0, 0], [0, 0, -1, 0], [0, 1, 0, 0], [0, 0, 0, 1]]
|
40 |
-
)
|
41 |
-
if camera_matrix.ndim == 3:
|
42 |
-
flip_yz = flip_yz.unsqueeze(0)
|
43 |
-
camera_matrix_blender = torch.matmul(flip_yz.to(camera_matrix), camera_matrix)
|
44 |
-
return camera_matrix_blender
|
45 |
-
|
46 |
-
|
47 |
-
def normalize_camera(camera_matrix):
|
48 |
-
"""normalize the camera location onto a unit-sphere"""
|
49 |
-
if isinstance(camera_matrix, np.ndarray):
|
50 |
-
camera_matrix = camera_matrix.reshape(-1, 4, 4)
|
51 |
-
translation = camera_matrix[:, :3, 3]
|
52 |
-
translation = translation / (
|
53 |
-
np.linalg.norm(translation, axis=1, keepdims=True) + 1e-8
|
54 |
-
)
|
55 |
-
camera_matrix[:, :3, 3] = translation
|
56 |
-
else:
|
57 |
-
camera_matrix = camera_matrix.reshape(-1, 4, 4)
|
58 |
-
translation = camera_matrix[:, :3, 3]
|
59 |
-
translation = translation / (
|
60 |
-
torch.norm(translation, dim=1, keepdim=True) + 1e-8
|
61 |
-
)
|
62 |
-
camera_matrix[:, :3, 3] = translation
|
63 |
-
return camera_matrix.reshape(-1, 16)
|
64 |
-
|
65 |
-
|
66 |
-
def get_camera(
|
67 |
-
num_frames,
|
68 |
-
elevation=15,
|
69 |
-
azimuth_start=0,
|
70 |
-
azimuth_span=360,
|
71 |
-
blender_coord=True,
|
72 |
-
extra_view=False,
|
73 |
-
):
|
74 |
-
angle_gap = azimuth_span / num_frames
|
75 |
-
cameras = []
|
76 |
-
for azimuth in np.arange(azimuth_start, azimuth_span + azimuth_start, angle_gap):
|
77 |
-
camera_matrix = create_camera_to_world_matrix(elevation, azimuth)
|
78 |
-
if blender_coord:
|
79 |
-
camera_matrix = convert_opengl_to_blender(camera_matrix)
|
80 |
-
cameras.append(camera_matrix.flatten())
|
81 |
-
|
82 |
-
if extra_view:
|
83 |
-
dim = len(cameras[0])
|
84 |
-
cameras.append(np.zeros(dim))
|
85 |
-
return torch.tensor(np.stack(cameras, 0)).float()
|
86 |
-
|
87 |
-
|
88 |
-
def get_camera_for_index(data_index):
|
89 |
-
"""
|
90 |
-
按照当前我们的数据格式, 以000为正对我们的情况:
|
91 |
-
000是正面, ev: 0, azimuth: 0
|
92 |
-
001是左边, ev: 0, azimuth: -90
|
93 |
-
002是下面, ev: -90, azimuth: 0
|
94 |
-
003是背面, ev: 0, azimuth: 180
|
95 |
-
004是右边, ev: 0, azimuth: 90
|
96 |
-
005是上面, ev: 90, azimuth: 0
|
97 |
-
"""
|
98 |
-
params = [(0, 0), (0, -90), (-90, 0), (0, 180), (0, 90), (90, 0)]
|
99 |
-
return get_camera(1, *params[data_index])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apps/third_party/CRM/imagedream/configs/sd_v2_base_ipmv.yaml
DELETED
@@ -1,61 +0,0 @@
|
|
1 |
-
model:
|
2 |
-
target: imagedream.ldm.interface.LatentDiffusionInterface
|
3 |
-
params:
|
4 |
-
linear_start: 0.00085
|
5 |
-
linear_end: 0.0120
|
6 |
-
timesteps: 1000
|
7 |
-
scale_factor: 0.18215
|
8 |
-
parameterization: "eps"
|
9 |
-
|
10 |
-
unet_config:
|
11 |
-
target: imagedream.ldm.modules.diffusionmodules.openaimodel.MultiViewUNetModel
|
12 |
-
params:
|
13 |
-
image_size: 32 # unused
|
14 |
-
in_channels: 4
|
15 |
-
out_channels: 4
|
16 |
-
model_channels: 320
|
17 |
-
attention_resolutions: [ 4, 2, 1 ]
|
18 |
-
num_res_blocks: 2
|
19 |
-
channel_mult: [ 1, 2, 4, 4 ]
|
20 |
-
num_head_channels: 64 # need to fix for flash-attn
|
21 |
-
use_spatial_transformer: True
|
22 |
-
use_linear_in_transformer: True
|
23 |
-
transformer_depth: 1
|
24 |
-
context_dim: 1024
|
25 |
-
use_checkpoint: False
|
26 |
-
legacy: False
|
27 |
-
camera_dim: 16
|
28 |
-
with_ip: True
|
29 |
-
ip_dim: 16 # ip token length
|
30 |
-
ip_mode: "local_resample"
|
31 |
-
|
32 |
-
vae_config:
|
33 |
-
target: imagedream.ldm.models.autoencoder.AutoencoderKL
|
34 |
-
params:
|
35 |
-
embed_dim: 4
|
36 |
-
monitor: val/rec_loss
|
37 |
-
ddconfig:
|
38 |
-
#attn_type: "vanilla-xformers"
|
39 |
-
double_z: true
|
40 |
-
z_channels: 4
|
41 |
-
resolution: 256
|
42 |
-
in_channels: 3
|
43 |
-
out_ch: 3
|
44 |
-
ch: 128
|
45 |
-
ch_mult:
|
46 |
-
- 1
|
47 |
-
- 2
|
48 |
-
- 4
|
49 |
-
- 4
|
50 |
-
num_res_blocks: 2
|
51 |
-
attn_resolutions: []
|
52 |
-
dropout: 0.0
|
53 |
-
lossconfig:
|
54 |
-
target: torch.nn.Identity
|
55 |
-
|
56 |
-
clip_config:
|
57 |
-
target: imagedream.ldm.modules.encoders.modules.FrozenOpenCLIPEmbedder
|
58 |
-
params:
|
59 |
-
freeze: True
|
60 |
-
layer: "penultimate"
|
61 |
-
ip_mode: "local_resample"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
apps/third_party/CRM/imagedream/configs/sd_v2_base_ipmv_ch8.yaml
DELETED
@@ -1,61 +0,0 @@
|
|
1 |
-
model:
|
2 |
-
target: imagedream.ldm.interface.LatentDiffusionInterface
|
3 |
-
params:
|
4 |
-
linear_start: 0.00085
|
5 |
-
linear_end: 0.0120
|
6 |
-
timesteps: 1000
|
7 |
-
scale_factor: 0.18215
|
8 |
-
parameterization: "eps"
|
9 |
-
|
10 |
-
unet_config:
|
11 |
-
target: imagedream.ldm.modules.diffusionmodules.openaimodel.MultiViewUNetModel
|
12 |
-
params:
|
13 |
-
image_size: 32 # unused
|
14 |
-
in_channels: 8
|
15 |
-
out_channels: 8
|
16 |
-
model_channels: 320
|
17 |
-
attention_resolutions: [ 4, 2, 1 ]
|
18 |
-
num_res_blocks: 2
|
19 |
-
channel_mult: [ 1, 2, 4, 4 ]
|
20 |
-
num_head_channels: 64 # need to fix for flash-attn
|
21 |
-
use_spatial_transformer: True
|
22 |
-
use_linear_in_transformer: True
|
23 |
-
transformer_depth: 1
|
24 |
-
context_dim: 1024
|
25 |
-
use_checkpoint: False
|
26 |
-
legacy: False
|
27 |
-
camera_dim: 16
|
28 |
-
with_ip: True
|
29 |
-
ip_dim: 16 # ip token length
|
30 |
-
ip_mode: "local_resample"
|
31 |
-
|
32 |
-
vae_config:
|
33 |
-
target: imagedream.ldm.models.autoencoder.AutoencoderKL
|
34 |
-
params:
|
35 |
-
embed_dim: 4
|
36 |
-
monitor: val/rec_loss
|
37 |
-
ddconfig:
|
38 |
-
#attn_type: "vanilla-xformers"
|
39 |
-
double_z: true
|
40 |
-
z_channels: 4
|
41 |
-
resolution: 256
|
42 |
-
in_channels: 3
|
43 |
-
out_ch: 3
|
44 |
-
ch: 128
|
45 |
-
ch_mult:
|
46 |
-
- 1
|
47 |
-
- 2
|
48 |
-
- 4
|
49 |
-
- 4
|
50 |
-
num_res_blocks: 2
|
51 |
-
attn_resolutions: []
|
52 |
-
dropout: 0.0
|
53 |
-
lossconfig:
|
54 |
-
target: torch.nn.Identity
|
55 |
-
|
56 |
-
clip_config:
|
57 |
-
target: imagedream.ldm.modules.encoders.modules.FrozenOpenCLIPEmbedder
|
58 |
-
params:
|
59 |
-
freeze: True
|
60 |
-
layer: "penultimate"
|
61 |
-
ip_mode: "local_resample"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|