lukemelas / PyTorch-Pretrained-ViT

Vision Transformer (ViT) in PyTorch
770 stars 124 forks source link

When Run [B_16, B_32, L_32 ] models, an error occurs because of position embedding. #16

Open sdh5349 opened 3 years ago

sdh5349 commented 3 years ago

First solved with "ViT(image_size=image_size)" <- add image_size

njw0709 commented 2 years ago

I also got the same error. Here is the error message: Traceback (most recent call last): File "step1_save_feature/save_feature2h5py.py", line 54, in original_stored_imgname, original_stored_feat = extract_features_torch(datadir, model, input_img_size=384) File "/home/namj/ShapeY/step1_save_feature/your_feature_extraction_code.py", line 42, in extract_features_torch output1 = model(img1.cuda()) File "/home/namj/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 550, in call result = self.forward(*input, kwargs) File "/home/namj/.local/lib/python3.6/site-packages/shapey/utils/modelutils.py", line 10, in forward x = self.features(x) File "/home/namj/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 550, in call result = self.forward(*input, *kwargs) File "/home/namj/.local/lib/python3.6/site-packages/torch/nn/modules/container.py", line 100, in forward input = module(input) File "/home/namj/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 550, in call result = self.forward(input, kwargs) File "/home/namj/.local/lib/python3.6/site-packages/pytorch_pretrained_vit/model.py", line 24, in forward return x + self.pos_embedding RuntimeError: The size of tensor a (12) must match the size of tensor b (768) at non-singleton dimension 3

I resized the input image to 384 x 384