CoolFace
Modelpublic

InPeerReview/RemoteSensingChangeDetection-RSCD.HA2F

sourceHugging Faceupdated 10mo agoView on Hugging Face
2likes
mlp.py41 linesDownload Raw Back to layers
1# Copyright (c) Meta Platforms, Inc. and affiliates.2#3# This source code is licensed under the Apache License, Version 2.04# found in the LICENSE file in the root directory of this source tree.5 6# References:7#   https://github.com/facebookresearch/dino/blob/master/vision_transformer.py8#   https://github.com/rwightman/pytorch-image-models/tree/master/timm/layers/mlp.py9 10 11from typing import Callable, Optional12 13from torch import Tensor, nn14 15 16class Mlp(nn.Module):17    def __init__(18        self,19        in_features: int,20        hidden_features: Optional[int] = None,21        out_features: Optional[int] = None,22        act_layer: Callable[..., nn.Module] = nn.GELU,23        drop: float = 0.0,24        bias: bool = True,25    ) -> None:26        super().__init__()27        out_features = out_features or in_features28        hidden_features = hidden_features or in_features29        self.fc1 = nn.Linear(in_features, hidden_features, bias=bias)30        self.act = act_layer()31        self.fc2 = nn.Linear(hidden_features, out_features, bias=bias)32        self.drop = nn.Dropout(drop)33 34    def forward(self, x: Tensor) -> Tensor:35        x = self.fc1(x)36        x = self.act(x)37        x = self.drop(x)38        x = self.fc2(x)39        x = self.drop(x)40        return x41