PyTorch-Pretrained-ViT icon indicating copy to clipboard operation
PyTorch-Pretrained-ViT copied to clipboard

self.pos_embedding error training on different dataset

Open khawar-islam opened this issue 3 years ago • 6 comments

I am using a pre-trained VIT model and trained on some different task but I got an error

model.py file

class PositionalEmbedding1D(nn.Module):
    """Adds (optionally learned) positional embeddings to the inputs."""

    def __init__(self, seq_len, dim):
        super().__init__()
        self.pos_embedding = nn.Parameter(torch.zeros(1, seq_len, dim))
    
    def forward(self, x):
        """Input has shape `(batch_size, seq_len, emb_dim)`"""
        return x + self.pos_embedding

Traceback

    result = self.forward(*input, **kwargs)
  File "/media/khawar/HDD_Khawar/n/Pretrained_ViT/pytorch_pretrained_vit/model.py", line 24, in forward
    return x + self.pos_embedding

khawar-islam avatar Apr 27 '21 15:04 khawar-islam

Same problem!

culiver avatar Dec 02 '21 16:12 culiver

Same problem!

Solved by assigning the image_size

culiver avatar Dec 03 '21 01:12 culiver

Same problem!

Solved by assigning the image_size

Hello, I have the same problem. Could you tell me how to assign the image_size? Thank you!

helloworld-wu avatar Dec 10 '21 08:12 helloworld-wu

@culiver Hello, I have the same problem. Could you tell me how to assign the image_size? Thank you!

helloworld-wu avatar Dec 10 '21 08:12 helloworld-wu

@culiver Hello, I have the same problem. Could you tell me how to assign the image_size? Thank you!

I assigned the image size as the below code. model = ViT('B_16_imagenet1k', pretrained=True, num_classes=37, image_size=opt.input_size).cuda()

Note that do not put this line in nn.Sequential or it might not change the input size.

culiver avatar Dec 12 '21 01:12 culiver

@culiver Hello, I have the same problem. Could you tell me how to assign the image_size? Thank you!

I assigned the image size as the below code. model = ViT('B_16_imagenet1k', pretrained=True, num_classes=37, image_size=opt.input_size).cuda()

Note that do not put this line in nn.Sequential or it might not change the input size.

Thanks !

helloworld-wu avatar Dec 12 '21 16:12 helloworld-wu