Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,8 @@ import numpy as np
|
|
| 4 |
import cv2
|
| 5 |
from PIL import Image
|
| 6 |
import tempfile # For creating temporary video files
|
| 7 |
-
import os #
|
|
|
|
| 8 |
|
| 9 |
# Marigold specific imports
|
| 10 |
from diffusers import MarigoldDepthPipeline, DDIMScheduler
|
|
@@ -27,13 +28,16 @@ try:
|
|
| 27 |
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
|
| 28 |
pipe = pipe.to(device=device, dtype=dtype)
|
| 29 |
|
| 30 |
-
# Enable xformers for memory-efficient attention
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
print(f"MarigoldDepthPipeline loaded successfully from {CHECKPOINT} on {device}.")
|
| 39 |
except Exception as e:
|
|
|
|
| 4 |
import cv2
|
| 5 |
from PIL import Image
|
| 6 |
import tempfile # For creating temporary video files
|
| 7 |
+
import os # Import the 'os' module
|
| 8 |
+
import accelerate # Import accelerate for better memory management (recommended)
|
| 9 |
|
| 10 |
# Marigold specific imports
|
| 11 |
from diffusers import MarigoldDepthPipeline, DDIMScheduler
|
|
|
|
| 28 |
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
|
| 29 |
pipe = pipe.to(device=device, dtype=dtype)
|
| 30 |
|
| 31 |
+
# Enable xformers for memory-efficient attention ONLY IF CUDA is available
|
| 32 |
+
if torch.cuda.is_available():
|
| 33 |
+
try:
|
| 34 |
+
import xformers
|
| 35 |
+
pipe.enable_xformers_memory_efficient_attention()
|
| 36 |
+
print("xFormers enabled for Marigold pipeline.")
|
| 37 |
+
except ImportError:
|
| 38 |
+
print("xFormers not found, running without memory-efficient attention (on GPU).")
|
| 39 |
+
else:
|
| 40 |
+
print("Running on CPU or MPS. xFormers memory-efficient attention is not applicable.")
|
| 41 |
|
| 42 |
print(f"MarigoldDepthPipeline loaded successfully from {CHECKPOINT} on {device}.")
|
| 43 |
except Exception as e:
|