Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,8 +38,7 @@ def initialize_models(device):
|
|
| 38 |
print("Initializing models...")
|
| 39 |
# 3D ์์ฑ ํ์ดํ๋ผ์ธ
|
| 40 |
g.trellis_pipeline = TrellisImageTo3DPipeline.from_pretrained(
|
| 41 |
-
"JeffreyXiang/TRELLIS-image-large"
|
| 42 |
-
torch_dtype=torch.float32 # ๋ช
์์ ์ผ๋ก dtype ์ง์
|
| 43 |
)
|
| 44 |
|
| 45 |
# ์ด๋ฏธ์ง ์์ฑ ํ์ดํ๋ผ์ธ
|
|
@@ -78,15 +77,12 @@ torch.cuda.empty_cache()
|
|
| 78 |
torch.backends.cuda.matmul.allow_tf32 = True
|
| 79 |
torch.backends.cudnn.benchmark = True
|
| 80 |
|
| 81 |
-
# ํ๊ฒฝ ๋ณ์ ์ค์
|
| 82 |
# ํ๊ฒฝ ๋ณ์ ์ค์
|
| 83 |
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:512"
|
| 84 |
os.environ['SPCONV_ALGO'] = 'native'
|
| 85 |
os.environ['SPARSE_BACKEND'] = 'native'
|
| 86 |
os.environ['CUDA_LAUNCH_BLOCKING'] = '1'
|
| 87 |
-
os.environ['
|
| 88 |
-
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
|
| 89 |
-
os.environ['XFORMERS_FORCE_DISABLE_TRITON'] = '1' # xformers ๊ด๋ จ ์ค์ ์ถ๊ฐ
|
| 90 |
|
| 91 |
# CUDA ์ด๊ธฐํ ๋ฐฉ์ง
|
| 92 |
torch.set_grad_enabled(False)
|
|
@@ -217,47 +213,36 @@ def image_to_3d(trial_id: str, seed: int, randomize_seed: bool, ss_guidance_stre
|
|
| 217 |
image = Image.open(image_path)
|
| 218 |
print(f"Successfully loaded image with size: {image.size}")
|
| 219 |
|
| 220 |
-
#
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
"steps": slat_sampling_steps,
|
| 237 |
-
"cfg_strength": slat_guidance_strength,
|
| 238 |
-
},
|
| 239 |
-
)
|
| 240 |
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
finally:
|
| 252 |
-
# Move model back to CPU
|
| 253 |
-
g.trellis_pipeline.to("cpu")
|
| 254 |
-
torch.cuda.empty_cache()
|
| 255 |
|
| 256 |
except Exception as e:
|
| 257 |
print(f"Error in image_to_3d: {str(e)}")
|
| 258 |
-
if hasattr(g.trellis_pipeline, 'device') and g.trellis_pipeline.device.type == "cuda":
|
| 259 |
-
g.trellis_pipeline.to("cpu")
|
| 260 |
-
torch.cuda.empty_cache()
|
| 261 |
return None, None
|
| 262 |
|
| 263 |
|
|
|
|
| 38 |
print("Initializing models...")
|
| 39 |
# 3D ์์ฑ ํ์ดํ๋ผ์ธ
|
| 40 |
g.trellis_pipeline = TrellisImageTo3DPipeline.from_pretrained(
|
| 41 |
+
"JeffreyXiang/TRELLIS-image-large"
|
|
|
|
| 42 |
)
|
| 43 |
|
| 44 |
# ์ด๋ฏธ์ง ์์ฑ ํ์ดํ๋ผ์ธ
|
|
|
|
| 77 |
torch.backends.cuda.matmul.allow_tf32 = True
|
| 78 |
torch.backends.cudnn.benchmark = True
|
| 79 |
|
|
|
|
| 80 |
# ํ๊ฒฝ ๋ณ์ ์ค์
|
| 81 |
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:512"
|
| 82 |
os.environ['SPCONV_ALGO'] = 'native'
|
| 83 |
os.environ['SPARSE_BACKEND'] = 'native'
|
| 84 |
os.environ['CUDA_LAUNCH_BLOCKING'] = '1'
|
| 85 |
+
os.environ['XFORMERS_FORCE_DISABLE_TRITON'] = '1'
|
|
|
|
|
|
|
| 86 |
|
| 87 |
# CUDA ์ด๊ธฐํ ๋ฐฉ์ง
|
| 88 |
torch.set_grad_enabled(False)
|
|
|
|
| 213 |
image = Image.open(image_path)
|
| 214 |
print(f"Successfully loaded image with size: {image.size}")
|
| 215 |
|
| 216 |
+
# GPU ์์
์์
|
| 217 |
+
with torch.inference_mode():
|
| 218 |
+
outputs = g.trellis_pipeline.run(
|
| 219 |
+
image,
|
| 220 |
+
seed=seed,
|
| 221 |
+
formats=["gaussian", "mesh"],
|
| 222 |
+
preprocess_image=False,
|
| 223 |
+
sparse_structure_sampler_params={
|
| 224 |
+
"steps": ss_sampling_steps,
|
| 225 |
+
"cfg_strength": ss_guidance_strength,
|
| 226 |
+
},
|
| 227 |
+
slat_sampler_params={
|
| 228 |
+
"steps": slat_sampling_steps,
|
| 229 |
+
"cfg_strength": slat_guidance_strength,
|
| 230 |
+
},
|
| 231 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
|
| 233 |
+
video = render_utils.render_video(outputs['gaussian'][0], num_frames=120)['color']
|
| 234 |
+
video_geo = render_utils.render_video(outputs['mesh'][0], num_frames=120)['normal']
|
| 235 |
+
video = [np.concatenate([video[i], video_geo[i]], axis=1) for i in range(len(video))]
|
| 236 |
+
new_trial_id = str(uuid.uuid4())
|
| 237 |
+
video_path = f"{TMP_DIR}/{new_trial_id}.mp4"
|
| 238 |
+
os.makedirs(os.path.dirname(video_path), exist_ok=True)
|
| 239 |
+
imageio.mimsave(video_path, video, fps=15)
|
| 240 |
+
state = pack_state(outputs['gaussian'][0], outputs['mesh'][0], new_trial_id)
|
| 241 |
+
|
| 242 |
+
return state, video_path
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
|
| 244 |
except Exception as e:
|
| 245 |
print(f"Error in image_to_3d: {str(e)}")
|
|
|
|
|
|
|
|
|
|
| 246 |
return None, None
|
| 247 |
|
| 248 |
|