CazC commited on
Commit
3aa18cd
·
verified ·
1 Parent(s): daca4d1

Update TripoSR/obj_gen.py

Browse files
Files changed (1) hide show
  1. TripoSR/obj_gen.py +14 -10
TripoSR/obj_gen.py CHANGED
@@ -13,13 +13,12 @@ from tsr.system import TSR
13
  from tsr.utils import remove_background, resize_foreground, to_gradio_3d_orientation
14
 
15
  import argparse
16
- # from dotenv import load_dotenv
17
 
18
- # load_dotenv()
19
 
20
-
21
-
22
- device = "cpu"
 
23
 
24
  model = TSR.from_pretrained(
25
  "stabilityai/TripoSR",
@@ -73,11 +72,16 @@ def run_example(image_pil):
73
  return preprocessed, mesh_name_obj, mesh_name_glb
74
 
75
  def generate_obj_from_image(image_pil, path="output.obj"):
76
- # Preprocess the image without removing the background and with a foreground ratio of 0.9
77
- preprocessed = preprocess(image_pil, True, 0.9)
78
-
79
- # Generate the mesh and get the paths to the .obj and .glb files
80
- mesh_paths = generate(preprocessed, 256, ["obj"], path)
 
 
 
 
 
81
 
82
  # Return the path to the .obj file
83
  return mesh_paths[0]
 
13
  from tsr.utils import remove_background, resize_foreground, to_gradio_3d_orientation
14
 
15
  import argparse
 
16
 
 
17
 
18
+ if torch.cuda.is_available():
19
+ device = "cuda:0"
20
+ else:
21
+ device = "cpu"
22
 
23
  model = TSR.from_pretrained(
24
  "stabilityai/TripoSR",
 
72
  return preprocessed, mesh_name_obj, mesh_name_glb
73
 
74
  def generate_obj_from_image(image_pil, path="output.obj"):
75
+ try:
76
+ # Preprocess the image without removing the background and with a foreground ratio of 0.9
77
+ print("Preprocessing image")
78
+ preprocessed = preprocess(image_pil, True, 0.9)
79
+ print("Generating mesh")
80
+ # Generate the mesh and get the paths to the .obj and .glb files
81
+ mesh_paths = generate(preprocessed, 256, ["obj"], path)
82
+ except Exception as e:
83
+ print(f"Error generating mesh: {e}")
84
+ return None
85
 
86
  # Return the path to the .obj file
87
  return mesh_paths[0]