Spaces:
Running on Zero
Running on Zero
fix: Make `sharp_linalg.rotation_matrices_from_quaternions` robust to empty tensor inputs.
Browse files- model_utils.py +11 -0
model_utils.py
CHANGED
|
@@ -37,6 +37,17 @@ from sharp.cli.predict import DEFAULT_MODEL_URL, predict_image
|
|
| 37 |
from sharp.models import PredictorParams, create_predictor
|
| 38 |
from sharp.utils import io
|
| 39 |
from sharp.utils.gaussians import save_ply
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
# -----------------------------------------------------------------------------
|
| 42 |
# Helpers
|
|
|
|
| 37 |
from sharp.models import PredictorParams, create_predictor
|
| 38 |
from sharp.utils import io
|
| 39 |
from sharp.utils.gaussians import save_ply
|
| 40 |
+
from sharp.utils import linalg as sharp_linalg
|
| 41 |
+
|
| 42 |
+
_orig = sharp_linalg.rotation_matrices_from_quaternions
|
| 43 |
+
|
| 44 |
+
def _safe_rotation_matrices_from_quaternions(quaternions: torch.Tensor) -> torch.Tensor:
|
| 45 |
+
# Handles shape (..., 4)
|
| 46 |
+
if quaternions.numel() == 0:
|
| 47 |
+
return quaternions.new_empty((*quaternions.shape[:-1], 3, 3))
|
| 48 |
+
return _orig(quaternions.contiguous())
|
| 49 |
+
|
| 50 |
+
sharp_linalg.rotation_matrices_from_quaternions = _safe_rotation_matrices_from_quaternions
|
| 51 |
|
| 52 |
# -----------------------------------------------------------------------------
|
| 53 |
# Helpers
|