gusgeneris commited on
Commit
c24da45
1 Parent(s): 6bf025f
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitignore +155 -0
  2. LICENSE +21 -0
  3. README.md +85 -12
  4. app.py +228 -0
  5. configs/nf7_v3_SNR_rd_size_stroke.yaml +21 -0
  6. configs/specs_objaverse_total.json +57 -0
  7. configs/stage2-v2-snr.yaml +25 -0
  8. examples/3D/345/215/241/351/200/232/347/213/227.webp +0 -0
  9. examples/astronaut.webp +0 -0
  10. examples/bulldog.webp +0 -0
  11. examples/ghost-eating-burger.webp +0 -0
  12. examples/kunkun.webp +0 -0
  13. examples//344/270/207/345/234/243/345/215/227/347/223/234.webp +0 -0
  14. examples//344/272/272/347/211/251/351/252/221/351/251/254.webp +0 -0
  15. examples//345/210/235/351/237/263/346/234/252/346/235/245/347/216/251/345/201/266.webp +0 -0
  16. examples//345/215/241/351/200/232/346/201/220/351/276/231.webp +0 -0
  17. examples//345/215/241/351/200/232/346/211/213/346/236/252/346/210/252/345/233/276.webp +0 -0
  18. examples//345/215/241/351/200/232/347/214/253.webp +0 -0
  19. examples//345/215/241/351/200/232/350/230/221/350/217/207/345/245/227/350/243/205.webp +0 -0
  20. examples//345/217/257/347/210/261/347/216/204/347/255/226.webp +0 -0
  21. examples//345/244/247/345/244/264/346/263/241/346/263/241/351/251/254/347/211/271.webp +0 -0
  22. examples//345/275/251/350/211/262/350/230/221/350/217/207.webp +0 -0
  23. examples//345/275/251/350/211/262/350/230/221/350/217/2072.webp +0 -0
  24. examples//346/201/220/351/276/231/345/245/227/350/243/205.webp +0 -0
  25. examples//346/211/213/345/212/236.webp +0 -0
  26. examples//346/234/272/346/242/260/347/213/227/350/243/201/345/210/207.webp +0 -0
  27. examples//346/236/227/345/205/213.webp +0 -0
  28. examples//346/244/215/347/211/2511.webp +0 -0
  29. examples//346/255/246/345/231/250-/345/211/221.webp +0 -0
  30. examples//346/257/233/347/272/277/350/241/243.webp +0 -0
  31. examples//346/265/267/351/276/237.webp +0 -0
  32. examples//347/214/253/344/272/272.webp +0 -0
  33. examples//347/214/253/345/244/264/351/271/260.webp +0 -0
  34. examples//347/216/251/345/205/267/345/205/224.webp +0 -0
  35. examples//347/216/251/345/205/267/347/206/212.webp +0 -0
  36. examples//347/216/251/345/205/267/347/214/252.webp +0 -0
  37. examples//347/216/253/347/221/260.webp +0 -0
  38. examples//347/232/256/345/215/241/344/270/230.webp +0 -0
  39. examples//347/232/256/351/236/213.webp +0 -0
  40. examples//347/237/263/345/244/264.webp +0 -0
  41. examples//347/237/263/345/244/264/345/223/206/345/225/246A/346/242/246.webp +0 -0
  42. examples//347/272/242/347/216/251/345/205/267/347/214/252.webp +0 -0
  43. examples//347/277/205/350/206/200/351/201/223/345/205/267.webp +0 -0
  44. examples//350/214/266/345/243/266.webp +0 -0
  45. examples//350/215/211/347/263/273/347/262/276/347/201/265.webp +0 -0
  46. examples//350/223/235/350/211/262/345/260/217/346/200/252/347/211/251.webp +0 -0
  47. examples//350/223/235/350/211/262/346/263/241/346/263/241/351/251/254/347/211/271.webp +0 -0
  48. examples//350/223/235/350/211/262/347/214/253.webp +0 -0
  49. examples//350/265/233/345/215/232/346/234/213/345/205/213-/347/224/267.webp +0 -0
  50. examples//350/267/257/347/201/257.webp +0 -0
.gitignore ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ out/
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.
README.md CHANGED
@@ -1,12 +1,85 @@
1
- ---
2
- title: 3dart
3
- emoji: 🚀
4
- colorFrom: red
5
- colorTo: pink
6
- sdk: gradio
7
- sdk_version: 4.43.0
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ```
app.py ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()
configs/nf7_v3_SNR_rd_size_stroke.yaml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
configs/specs_objaverse_total.json ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
configs/stage2-v2-snr.yaml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
examples/3D/345/215/241/351/200/232/347/213/227.webp ADDED
examples/astronaut.webp ADDED
examples/bulldog.webp ADDED
examples/ghost-eating-burger.webp ADDED
examples/kunkun.webp ADDED
examples//344/270/207/345/234/243/345/215/227/347/223/234.webp ADDED
examples//344/272/272/347/211/251/351/252/221/351/251/254.webp ADDED
examples//345/210/235/351/237/263/346/234/252/346/235/245/347/216/251/345/201/266.webp ADDED
examples//345/215/241/351/200/232/346/201/220/351/276/231.webp ADDED
examples//345/215/241/351/200/232/346/211/213/346/236/252/346/210/252/345/233/276.webp ADDED
examples//345/215/241/351/200/232/347/214/253.webp ADDED
examples//345/215/241/351/200/232/350/230/221/350/217/207/345/245/227/350/243/205.webp ADDED
examples//345/217/257/347/210/261/347/216/204/347/255/226.webp ADDED
examples//345/244/247/345/244/264/346/263/241/346/263/241/351/251/254/347/211/271.webp ADDED
examples//345/275/251/350/211/262/350/230/221/350/217/207.webp ADDED
examples//345/275/251/350/211/262/350/230/221/350/217/2072.webp ADDED
examples//346/201/220/351/276/231/345/245/227/350/243/205.webp ADDED
examples//346/211/213/345/212/236.webp ADDED
examples//346/234/272/346/242/260/347/213/227/350/243/201/345/210/207.webp ADDED
examples//346/236/227/345/205/213.webp ADDED
examples//346/244/215/347/211/2511.webp ADDED
examples//346/255/246/345/231/250-/345/211/221.webp ADDED
examples//346/257/233/347/272/277/350/241/243.webp ADDED
examples//346/265/267/351/276/237.webp ADDED
examples//347/214/253/344/272/272.webp ADDED
examples//347/214/253/345/244/264/351/271/260.webp ADDED
examples//347/216/251/345/205/267/345/205/224.webp ADDED
examples//347/216/251/345/205/267/347/206/212.webp ADDED
examples//347/216/251/345/205/267/347/214/252.webp ADDED
examples//347/216/253/347/221/260.webp ADDED
examples//347/232/256/345/215/241/344/270/230.webp ADDED
examples//347/232/256/351/236/213.webp ADDED
examples//347/237/263/345/244/264.webp ADDED
examples//347/237/263/345/244/264/345/223/206/345/225/246A/346/242/246.webp ADDED
examples//347/272/242/347/216/251/345/205/267/347/214/252.webp ADDED
examples//347/277/205/350/206/200/351/201/223/345/205/267.webp ADDED
examples//350/214/266/345/243/266.webp ADDED
examples//350/215/211/347/263/273/347/262/276/347/201/265.webp ADDED
examples//350/223/235/350/211/262/345/260/217/346/200/252/347/211/251.webp ADDED
examples//350/223/235/350/211/262/346/263/241/346/263/241/351/251/254/347/211/271.webp ADDED
examples//350/223/235/350/211/262/347/214/253.webp ADDED
examples//350/265/233/345/215/232/346/234/213/345/205/213-/347/224/267.webp ADDED
examples//350/267/257/347/201/257.webp ADDED