Views
No views yet

1ViT.vit_small_patch16_224()
2ViT.vit_base_patch16_224()
3ViT.vit_base_patch16_384()
4ViT.vit_base_patch32_384()
5ViT.vit_huge_patch16_224()
6ViT.vit_huge_patch32_384()
7ViT.vit_large_patch16_224()
8ViT.vit_large_patch16_384()
9ViT.vit_large_patch32_384()1# change activation
2ViT.vit_base_patch16_224(activation = nn.SELU)
3# change number of classes (default is 1000 )
4ViT.vit_base_patch16_224(n_classes=100)
5# pass a different block, default is TransformerEncoderBlock
6ViT.vit_base_patch16_224(block=MyCoolTransformerBlock)
7# get features
8model = ViT.vit_base_patch16_224
9# first call .features, this will activate the forward hooks and tells the model you'll like to get the features
10model.encoder.features
11model(torch.randn((1,3,224,224)))
12# get the features from the encoder
13features = model.encoder.features
14print([x.shape for x in features])
15#[[torch.Size([1, 197, 768]), torch.Size([1, 197, 768]), ...]
16# change the tokens, you have to subclass ViTTokens
17class MyTokens(ViTTokens):
18 def __init__(self, emb_size: int):
19 super().__init__(emb_size)
20 self.my_new_token = nn.Parameter(torch.randn(1, 1, emb_size))
21ViT(tokens=MyTokens)