Skip to content

Commit

Permalink
Update cvt.py
Browse files Browse the repository at this point in the history
  • Loading branch information
fffffgggg54 committed Dec 15, 2024
1 parent 4d1b21a commit 430f7b4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion timm/models/cvt.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import torch.nn.functional as F

from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
from timm.layers import ConvNormAct, LayerNorm, LayerNorm2d, Mlp, QuickGELU, trunc_normal_, use_fused_attn, nchw_to
from timm.layers import ConvNormAct, DropPath, LayerNorm, LayerNorm2d, Mlp, QuickGELU, trunc_normal_, use_fused_attn, nchw_to
from ._builder import build_model_with_cfg
from ._registry import generate_default_cfgs, register_model

Expand Down Expand Up @@ -175,6 +175,20 @@ def forward(self, q: torch.Tensor, k: torch.Tensor, v: torch.Tensor) -> torch.Te
x = self.proj_drop(x)
return x

class LayerScale(nn.Module):
def __init__(
self,
dim: int,
init_values: float = 1e-5,
inplace: bool = False,
) -> None:
super().__init__()
self.inplace = inplace
self.gamma = nn.Parameter(init_values * torch.ones(dim))

def forward(self, x: torch.Tensor) -> torch.Tensor:
return x.mul_(self.gamma) if self.inplace else x * self.gamma

class CvTBlock(nn.Module):
def __init__(
self,
Expand Down

0 comments on commit 430f7b4

Please sign in to comment.