dmitriitochilkin commited on
Commit
b88f82b
1 Parent(s): a9e44d5

fix orientation, markdown

Browse files
Files changed (2) hide show
  1. app.py +10 -18
  2. tsr/utils.py +6 -16
app.py CHANGED
@@ -17,14 +17,13 @@ HF_TOKEN = os.getenv("HF_TOKEN")
17
 
18
  HEADER = """
19
  # TripoSR Demo
20
- <table>
21
- <tr>
22
  <td style="text-align: center;">
23
  <a href="https://stability.ai">
24
  <img src="https://images.squarespace-cdn.com/content/v1/6213c340453c3f502425776e/6c9c4c25-5410-4547-bc26-dc621cdacb25/Stability+AI+logo.png" width="200" height="40" />
25
  </a>
26
  </td>
27
- <td style="border-left: 1px solid #000; width: 1px;"></td>
28
  <td style="text-align: center;">
29
  <a href="https://www.tripo3d.ai">
30
  <img src="https://www.tripo3d.ai/logo.png" width="170" height="40" />
@@ -32,19 +31,17 @@ HEADER = """
32
  </td>
33
  </tr>
34
  </table>
35
-
36
- <table>
37
- <tr>
38
  <td style="text-align: center;">
39
- <a href="https://huggingface.co/stabilityai/TripoSR"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Model_Card-Huggingface-orange"></a>
40
  </td>
41
- <td style="border-left: 1px solid #000; width: 1px;"></td>
42
  <td style="text-align: center;">
43
- <a href="https://github.com/VAST-AI-Research/TripoSR"><img src="logos/github-mark-white.png" height="20"></a>
44
  </td>
45
- <td style="border-left: 1px solid #000; width: 1px;"></td>
46
- <td style="text-align: left;">
47
- <a href="https://github.com/VAST-AI-Research/TripoSR"><img src="https://img.shields.io/badge/arXiv-1234.56789-b31b1b.svg" height="20"></a>
48
  </td>
49
  </tr>
50
  </table>
@@ -101,7 +98,7 @@ def preprocess(input_image, do_remove_background, foreground_ratio):
101
  def generate(image):
102
  scene_codes = model(image, device=device)
103
  mesh = model.extract_mesh(scene_codes)[0]
104
- mesh.vertices = to_gradio_3d_orientation(mesh.vertices)
105
  mesh_path = tempfile.NamedTemporaryFile(suffix=".obj", delete=False)
106
  mesh.export(mesh_path.name)
107
  return mesh_path.name
@@ -144,11 +141,6 @@ with gr.Blocks() as demo:
144
  label="Output Model",
145
  interactive=False,
146
  )
147
- gr.Markdown(
148
- """
149
- Note: The model shown here will be flipped due to some visualization issues. Please download to get the correct result.
150
- """
151
- )
152
  with gr.Row(variant="panel"):
153
  gr.Examples(
154
  examples=[
 
17
 
18
  HEADER = """
19
  # TripoSR Demo
20
+ <table bgcolor="#1E2432" cellspacing="0" cellpadding="0" width="450">
21
+ <tr style="height:50px;">
22
  <td style="text-align: center;">
23
  <a href="https://stability.ai">
24
  <img src="https://images.squarespace-cdn.com/content/v1/6213c340453c3f502425776e/6c9c4c25-5410-4547-bc26-dc621cdacb25/Stability+AI+logo.png" width="200" height="40" />
25
  </a>
26
  </td>
 
27
  <td style="text-align: center;">
28
  <a href="https://www.tripo3d.ai">
29
  <img src="https://www.tripo3d.ai/logo.png" width="170" height="40" />
 
31
  </td>
32
  </tr>
33
  </table>
34
+ <table bgcolor="#1E2432" cellspacing="0" cellpadding="0" width="450">
35
+ <tr style="height:30px;">
 
36
  <td style="text-align: center;">
37
+ <a href="https://huggingface.co/stabilityai/TripoSR"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Model_Card-Huggingface-orange" height="20"></a>
38
  </td>
 
39
  <td style="text-align: center;">
40
+ <a href="https://github.com/VAST-AI-Research/TripoSR"><img src="https://postimage.me/images/2024/03/04/GitHub_Logo_White.png" width="100" height="20"></a>
41
  </td>
42
+ <td style="text-align: center; color: white;">
43
+ <!-- <a href="https://github.com/VAST-AI-Research/TripoSR"><img src="https://img.shields.io/badge/arXiv-1234.56789-b31b1b.svg" height="20"></a> -->
44
+ <a href="http://your-url.com"><b>[Tech Report pdf]</b></a>
45
  </td>
46
  </tr>
47
  </table>
 
98
  def generate(image):
99
  scene_codes = model(image, device=device)
100
  mesh = model.extract_mesh(scene_codes)[0]
101
+ mesh = to_gradio_3d_orientation(mesh)
102
  mesh_path = tempfile.NamedTemporaryFile(suffix=".obj", delete=False)
103
  mesh.export(mesh_path.name)
104
  return mesh_path.name
 
141
  label="Output Model",
142
  interactive=False,
143
  )
 
 
 
 
 
144
  with gr.Row(variant="panel"):
145
  gr.Examples(
146
  examples=[
tsr/utils.py CHANGED
@@ -11,6 +11,7 @@ import rembg
11
  import torch
12
  import torch.nn as nn
13
  import torch.nn.functional as F
 
14
  from omegaconf import DictConfig, OmegaConf
15
  from PIL import Image
16
 
@@ -474,19 +475,8 @@ def save_video(
474
  writer.close()
475
 
476
 
477
- _dir2vec = {
478
- "+x": np.array([1, 0, 0]),
479
- "+y": np.array([0, 1, 0]),
480
- "+z": np.array([0, 0, 1]),
481
- "-x": np.array([-1, 0, 0]),
482
- "-y": np.array([0, -1, 0]),
483
- "-z": np.array([0, 0, -1]),
484
- }
485
-
486
-
487
- def to_gradio_3d_orientation(vertices):
488
- z_, x_ = _dir2vec["+y"], _dir2vec["-z"]
489
- y_ = np.cross(z_, x_)
490
- std2mesh = np.stack([x_, y_, z_], axis=0).T
491
- vertices = np.dot(std2mesh, vertices.T).T
492
- return vertices
 
11
  import torch
12
  import torch.nn as nn
13
  import torch.nn.functional as F
14
+ import trimesh
15
  from omegaconf import DictConfig, OmegaConf
16
  from PIL import Image
17
 
 
475
  writer.close()
476
 
477
 
478
+ def to_gradio_3d_orientation(mesh):
479
+ mesh.apply_transform(trimesh.transformations.rotation_matrix(-np.pi/2, [1, 0, 0]))
480
+ mesh.apply_scale([1, 1, -1])
481
+ mesh.apply_transform(trimesh.transformations.rotation_matrix(np.pi/2, [0, 1, 0]))
482
+ return mesh