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
handle non square patch sizes #104
Comments
I added initial functionality for this inside the vanilla Vit class, |
@FilipAndersson245 hey! it actually already works with non-square patches, as long as you set the image size to be that of max(height, width), and your height and width is divisible by the patch size |
@lucidrains Hey! do you have an example of how you do that? from vit_pytorch import vit
v = vit.ViT(
image_size = (25,60),
patch_size = (25,1),
num_classes = 30,
dim = 1024,
depth = 6,
heads = 16,
mlp_dim = 2048,
dropout = 0.1,
emb_dropout = 0.1
)
img = torch.randn(1, 3, 25, 60)
preds = v(img) |
@FilipAndersson245 yup, just try import torch
from vit_pytorch import ViT
v = ViT(
image_size = 256,
patch_size = 32,
num_classes = 1000,
dim = 1024,
depth = 6,
heads = 16,
mlp_dim = 2048,
dropout = 0.1,
emb_dropout = 0.1
)
img = torch.randn(1, 3, 256, 128) # not a square
preds = v(img) # (1, 1000) |
@FilipAndersson245 updated the readme too :) this is a frequently asked question |
@lucidrains Okay, but in your example, the patch size is still square 32x32 correct? |
Ohh gotcha, you want nonsquare patches! 🤦♂️ Ok I'll get this built :) |
Did a pull request implementing it if you want to give it a look :) |
my pull request was only for VIT but it would probably be good to do the same to all variants. |
Are there plans to include this modification to the other variants of ViT? e.g. the efficient one? |
Hello, would it be difficult to allow for nonsquare patches to be used, I'm examining the use of Vit on some non-image data where it cannot be represented in a square format.
Preferably by having a tuple as an input to select width and height. Is there anything currently that would block this from being done?
The text was updated successfully, but these errors were encountered: