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

Inquiry about patch embedding #140

Open
zihao19 opened this issue May 16, 2023 · 4 comments
Open

Inquiry about patch embedding #140

zihao19 opened this issue May 16, 2023 · 4 comments

Comments

@zihao19
Copy link

zihao19 commented May 16, 2023

I'm confused by the patch embedding codes in network_swinir.py
If I read the codes correctly, there seems to be no patch embedding in the forward method. Only flatten and transpose. Can someone help me understand the codes?

class PatchEmbed(nn.Module):

def __init__(self, img_size=224, patch_size=4, in_chans=3, embed_dim=96, norm_layer=None):
    super().__init__()
    img_size = to_2tuple(img_size)
    patch_size = to_2tuple(patch_size)
    patches_resolution = [img_size[0] // patch_size[0], img_size[1] // patch_size[1]]
    self.img_size = img_size
    self.patch_size = patch_size
    self.patches_resolution = patches_resolution
    self.num_patches = patches_resolution[0] * patches_resolution[1]

    self.in_chans = in_chans
    self.embed_dim = embed_dim

    if norm_layer is not None:
        self.norm = norm_layer(embed_dim)
    else:
        self.norm = None

def forward(self, x):
    x = x.flatten(2).transpose(1, 2)  # B Ph*Pw C
    if self.norm is not None:
        x = self.norm(x)
    return x

def flops(self):
    flops = 0
    H, W = self.img_size
    if self.norm is not None:
        flops += H * W * self.embed_dim
    return flops`
@azzooz1417
Copy link

Uploading D827A639-9967-4A59-AE0F-C9432BE5708A.jpeg…

@azzooz1417
Copy link

Uploading 14D0BB97-409C-490B-9BDE-D26D7E1E7908.png…

@Feynman1999
Copy link

because patchsize is 1 here

@YoungP2001
Copy link

I have the same question, and the reply is missing.

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

4 participants