Download perception_models/core/vision_projector/base.py from haiphamcse/XAI: direct link, hf CLI and curl.
- Browser
- Download file 628 Bytes
-
https://huggingface.co/haiphamcse/XAI/resolve/main/perception_models/core/vision_projector/base.py
- Command line
-
hf download hf://haiphamcse/XAI/perception_models/core/vision_projector/base.py
-
curl -L -o base.py https://huggingface.co/haiphamcse/XAI/resolve/main/perception_models/core/vision_projector/base.py
628 Bytes
| # Copyright (c) Meta Platforms, Inc. and affiliates. | |
| from abc import ABC, abstractmethod | |
| from torch import nn | |
| class BaseProjector(nn.Module, ABC): | |
| def __init__(self): | |
| super().__init__() | |
| self.adaptive_avg_pool = None | |
| def setup_projector(self): | |
| """ | |
| Setup the vision_projector attribute in subclasses. | |
| """ | |
| pass | |
| def forward(self, x): | |
| x = x.permute(1, 0, 2) # NLD -> LND | |
| x = self.projector(x) | |
| x = x.permute(1, 0, 2) | |
| if self.adaptive_avg_pool is not None: | |
| x = self.adaptive_avg_pool(x) | |
| return x | |