Spaces:
Runtime error
Runtime error
Luigi Piccinelli
commited on
Commit
·
02b5a6d
1
Parent(s):
183b4b6
add profiling
Browse files
unik3d/layers/upsample.py
CHANGED
|
@@ -89,7 +89,7 @@ class ResUpsampleBil(nn.Module):
|
|
| 89 |
nn.Upsample(scale_factor=2, mode="bilinear", align_corners=False),
|
| 90 |
)
|
| 91 |
|
| 92 |
-
@profile_method(verbose=
|
| 93 |
def forward(self, x: torch.Tensor):
|
| 94 |
for conv in self.convs:
|
| 95 |
x = conv(x)
|
|
@@ -122,7 +122,7 @@ class ResUpsample(nn.Module):
|
|
| 122 |
hidden_dim, hidden_dim // 2, kernel_size=2, stride=2, padding=0
|
| 123 |
)
|
| 124 |
|
| 125 |
-
@profile_method(verbose=
|
| 126 |
def forward(self, x: torch.Tensor):
|
| 127 |
for conv in self.convs:
|
| 128 |
x = conv(x)
|
|
|
|
| 89 |
nn.Upsample(scale_factor=2, mode="bilinear", align_corners=False),
|
| 90 |
)
|
| 91 |
|
| 92 |
+
@profile_method(verbose=True)
|
| 93 |
def forward(self, x: torch.Tensor):
|
| 94 |
for conv in self.convs:
|
| 95 |
x = conv(x)
|
|
|
|
| 122 |
hidden_dim, hidden_dim // 2, kernel_size=2, stride=2, padding=0
|
| 123 |
)
|
| 124 |
|
| 125 |
+
@profile_method(verbose=True)
|
| 126 |
def forward(self, x: torch.Tensor):
|
| 127 |
for conv in self.convs:
|
| 128 |
x = conv(x)
|
unik3d/models/decoder.py
CHANGED
|
@@ -18,7 +18,7 @@ from unik3d.utils.geometric import flat_interpolate
|
|
| 18 |
from unik3d.utils.misc import get_params
|
| 19 |
from unik3d.utils.positional_embedding import generate_fourier_features
|
| 20 |
from unik3d.utils.sht import rsh_cart_3
|
| 21 |
-
|
| 22 |
|
| 23 |
def orthonormal_init(num_tokens, dims):
|
| 24 |
pe = torch.randn(num_tokens, dims)
|
|
@@ -120,6 +120,7 @@ class AngularModule(nn.Module):
|
|
| 120 |
intrinsics = correction_tensor.unsqueeze(0) * intrinsics
|
| 121 |
return intrinsics
|
| 122 |
|
|
|
|
| 123 |
def forward(self, cls_tokens) -> torch.Tensor:
|
| 124 |
latents_pos = self.latents_pos.expand(cls_tokens.shape[0], -1, -1)
|
| 125 |
|
|
@@ -271,6 +272,7 @@ class RadialModule(nn.Module):
|
|
| 271 |
def set_shapes(self, shapes: tuple[int, int]):
|
| 272 |
self.shapes = shapes
|
| 273 |
|
|
|
|
| 274 |
def embed_rays(self, rays):
|
| 275 |
rays_embedding = flat_interpolate(
|
| 276 |
rays, old=self.original_shapes, new=self.shapes, antialias=True
|
|
@@ -292,6 +294,7 @@ class RadialModule(nn.Module):
|
|
| 292 |
)
|
| 293 |
return rays_embedding
|
| 294 |
|
|
|
|
| 295 |
def condition(self, feat, rays_embeddings):
|
| 296 |
conditioned_features = [
|
| 297 |
prompter(rearrange(feature, "b h w c -> b (h w) c"), rays_embeddings)
|
|
@@ -321,6 +324,7 @@ class RadialModule(nn.Module):
|
|
| 321 |
|
| 322 |
return out_features, init_latents
|
| 323 |
|
|
|
|
| 324 |
def depth_proj(self, out_features):
|
| 325 |
depths = []
|
| 326 |
h_out, w_out = out_features[-1].shape[-2:]
|
|
@@ -340,6 +344,7 @@ class RadialModule(nn.Module):
|
|
| 340 |
logdepth = self.to_depth_hr(logdepth)
|
| 341 |
return logdepth
|
| 342 |
|
|
|
|
| 343 |
def confidence_proj(self, out_features):
|
| 344 |
highres_features = out_features[-1].permute(0, 2, 3, 1)
|
| 345 |
confidence = self.confidence_mlp(highres_features).permute(0, 3, 1, 2)
|
|
|
|
| 18 |
from unik3d.utils.misc import get_params
|
| 19 |
from unik3d.utils.positional_embedding import generate_fourier_features
|
| 20 |
from unik3d.utils.sht import rsh_cart_3
|
| 21 |
+
from unik3d.utils.misc import profile_method
|
| 22 |
|
| 23 |
def orthonormal_init(num_tokens, dims):
|
| 24 |
pe = torch.randn(num_tokens, dims)
|
|
|
|
| 120 |
intrinsics = correction_tensor.unsqueeze(0) * intrinsics
|
| 121 |
return intrinsics
|
| 122 |
|
| 123 |
+
@profile_method(verbose=True)
|
| 124 |
def forward(self, cls_tokens) -> torch.Tensor:
|
| 125 |
latents_pos = self.latents_pos.expand(cls_tokens.shape[0], -1, -1)
|
| 126 |
|
|
|
|
| 272 |
def set_shapes(self, shapes: tuple[int, int]):
|
| 273 |
self.shapes = shapes
|
| 274 |
|
| 275 |
+
@profile_method(verbose=True)
|
| 276 |
def embed_rays(self, rays):
|
| 277 |
rays_embedding = flat_interpolate(
|
| 278 |
rays, old=self.original_shapes, new=self.shapes, antialias=True
|
|
|
|
| 294 |
)
|
| 295 |
return rays_embedding
|
| 296 |
|
| 297 |
+
@profile_method(verbose=True)
|
| 298 |
def condition(self, feat, rays_embeddings):
|
| 299 |
conditioned_features = [
|
| 300 |
prompter(rearrange(feature, "b h w c -> b (h w) c"), rays_embeddings)
|
|
|
|
| 324 |
|
| 325 |
return out_features, init_latents
|
| 326 |
|
| 327 |
+
@profile_method(verbose=True)
|
| 328 |
def depth_proj(self, out_features):
|
| 329 |
depths = []
|
| 330 |
h_out, w_out = out_features[-1].shape[-2:]
|
|
|
|
| 344 |
logdepth = self.to_depth_hr(logdepth)
|
| 345 |
return logdepth
|
| 346 |
|
| 347 |
+
@profile_method(verbose=True)
|
| 348 |
def confidence_proj(self, out_features):
|
| 349 |
highres_features = out_features[-1].permute(0, 2, 3, 1)
|
| 350 |
confidence = self.confidence_mlp(highres_features).permute(0, 3, 1, 2)
|
unik3d/models/metadinov2/block.py
CHANGED
|
@@ -21,6 +21,7 @@ from .mlp import Mlp
|
|
| 21 |
|
| 22 |
logger = logging.getLogger("dinov2")
|
| 23 |
|
|
|
|
| 24 |
|
| 25 |
try:
|
| 26 |
from xformers.ops import fmha, index_select_cat, scaled_index_add
|
|
@@ -80,6 +81,7 @@ class Block(nn.Module):
|
|
| 80 |
|
| 81 |
self.sample_drop_ratio = drop_path
|
| 82 |
|
|
|
|
| 83 |
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 84 |
def attn_residual_func(x: torch.Tensor) -> torch.Tensor:
|
| 85 |
return self.ls1(self.attn(self.norm1(x)))
|
|
|
|
| 21 |
|
| 22 |
logger = logging.getLogger("dinov2")
|
| 23 |
|
| 24 |
+
from unik3d.utils.misc import profile_method
|
| 25 |
|
| 26 |
try:
|
| 27 |
from xformers.ops import fmha, index_select_cat, scaled_index_add
|
|
|
|
| 81 |
|
| 82 |
self.sample_drop_ratio = drop_path
|
| 83 |
|
| 84 |
+
@profile_method(verbose=True)
|
| 85 |
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 86 |
def attn_residual_func(x: torch.Tensor) -> torch.Tensor:
|
| 87 |
return self.ls1(self.attn(self.norm1(x)))
|