Skip to content

Indentation Error in Code within the CvT Chapter #392

Description

@ryan-minato

While translating this chapter, I noticed that the code here seems a bit strange. Is the indentation of the forward method incorrect?

def forward(self, x):
x = self.patch_embed(x)
B, C, H, W = x.size()
x = rearrange(x, "b c h w -> b (h w) c")
cls_tokens = None
if self.cls_token is not None:
cls_tokens = self.cls_token.expand(B, -1, -1)
x = torch.cat((cls_tokens, x), dim=1)
x = self.pos_drop(x)
for i, blk in enumerate(self.blocks):
x = blk(x, H, W)
if self.cls_token is not None:
cls_tokens, x = torch.split(x, [1, H * W], 1)
x = rearrange(x, "b (h w) c -> b c h w", h=H, w=W)
return x, cls_tokens

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions