ashawkey hysts HF staff commited on
Commit
c0afa50
1 Parent(s): ce24b70

- Update for ZeroGPU (91189e1bee8b4418409045f231a721b869fd024a)


Co-authored-by: hysts <hysts@users.noreply.huggingface.co>

.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.whl filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -4,7 +4,8 @@ emoji: 🦀
4
  colorFrom: red
5
  colorTo: indigo
6
  sdk: gradio
7
- sdk_version: 4.17.0
 
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
4
  colorFrom: red
5
  colorTo: indigo
6
  sdk: gradio
7
+ sdk_version: 4.20.1
8
+ python_version: 3.10.13
9
  app_file: app.py
10
  pinned: false
11
  license: mit
app.py CHANGED
@@ -1,4 +1,6 @@
1
  import os
 
 
2
  import tyro
3
  import imageio
4
  import numpy as np
@@ -15,8 +17,7 @@ import gradio as gr
15
  from huggingface_hub import hf_hub_download
16
  ckpt_path = hf_hub_download(repo_id="ashawkey/LGM", filename="model_fp16.safetensors")
17
 
18
- # NOTE: no -e... else it's not working!
19
- os.system("pip install ./diff-gaussian-rasterization")
20
 
21
  import kiui
22
  from kiui.op import recenter
@@ -66,7 +67,7 @@ model = model.half().to(device)
66
  model.eval()
67
 
68
  tan_half_fov = np.tan(0.5 * np.deg2rad(opt.fovy))
69
- proj_matrix = torch.zeros(4, 4, dtype=torch.float32, device=device)
70
  proj_matrix[0, 0] = 1 / tan_half_fov
71
  proj_matrix[1, 1] = 1 / tan_half_fov
72
  proj_matrix[2, 2] = (opt.zfar + opt.znear) / (opt.zfar - opt.znear)
@@ -127,7 +128,7 @@ def process(input_image, prompt, prompt_neg='', input_elevation=0, input_num_ste
127
  image = image.astype(np.float32) / 255.0
128
  image = image[..., :3] * image[..., 3:4] + (1 - image[..., 3:4])
129
  mv_image = pipe_image(prompt, image, negative_prompt=prompt_neg, num_inference_steps=input_num_steps, guidance_scale=5.0, elevation=input_elevation)
130
-
131
  mv_image_grid = np.concatenate([
132
  np.concatenate([mv_image[1], mv_image[2]], axis=1),
133
  np.concatenate([mv_image[3], mv_image[0]], axis=1),
@@ -146,21 +147,21 @@ def process(input_image, prompt, prompt_neg='', input_elevation=0, input_num_ste
146
  with torch.autocast(device_type='cuda', dtype=torch.float16):
147
  # generate gaussians
148
  gaussians = model.forward_gaussians(input_image)
149
-
150
  # save gaussians
151
  model.gs.save_ply(gaussians, output_ply_path)
152
-
153
- # render 360 video
154
  images = []
155
  elevation = 0
156
  if opt.fancy_video:
157
  azimuth = np.arange(0, 720, 4, dtype=np.int32)
158
  for azi in tqdm.tqdm(azimuth):
159
-
160
  cam_poses = torch.from_numpy(orbit_camera(elevation, azi, radius=opt.cam_radius, opengl=True)).unsqueeze(0).to(device)
161
 
162
  cam_poses[:, :3, 1:3] *= -1 # invert up & forward direction
163
-
164
  # cameras needed by gaussian rasterizer
165
  cam_view = torch.inverse(cam_poses).transpose(1, 2) # [V, 4, 4]
166
  cam_view_proj = cam_view @ proj_matrix # [V, 4, 4]
@@ -173,11 +174,11 @@ def process(input_image, prompt, prompt_neg='', input_elevation=0, input_num_ste
173
  else:
174
  azimuth = np.arange(0, 360, 2, dtype=np.int32)
175
  for azi in tqdm.tqdm(azimuth):
176
-
177
  cam_poses = torch.from_numpy(orbit_camera(elevation, azi, radius=opt.cam_radius, opengl=True)).unsqueeze(0).to(device)
178
 
179
  cam_poses[:, :3, 1:3] *= -1 # invert up & forward direction
180
-
181
  # cameras needed by gaussian rasterizer
182
  cam_view = torch.inverse(cam_poses).transpose(1, 2) # [V, 4, 4]
183
  cam_view_proj = cam_view @ proj_matrix # [V, 4, 4]
@@ -201,7 +202,7 @@ _DESCRIPTION = '''
201
  <a style="display:inline-block; margin-left: .5em" href="https://github.com/3DTopia/LGM"><img src='https://img.shields.io/github/stars/3DTopia/LGM?style=social'/></a>
202
  </div>
203
 
204
- * Input can be only text, only image, or both image and text.
205
  * Output is a `ply` file containing the 3D Gaussians, please check our [repo](https://github.com/3DTopia/LGM/blob/main/readme.md) for visualization and mesh conversion.
206
  * If you find the output unsatisfying, try using different seeds!
207
  '''
@@ -212,7 +213,7 @@ with block:
212
  with gr.Column(scale=1):
213
  gr.Markdown('# ' + _TITLE)
214
  gr.Markdown(_DESCRIPTION)
215
-
216
  with gr.Row(variant='panel'):
217
  with gr.Column(scale=1):
218
  # input image
@@ -230,7 +231,7 @@ with block:
230
  # gen button
231
  button_gen = gr.Button("Generate")
232
 
233
-
234
  with gr.Column(scale=1):
235
  with gr.Tab("Video"):
236
  # final video results
@@ -242,7 +243,7 @@ with block:
242
  output_image = gr.Image(interactive=False, show_label=False)
243
 
244
  button_gen.click(process, inputs=[input_image, input_text, input_neg_text, input_elevation, input_num_steps, input_seed], outputs=[output_image, output_video, output_file])
245
-
246
  gr.Examples(
247
  examples=[
248
  "data_test/frog_sweater.jpg",
@@ -275,5 +276,5 @@ with block:
275
  cache_examples=True,
276
  label='Text-to-3D Examples'
277
  )
278
-
279
- block.launch()
 
1
  import os
2
+ import shlex
3
+ import subprocess
4
  import tyro
5
  import imageio
6
  import numpy as np
 
17
  from huggingface_hub import hf_hub_download
18
  ckpt_path = hf_hub_download(repo_id="ashawkey/LGM", filename="model_fp16.safetensors")
19
 
20
+ subprocess.run(shlex.split("pip install wheel/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.whl"))
 
21
 
22
  import kiui
23
  from kiui.op import recenter
 
67
  model.eval()
68
 
69
  tan_half_fov = np.tan(0.5 * np.deg2rad(opt.fovy))
70
+ proj_matrix = torch.zeros(4, 4, dtype=torch.float32).to(device)
71
  proj_matrix[0, 0] = 1 / tan_half_fov
72
  proj_matrix[1, 1] = 1 / tan_half_fov
73
  proj_matrix[2, 2] = (opt.zfar + opt.znear) / (opt.zfar - opt.znear)
 
128
  image = image.astype(np.float32) / 255.0
129
  image = image[..., :3] * image[..., 3:4] + (1 - image[..., 3:4])
130
  mv_image = pipe_image(prompt, image, negative_prompt=prompt_neg, num_inference_steps=input_num_steps, guidance_scale=5.0, elevation=input_elevation)
131
+
132
  mv_image_grid = np.concatenate([
133
  np.concatenate([mv_image[1], mv_image[2]], axis=1),
134
  np.concatenate([mv_image[3], mv_image[0]], axis=1),
 
147
  with torch.autocast(device_type='cuda', dtype=torch.float16):
148
  # generate gaussians
149
  gaussians = model.forward_gaussians(input_image)
150
+
151
  # save gaussians
152
  model.gs.save_ply(gaussians, output_ply_path)
153
+
154
+ # render 360 video
155
  images = []
156
  elevation = 0
157
  if opt.fancy_video:
158
  azimuth = np.arange(0, 720, 4, dtype=np.int32)
159
  for azi in tqdm.tqdm(azimuth):
160
+
161
  cam_poses = torch.from_numpy(orbit_camera(elevation, azi, radius=opt.cam_radius, opengl=True)).unsqueeze(0).to(device)
162
 
163
  cam_poses[:, :3, 1:3] *= -1 # invert up & forward direction
164
+
165
  # cameras needed by gaussian rasterizer
166
  cam_view = torch.inverse(cam_poses).transpose(1, 2) # [V, 4, 4]
167
  cam_view_proj = cam_view @ proj_matrix # [V, 4, 4]
 
174
  else:
175
  azimuth = np.arange(0, 360, 2, dtype=np.int32)
176
  for azi in tqdm.tqdm(azimuth):
177
+
178
  cam_poses = torch.from_numpy(orbit_camera(elevation, azi, radius=opt.cam_radius, opengl=True)).unsqueeze(0).to(device)
179
 
180
  cam_poses[:, :3, 1:3] *= -1 # invert up & forward direction
181
+
182
  # cameras needed by gaussian rasterizer
183
  cam_view = torch.inverse(cam_poses).transpose(1, 2) # [V, 4, 4]
184
  cam_view_proj = cam_view @ proj_matrix # [V, 4, 4]
 
202
  <a style="display:inline-block; margin-left: .5em" href="https://github.com/3DTopia/LGM"><img src='https://img.shields.io/github/stars/3DTopia/LGM?style=social'/></a>
203
  </div>
204
 
205
+ * Input can be only text, only image, or both image and text.
206
  * Output is a `ply` file containing the 3D Gaussians, please check our [repo](https://github.com/3DTopia/LGM/blob/main/readme.md) for visualization and mesh conversion.
207
  * If you find the output unsatisfying, try using different seeds!
208
  '''
 
213
  with gr.Column(scale=1):
214
  gr.Markdown('# ' + _TITLE)
215
  gr.Markdown(_DESCRIPTION)
216
+
217
  with gr.Row(variant='panel'):
218
  with gr.Column(scale=1):
219
  # input image
 
231
  # gen button
232
  button_gen = gr.Button("Generate")
233
 
234
+
235
  with gr.Column(scale=1):
236
  with gr.Tab("Video"):
237
  # final video results
 
243
  output_image = gr.Image(interactive=False, show_label=False)
244
 
245
  button_gen.click(process, inputs=[input_image, input_text, input_neg_text, input_elevation, input_num_steps, input_seed], outputs=[output_image, output_video, output_file])
246
+
247
  gr.Examples(
248
  examples=[
249
  "data_test/frog_sweater.jpg",
 
276
  cache_examples=True,
277
  label='Text-to-3D Examples'
278
  )
279
+
280
+ block.launch()
requirements.txt CHANGED
@@ -1,4 +1,3 @@
1
- --extra-index-url https://download.pytorch.org/whl/cu118
2
  torch==2.0.0
3
  xformers
4
 
@@ -28,4 +27,4 @@ trimesh
28
  kiui >= 0.2.3
29
  xatlas
30
  roma
31
- plyfile
 
 
1
  torch==2.0.0
2
  xformers
3
 
 
27
  kiui >= 0.2.3
28
  xatlas
29
  roma
30
+ plyfile
wheel/diff_gaussian_rasterization-0.0.0-cp310-cp310-linux_x86_64.whl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:42bf718442ba764469170abc09d99a70b7c1d891dc290f2e1247db09c95a0e88
3
+ size 3021758