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 |
While translating this chapter, I noticed that the code here seems a bit strange. Is the indentation of the
forwardmethod incorrect?computer-vision-course/chapters/en/unit3/vision-transformers/cvt.mdx
Lines 241 to 261 in d5b297e