Skip to content

ResNet

ResNet

Bases: BaseBackbone

ResNet18 backbone with the number of features as an arguments. For nf=20, the ResNet has 1/3 of the features of the original. Code adapted from: 1. https://github.com/facebookresearch/GradientEpisodicMemory 2. https://worksheets.codalab.org/rest/bundles/0xaf60b5ed6a4a44c89d296aae9bc6a0f1/contents/blob/models.py

Source code in sequel/backbones/pytorch/resnet.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
class ResNet(BaseBackbone):
    """ResNet18 backbone with the number of features as an arguments. For `nf=20`, the ResNet has 1/3 of the features
    of the original. Code adapted from:
        1.  https://github.com/facebookresearch/GradientEpisodicMemory
        2.  https://worksheets.codalab.org/rest/bundles/0xaf60b5ed6a4a44c89d296aae9bc6a0f1/contents/blob/models.py
    """

    def __init__(self, block, num_blocks, num_classes, nf=20, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.encoder = ResNetEncoder(block, num_blocks, num_classes, nf)
        self.classifier = nn.Linear(nf * 8 * block.expansion, num_classes)

    def forward(self, inp: torch.Tensor, head_ids: Optional[Iterable] = None):
        out = self.encoder(inp)
        out = self.classifier(out)

        if self.multihead:
            out = self.select_output_head(out, head_ids)
        return out