Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

self.pos_embedding error training on different dataset #14

Open
khawar-islam opened this issue Apr 27, 2021 · 6 comments
Open

self.pos_embedding error training on different dataset #14

khawar-islam opened this issue Apr 27, 2021 · 6 comments

Comments

@khawar-islam
Copy link

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
@culiver
Copy link

culiver commented Dec 2, 2021

Same problem!

@culiver
Copy link

culiver commented Dec 3, 2021

Same problem!

Solved by assigning the image_size

@helloworld-wu
Copy link

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
Copy link

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

@culiver
Copy link

culiver commented Dec 12, 2021

@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.

@helloworld-wu
Copy link

@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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants