mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 17:24:32 +02:00
+1
-1
@@ -66,7 +66,7 @@ def attention_forward(self, x, resolution, shared_rel_pos_bias: Optional[torch.T
|
||||
"""
|
||||
Modification of timm.models.beit.py: Attention.forward to support arbitrary window sizes.
|
||||
"""
|
||||
B, N, _C = x.shape
|
||||
B, N, C = x.shape
|
||||
|
||||
qkv_bias = torch.cat((self.q_bias, self.k_bias, self.v_bias)) if self.q_bias is not None else None
|
||||
qkv = F.linear(input=x, weight=self.qkv.weight, bias=qkv_bias)
|
||||
|
||||
+1
-1
@@ -81,7 +81,7 @@ def forward_default(pretrained, x, function_name="forward_features"):
|
||||
|
||||
|
||||
def forward_adapted_unflatten(pretrained, x, function_name="forward_features"):
|
||||
_b, _c, h, w = x.shape
|
||||
b, c, h, w = x.shape
|
||||
|
||||
exec(f"glob = pretrained.model.{function_name}(x)")
|
||||
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ def _resize_pos_embed(self, posemb, gs_h, gs_w):
|
||||
|
||||
|
||||
def forward_flex(self, x):
|
||||
_b, _c, h, w = x.shape
|
||||
b, c, h, w = x.shape
|
||||
|
||||
pos_embed = self._resize_pos_embed(
|
||||
self.pos_embed, h // self.patch_size[1], w // self.patch_size[0]
|
||||
|
||||
@@ -5,6 +5,10 @@ from .backbones.beit import (
|
||||
_make_pretrained_beitl16_512,
|
||||
_make_pretrained_beitl16_384,
|
||||
_make_pretrained_beitb16_384,
|
||||
forward_beit,
|
||||
)
|
||||
from .backbones.swin_common import (
|
||||
forward_swin,
|
||||
)
|
||||
from .backbones.swin2 import (
|
||||
_make_pretrained_swin2l24_384,
|
||||
@@ -16,11 +20,13 @@ from .backbones.swin import (
|
||||
)
|
||||
from .backbones.levit import (
|
||||
_make_pretrained_levit_384,
|
||||
forward_levit,
|
||||
)
|
||||
from .backbones.vit import (
|
||||
_make_pretrained_vitb_rn50_384,
|
||||
_make_pretrained_vitl16_384,
|
||||
_make_pretrained_vitb16_384,
|
||||
forward_vit,
|
||||
)
|
||||
|
||||
def _make_encoder(backbone, features, use_pretrained, groups=1, expand=False, exportable=True, hooks=None,
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from .base_model import BaseModel
|
||||
from .blocks import FeatureFusionBlock_custom, Interpolate, _make_encoder
|
||||
from .blocks import FeatureFusionBlock, FeatureFusionBlock_custom, Interpolate, _make_encoder
|
||||
|
||||
|
||||
class MidasNet_small(BaseModel):
|
||||
|
||||
@@ -100,7 +100,7 @@ class AttractorLayer(nn.Module):
|
||||
A = self._net(x)
|
||||
eps = 1e-3
|
||||
A = A + eps
|
||||
n, _c, h, w = A.shape
|
||||
n, c, h, w = A.shape
|
||||
A = A.view(n, self.n_attractors, 2, h, w)
|
||||
A_normed = A / A.sum(dim=2, keepdim=True) # n, a, 2, h, w
|
||||
A_normed = A[:, :, 0, ...] # n, na, h, w
|
||||
@@ -177,7 +177,7 @@ class AttractorLayerUnnormed(nn.Module):
|
||||
x = x + prev_b_embedding
|
||||
|
||||
A = self._net(x)
|
||||
_n, _c, h, w = A.shape
|
||||
n, c, h, w = A.shape
|
||||
|
||||
b_prev = nn.functional.interpolate(
|
||||
b_prev, (h, w), mode='bilinear', align_corners=True)
|
||||
|
||||
@@ -146,7 +146,7 @@ class LinearSplitter(nn.Module):
|
||||
S = self._net(x)
|
||||
eps = 1e-3
|
||||
S = S + eps
|
||||
n, _c, h, w = S.shape
|
||||
n, c, h, w = S.shape
|
||||
S = S.view(n, self.prev_nbins, self.split_factor, h, w)
|
||||
S_normed = S / S.sum(dim=2, keepdim=True) # fractional splits
|
||||
|
||||
|
||||
@@ -26,13 +26,13 @@ import itertools
|
||||
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
from ..depth_model import DepthModel # noqa: TID252
|
||||
from ..base_models.midas import MidasCore # noqa: TID252
|
||||
from ..layers.attractor import AttractorLayer, AttractorLayerUnnormed # noqa: TID252
|
||||
from ..layers.dist_layers import ConditionalLogBinomial # noqa: TID252
|
||||
from ..layers.localbins_layers import (Projector, SeedBinRegressor, # noqa: TID252
|
||||
from ..depth_model import DepthModel
|
||||
from ..base_models.midas import MidasCore
|
||||
from ..layers.attractor import AttractorLayer, AttractorLayerUnnormed
|
||||
from ..layers.dist_layers import ConditionalLogBinomial
|
||||
from ..layers.localbins_layers import (Projector, SeedBinRegressor,
|
||||
SeedBinRegressorUnnormed)
|
||||
from ..model_io import load_state_from_resource # noqa: TID252
|
||||
from ..model_io import load_state_from_resource
|
||||
|
||||
|
||||
class ZoeDepth(DepthModel):
|
||||
@@ -139,7 +139,7 @@ class ZoeDepth(DepthModel):
|
||||
- probs (torch.Tensor): Output probability distribution of shape (B, n_bins, H, W). Present only if return_probs is True
|
||||
|
||||
"""
|
||||
b, _c, h, w = x.shape
|
||||
b, c, h, w = x.shape
|
||||
# print("input shape ", x.shape)
|
||||
self.orig_input_width = w
|
||||
self.orig_input_height = h
|
||||
|
||||
@@ -27,14 +27,14 @@ import itertools
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from ..depth_model import DepthModel # noqa: TID252
|
||||
from ..base_models.midas import MidasCore # noqa: TID252
|
||||
from ..layers.attractor import AttractorLayer, AttractorLayerUnnormed # noqa: TID252
|
||||
from ..layers.dist_layers import ConditionalLogBinomial # noqa: TID252
|
||||
from ..layers.localbins_layers import (Projector, SeedBinRegressor, # noqa: TID252
|
||||
from ..depth_model import DepthModel
|
||||
from ..base_models.midas import MidasCore
|
||||
from ..layers.attractor import AttractorLayer, AttractorLayerUnnormed
|
||||
from ..layers.dist_layers import ConditionalLogBinomial
|
||||
from ..layers.localbins_layers import (Projector, SeedBinRegressor,
|
||||
SeedBinRegressorUnnormed)
|
||||
from ..layers.patch_transformer import PatchTransformerEncoder # noqa: TID252
|
||||
from ..model_io import load_state_from_resource # noqa: TID252
|
||||
from ..layers.patch_transformer import PatchTransformerEncoder
|
||||
from ..model_io import load_state_from_resource
|
||||
|
||||
class ZoeDepthNK(DepthModel):
|
||||
def __init__(self, core, bin_conf, bin_centers_type="softplus", bin_embedding_dim=128,
|
||||
@@ -173,10 +173,10 @@ class ZoeDepthNK(DepthModel):
|
||||
- "bin_centers": Bin centers of shape (B, N, H, W). Present only if return_final_centers is True
|
||||
- "probs": Bin probabilities of shape (B, N, H, W). Present only if return_probs is True
|
||||
"""
|
||||
b, _c, h, w = x.shape
|
||||
b, c, h, w = x.shape
|
||||
self.orig_input_width = w
|
||||
self.orig_input_height = h
|
||||
_rel_depth, out = self.core(x, denorm=denorm, return_rel_depth=True)
|
||||
rel_depth, out = self.core(x, denorm=denorm, return_rel_depth=True)
|
||||
|
||||
outconv_activation = out[0]
|
||||
btlnck = out[1]
|
||||
|
||||
Reference in New Issue
Block a user