Team Ai
Apppublic

xdecoder/Instruct-X-Decoder

sourceHugging Faceafl-3.0updated 3y agoView on Hugging Face
163likes
backbone.py52 linesDownload Raw Back to backbone
1# Copyright (c) Facebook, Inc. and its affiliates.2import torch.nn as nn3 4from detectron2.modeling import ShapeSpec5 6__all__ = ["Backbone"]7 8 9class Backbone(nn.Module):10    """11    Abstract base class for network backbones.12    """13 14    def __init__(self):15        """16        The `__init__` method of any subclass can specify its own set of arguments.17        """18        super().__init__()19 20    def forward(self):21        """22        Subclasses must override this method, but adhere to the same return type.23 24        Returns:25            dict[str->Tensor]: mapping from feature name (e.g., "res2") to tensor26        """27        pass28 29    @property30    def size_divisibility(self) -> int:31        """32        Some backbones require the input height and width to be divisible by a33        specific integer. This is typically true for encoder / decoder type networks34        with lateral connection (e.g., FPN) for which feature maps need to match35        dimension in the "bottom up" and "top down" paths. Set to 0 if no specific36        input size divisibility is required.37        """38        return 039 40    def output_shape(self):41        """42        Returns:43            dict[str->ShapeSpec]44        """45        # this is a backward-compatible default46        return {47            name: ShapeSpec(48                channels=self._out_feature_channels[name], stride=self._out_feature_strides[name]49            )50            for name in self._out_features51        }52