Сводка модели ViT по умолчанию в Тимм заканчивается так:
Код: Выделить всё
LayerNorm-247 [-1, 197, 768] 1,536
Identity-248 [-1, 768] 0
Dropout-249 [-1, 768] 0
Linear-250 [-1, 1000] 769,000
VisionTransformer-251 [-1, 1000] 0
Код: Выделить всё
class VisionTransformerWithoutHead(nn.Module):
def __init__(self, model_name):
super(VisionTransformerWithoutHead, self).__init__()
# Load the ViT model
vit_model = timm.create_model(model_name, pretrained=True)
# Remove the final layers
self.features = nn.Sequential(*list(vit_model.children())[:-1])
def forward(self, x):
# Forward pass through the modified model
output = self.features(x)
return output
Код: Выделить всё
LayerNorm-247 [-1, 196, 768] 1,536
Identity-248 [-1, 196, 768] 0
Dropout-249 [-1, 196, 768] 0
Подробнее здесь: https://stackoverflow.com/questions/779 ... in-pytorch