Spaces:
Paused
Paused
Upload pytorch3d_stub/pytorch3d/renderer/__init__.py with huggingface_hub
Browse files
pytorch3d_stub/pytorch3d/renderer/__init__.py
CHANGED
|
@@ -1,6 +1,21 @@
|
|
| 1 |
-
"""pytorch3d.renderer stub
|
| 2 |
import torch
|
| 3 |
import math
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
def look_at_view_transform(dist=1.0, elev=0.0, azim=0.0, degrees=True, eye=None,
|
|
@@ -11,23 +26,18 @@ def look_at_view_transform(dist=1.0, elev=0.0, azim=0.0, degrees=True, eye=None,
|
|
| 11 |
if eye.dim() == 1:
|
| 12 |
eye = eye.unsqueeze(0)
|
| 13 |
else:
|
| 14 |
-
if degrees
|
| 15 |
-
|
| 16 |
-
azim_r = math.radians(float(azim))
|
| 17 |
-
else:
|
| 18 |
-
elev_r, azim_r = float(elev), float(azim)
|
| 19 |
x = dist * math.cos(elev_r) * math.sin(azim_r)
|
| 20 |
y = dist * math.sin(elev_r)
|
| 21 |
z = dist * math.cos(elev_r) * math.cos(azim_r)
|
| 22 |
eye = torch.tensor([[x, y, z]], dtype=torch.float32, device=device)
|
| 23 |
if not isinstance(at, torch.Tensor):
|
| 24 |
at = torch.tensor(at, dtype=torch.float32, device=device)
|
| 25 |
-
if at.dim() == 1:
|
| 26 |
-
at = at.unsqueeze(0)
|
| 27 |
if not isinstance(up, torch.Tensor):
|
| 28 |
up = torch.tensor(up, dtype=torch.float32, device=device)
|
| 29 |
-
if up.dim() == 1:
|
| 30 |
-
up = up.unsqueeze(0)
|
| 31 |
z_axis = eye - at
|
| 32 |
z_axis = z_axis / z_axis.norm(dim=-1, keepdim=True).clamp(min=1e-8)
|
| 33 |
x_axis = torch.cross(up.expand_as(z_axis), z_axis, dim=-1)
|
|
@@ -38,8 +48,11 @@ def look_at_view_transform(dist=1.0, elev=0.0, azim=0.0, degrees=True, eye=None,
|
|
| 38 |
return R, T
|
| 39 |
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
class CamerasBase:
|
| 42 |
-
"""Base camera class stub."""
|
| 43 |
pass
|
| 44 |
|
| 45 |
|
|
@@ -53,24 +66,18 @@ class PerspectiveCameras(CamerasBase):
|
|
| 53 |
self.T = T if T is not None else torch.zeros(1, 3, device=device)
|
| 54 |
self.image_size = image_size
|
| 55 |
self.in_ndc = in_ndc
|
| 56 |
-
|
| 57 |
def to(self, device):
|
| 58 |
-
self.device = device
|
| 59 |
-
return self
|
| 60 |
|
| 61 |
|
| 62 |
class RasterizationSettings:
|
| 63 |
def __init__(self, image_size=256, blur_radius=0.0, faces_per_pixel=1, **kwargs):
|
| 64 |
-
self.image_size = image_size
|
| 65 |
-
self.blur_radius = blur_radius
|
| 66 |
-
self.faces_per_pixel = faces_per_pixel
|
| 67 |
|
| 68 |
|
| 69 |
class BlendParams:
|
| 70 |
def __init__(self, sigma=1e-4, gamma=1e-4, background_color=(0.0, 0.0, 0.0)):
|
| 71 |
-
self.sigma = sigma
|
| 72 |
-
self.gamma = gamma
|
| 73 |
-
self.background_color = background_color
|
| 74 |
|
| 75 |
|
| 76 |
class SoftSilhouetteShader:
|
|
@@ -81,116 +88,39 @@ class SoftSilhouetteShader:
|
|
| 81 |
class MeshRasterizer(torch.nn.Module):
|
| 82 |
def __init__(self, cameras=None, raster_settings=None):
|
| 83 |
super().__init__()
|
| 84 |
-
self.cameras = cameras
|
| 85 |
-
|
| 86 |
-
def forward(self, meshes, **kwargs):
|
| 87 |
raise NotImplementedError("MeshRasterizer stub")
|
| 88 |
|
| 89 |
|
| 90 |
class MeshRenderer(torch.nn.Module):
|
| 91 |
def __init__(self, rasterizer=None, shader=None):
|
| 92 |
super().__init__()
|
| 93 |
-
self.rasterizer = rasterizer
|
| 94 |
-
|
| 95 |
-
def forward(self, meshes, **kwargs):
|
| 96 |
raise NotImplementedError("MeshRenderer stub")
|
| 97 |
|
| 98 |
|
| 99 |
class TexturesVertex:
|
| 100 |
def __init__(self, verts_features=None):
|
| 101 |
self.verts_features_list = verts_features if isinstance(verts_features, list) else [verts_features]
|
| 102 |
-
def to(self, device):
|
| 103 |
-
return self
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
class HeterogeneousRayBundle:
|
| 107 |
-
"""Stub for HeterogeneousRayBundle (not used in inference)."""
|
| 108 |
-
pass
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
class RayBundle:
|
| 112 |
-
"""Stub for RayBundle (not used in inference)."""
|
| 113 |
-
def __init__(self, origins=None, directions=None, lengths=None, xys=None, **kwargs):
|
| 114 |
-
self.origins = origins
|
| 115 |
-
self.directions = directions
|
| 116 |
-
self.lengths = lengths
|
| 117 |
-
self.xys = xys
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
class PointsRasterizationSettings:
|
| 121 |
-
def __init__(self, **kwargs):
|
| 122 |
-
pass
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
class PointsRenderer:
|
| 126 |
-
def __init__(self, **kwargs):
|
| 127 |
-
pass
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
class PointsRasterizer:
|
| 131 |
-
def __init__(self, **kwargs):
|
| 132 |
-
pass
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
class AlphaCompositor:
|
| 136 |
-
def __init__(self, **kwargs):
|
| 137 |
-
pass
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
class NormWeightedCompositor:
|
| 141 |
-
def __init__(self, **kwargs):
|
| 142 |
-
pass
|
| 143 |
|
| 144 |
|
| 145 |
class TexturesAtlas:
|
| 146 |
-
def __init__(self, atlas=None, **
|
| 147 |
-
|
| 148 |
-
def to(self, device):
|
| 149 |
-
return self
|
| 150 |
|
| 151 |
-
class TexturesUV:
|
| 152 |
-
def __init__(self, maps=None, faces_uvs=None, verts_uvs=None, **kwargs):
|
| 153 |
-
self.maps = maps
|
| 154 |
-
self.faces_uvs = faces_uvs
|
| 155 |
-
self.verts_uvs = verts_uvs
|
| 156 |
-
def to(self, device):
|
| 157 |
-
return self
|
| 158 |
-
|
| 159 |
-
class FoVPerspectiveCameras(CamerasBase):
|
| 160 |
-
def __init__(self, **kwargs):
|
| 161 |
-
pass
|
| 162 |
-
def to(self, device):
|
| 163 |
-
return self
|
| 164 |
|
| 165 |
-
class
|
| 166 |
-
def __init__(self, **
|
| 167 |
-
|
| 168 |
-
def to(self, device):
|
| 169 |
-
return self
|
| 170 |
-
|
| 171 |
-
class OrthographicCameras(CamerasBase):
|
| 172 |
-
def __init__(self, **kwargs):
|
| 173 |
-
pass
|
| 174 |
-
def to(self, device):
|
| 175 |
-
return self
|
| 176 |
-
|
| 177 |
-
class SoftPhongShader:
|
| 178 |
-
def __init__(self, **kwargs):
|
| 179 |
-
pass
|
| 180 |
|
| 181 |
-
class HardPhongShader:
|
| 182 |
-
def __init__(self, **kwargs):
|
| 183 |
-
pass
|
| 184 |
|
| 185 |
-
class
|
| 186 |
-
def __init__(self, **
|
| 187 |
-
pass
|
| 188 |
-
def to(self, device):
|
| 189 |
-
return self
|
| 190 |
|
| 191 |
-
class DirectionalLights:
|
| 192 |
-
def __init__(self, **kwargs):
|
| 193 |
-
pass
|
| 194 |
-
def to(self, device):
|
| 195 |
-
return self
|
| 196 |
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""pytorch3d.renderer stub with catch-all for missing attributes."""
|
| 2 |
import torch
|
| 3 |
import math
|
| 4 |
+
import warnings
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def __getattr__(name):
|
| 8 |
+
"""Catch-all: return a dummy class/function for any missing attribute."""
|
| 9 |
+
if name.startswith("_"):
|
| 10 |
+
raise AttributeError(name)
|
| 11 |
+
warnings.warn(f"pytorch3d.renderer stub: {name} not implemented, returning dummy", stacklevel=2)
|
| 12 |
+
class _Dummy:
|
| 13 |
+
def __init__(self, *a, **kw): pass
|
| 14 |
+
def __call__(self, *a, **kw): return None
|
| 15 |
+
def to(self, *a, **kw): return self
|
| 16 |
+
def forward(self, *a, **kw): return None
|
| 17 |
+
_Dummy.__name__ = _Dummy.__qualname__ = name
|
| 18 |
+
return _Dummy
|
| 19 |
|
| 20 |
|
| 21 |
def look_at_view_transform(dist=1.0, elev=0.0, azim=0.0, degrees=True, eye=None,
|
|
|
|
| 26 |
if eye.dim() == 1:
|
| 27 |
eye = eye.unsqueeze(0)
|
| 28 |
else:
|
| 29 |
+
elev_r = math.radians(float(elev)) if degrees else float(elev)
|
| 30 |
+
azim_r = math.radians(float(azim)) if degrees else float(azim)
|
|
|
|
|
|
|
|
|
|
| 31 |
x = dist * math.cos(elev_r) * math.sin(azim_r)
|
| 32 |
y = dist * math.sin(elev_r)
|
| 33 |
z = dist * math.cos(elev_r) * math.cos(azim_r)
|
| 34 |
eye = torch.tensor([[x, y, z]], dtype=torch.float32, device=device)
|
| 35 |
if not isinstance(at, torch.Tensor):
|
| 36 |
at = torch.tensor(at, dtype=torch.float32, device=device)
|
| 37 |
+
if at.dim() == 1: at = at.unsqueeze(0)
|
|
|
|
| 38 |
if not isinstance(up, torch.Tensor):
|
| 39 |
up = torch.tensor(up, dtype=torch.float32, device=device)
|
| 40 |
+
if up.dim() == 1: up = up.unsqueeze(0)
|
|
|
|
| 41 |
z_axis = eye - at
|
| 42 |
z_axis = z_axis / z_axis.norm(dim=-1, keepdim=True).clamp(min=1e-8)
|
| 43 |
x_axis = torch.cross(up.expand_as(z_axis), z_axis, dim=-1)
|
|
|
|
| 48 |
return R, T
|
| 49 |
|
| 50 |
|
| 51 |
+
def ray_bundle_to_ray_points(ray_bundle):
|
| 52 |
+
return None
|
| 53 |
+
|
| 54 |
+
|
| 55 |
class CamerasBase:
|
|
|
|
| 56 |
pass
|
| 57 |
|
| 58 |
|
|
|
|
| 66 |
self.T = T if T is not None else torch.zeros(1, 3, device=device)
|
| 67 |
self.image_size = image_size
|
| 68 |
self.in_ndc = in_ndc
|
|
|
|
| 69 |
def to(self, device):
|
| 70 |
+
self.device = device; return self
|
|
|
|
| 71 |
|
| 72 |
|
| 73 |
class RasterizationSettings:
|
| 74 |
def __init__(self, image_size=256, blur_radius=0.0, faces_per_pixel=1, **kwargs):
|
| 75 |
+
self.image_size = image_size; self.blur_radius = blur_radius; self.faces_per_pixel = faces_per_pixel
|
|
|
|
|
|
|
| 76 |
|
| 77 |
|
| 78 |
class BlendParams:
|
| 79 |
def __init__(self, sigma=1e-4, gamma=1e-4, background_color=(0.0, 0.0, 0.0)):
|
| 80 |
+
self.sigma = sigma; self.gamma = gamma; self.background_color = background_color
|
|
|
|
|
|
|
| 81 |
|
| 82 |
|
| 83 |
class SoftSilhouetteShader:
|
|
|
|
| 88 |
class MeshRasterizer(torch.nn.Module):
|
| 89 |
def __init__(self, cameras=None, raster_settings=None):
|
| 90 |
super().__init__()
|
| 91 |
+
self.cameras = cameras; self.raster_settings = raster_settings
|
| 92 |
+
def forward(self, meshes, **kw):
|
|
|
|
| 93 |
raise NotImplementedError("MeshRasterizer stub")
|
| 94 |
|
| 95 |
|
| 96 |
class MeshRenderer(torch.nn.Module):
|
| 97 |
def __init__(self, rasterizer=None, shader=None):
|
| 98 |
super().__init__()
|
| 99 |
+
self.rasterizer = rasterizer; self.shader = shader
|
| 100 |
+
def forward(self, meshes, **kw):
|
|
|
|
| 101 |
raise NotImplementedError("MeshRenderer stub")
|
| 102 |
|
| 103 |
|
| 104 |
class TexturesVertex:
|
| 105 |
def __init__(self, verts_features=None):
|
| 106 |
self.verts_features_list = verts_features if isinstance(verts_features, list) else [verts_features]
|
| 107 |
+
def to(self, device): return self
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
|
| 109 |
|
| 110 |
class TexturesAtlas:
|
| 111 |
+
def __init__(self, atlas=None, **kw): self.atlas = atlas
|
| 112 |
+
def to(self, device): return self
|
|
|
|
|
|
|
| 113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
+
class TexturesUV:
|
| 116 |
+
def __init__(self, **kw): pass
|
| 117 |
+
def to(self, device): return self
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
+
class HeterogeneousRayBundle:
|
| 121 |
+
def __init__(self, *a, **kw): pass
|
|
|
|
|
|
|
|
|
|
| 122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
+
class RayBundle:
|
| 125 |
+
def __init__(self, origins=None, directions=None, lengths=None, xys=None, **kw):
|
| 126 |
+
self.origins = origins; self.directions = directions; self.lengths = lengths; self.xys = xys
|