Class for creating a Swin Transformer model

The SwinT class can be used to create a Swin Transformer model, that can be used with the fastai library.

class SwinT[source]

SwinT(arch, num_classes, pretrained=True)

Class for setting up a Swin Transformer model. The architecture is specified by arch, and the number of classes is specified by num_classes. Returns a pretrained model, by default, or an initialised model if pretrained is set to False.

SwinT.get_model[source]

SwinT.get_model()

Method for getting the Swin Transformer model.

Let's see if this class returns a sequential model :

swint_ob = SwinT('swin_base_patch4_window7_224', pretrained = False, num_classes = 2)
swin_model = swint_ob.get_model()
assert isinstance(swin_model, nn.Sequential)

Now, this model can be used with the Learner class of fastai, like any other model, with any custom classification dataset.

Any SwinT architecture, present in the timm library, can be used with transcv.