Spaces:
Sleeping
Sleeping
Georg commited on
Commit ·
96b4daf
1
Parent(s): c23b196
Optimized Docker build to fix OOM errors
Browse files- Dockerfile +2 -1
- app.py +8 -1
- estimator.py +10 -5
Dockerfile
CHANGED
|
@@ -7,7 +7,8 @@ ENV FOUNDATIONPOSE_MODEL_REPO=gpue/foundationpose-weights
|
|
| 7 |
ENV USE_REAL_MODEL=true
|
| 8 |
|
| 9 |
# Ensure NumPy 1.x for CUDA extension compatibility
|
| 10 |
-
RUN pip install --no-cache-dir "numpy<2" transformers
|
|
|
|
| 11 |
|
| 12 |
# Set MAX_JOBS=1 BEFORE any CUDA compilation to limit memory usage
|
| 13 |
ENV MAX_JOBS=1
|
|
|
|
| 7 |
ENV USE_REAL_MODEL=true
|
| 8 |
|
| 9 |
# Ensure NumPy 1.x for CUDA extension compatibility
|
| 10 |
+
RUN pip install --no-cache-dir "numpy<2" transformers \
|
| 11 |
+
&& pip install --no-cache-dir pytorch3d -f https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/py310_cu118_pyt210/download.html
|
| 12 |
|
| 13 |
# Set MAX_JOBS=1 BEFORE any CUDA compilation to limit memory usage
|
| 14 |
ENV MAX_JOBS=1
|
app.py
CHANGED
|
@@ -75,6 +75,10 @@ logging.basicConfig(
|
|
| 75 |
)
|
| 76 |
logger = logging.getLogger(__name__)
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
# Always use real FoundationPose model
|
| 79 |
USE_REAL_MODEL = True
|
| 80 |
|
|
@@ -110,7 +114,10 @@ class FoundationPoseInference:
|
|
| 110 |
device=str(self.device),
|
| 111 |
weights_dir="weights"
|
| 112 |
)
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
except Exception as e:
|
| 116 |
logger.error(f"Failed to initialize real model: {e}", exc_info=True)
|
|
|
|
| 75 |
)
|
| 76 |
logger = logging.getLogger(__name__)
|
| 77 |
|
| 78 |
+
# Ensure OMP_NUM_THREADS is a valid integer to avoid libgomp warnings
|
| 79 |
+
if not os.environ.get("OMP_NUM_THREADS", "").isdigit():
|
| 80 |
+
os.environ["OMP_NUM_THREADS"] = "1"
|
| 81 |
+
|
| 82 |
# Always use real FoundationPose model
|
| 83 |
USE_REAL_MODEL = True
|
| 84 |
|
|
|
|
| 114 |
device=str(self.device),
|
| 115 |
weights_dir="weights"
|
| 116 |
)
|
| 117 |
+
if getattr(self.model, "available", True):
|
| 118 |
+
logger.info("✓ Real FoundationPose model initialized successfully")
|
| 119 |
+
else:
|
| 120 |
+
raise RuntimeError("FoundationPose dependencies missing")
|
| 121 |
|
| 122 |
except Exception as e:
|
| 123 |
logger.error(f"Failed to initialize real model: {e}", exc_info=True)
|
estimator.py
CHANGED
|
@@ -31,6 +31,7 @@ try:
|
|
| 31 |
except ImportError as e:
|
| 32 |
logger.warning(f"FoundationPose modules not available: {e}")
|
| 33 |
FOUNDATIONPOSE_AVAILABLE = False
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
def generate_naive_mask(
|
|
@@ -82,6 +83,7 @@ class FoundationPoseEstimator:
|
|
| 82 |
self.scorer = None
|
| 83 |
self.refiner = None
|
| 84 |
self.glctx = None
|
|
|
|
| 85 |
|
| 86 |
# Check if FoundationPose is available
|
| 87 |
if not FOUNDATIONPOSE_ROOT.exists():
|
|
@@ -124,11 +126,14 @@ class FoundationPoseEstimator:
|
|
| 124 |
# Load mesh if provided
|
| 125 |
mesh = None
|
| 126 |
if mesh_path and Path(mesh_path).exists():
|
| 127 |
-
|
| 128 |
-
mesh
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
# Store object registration
|
| 134 |
self.registered_objects[object_id] = {
|
|
|
|
| 31 |
except ImportError as e:
|
| 32 |
logger.warning(f"FoundationPose modules not available: {e}")
|
| 33 |
FOUNDATIONPOSE_AVAILABLE = False
|
| 34 |
+
trimesh = None
|
| 35 |
|
| 36 |
|
| 37 |
def generate_naive_mask(
|
|
|
|
| 83 |
self.scorer = None
|
| 84 |
self.refiner = None
|
| 85 |
self.glctx = None
|
| 86 |
+
self.available = FOUNDATIONPOSE_AVAILABLE
|
| 87 |
|
| 88 |
# Check if FoundationPose is available
|
| 89 |
if not FOUNDATIONPOSE_ROOT.exists():
|
|
|
|
| 126 |
# Load mesh if provided
|
| 127 |
mesh = None
|
| 128 |
if mesh_path and Path(mesh_path).exists():
|
| 129 |
+
if trimesh is None:
|
| 130 |
+
logger.warning("trimesh not available, skipping mesh load")
|
| 131 |
+
else:
|
| 132 |
+
try:
|
| 133 |
+
mesh = trimesh.load(mesh_path)
|
| 134 |
+
logger.info(f"Loaded mesh for '{object_id}' from {mesh_path}")
|
| 135 |
+
except Exception as e:
|
| 136 |
+
logger.warning(f"Failed to load mesh: {e}")
|
| 137 |
|
| 138 |
# Store object registration
|
| 139 |
self.registered_objects[object_id] = {
|