MCPcopy Create free account
hub / github.com/coperception/star / patchify

Method patchify

star/models/mae_base.py:377–390  ·  view source on GitHub ↗

imgs: (N, chs, H, W) x: (N, L, patch_size**2 *chns)

(self, imgs)

Source from the content-addressed store, hash-verified

375 nn.init.constant_(m.weight, 1.0)
376
377 def patchify(self, imgs):
378 """
379 imgs: (N, chs, H, W)
380 x: (N, L, patch_size**2 *chns)
381 """
382 p = self.patch_embed.patch_size[0]
383 assert imgs.shape[2] == imgs.shape[3] and imgs.shape[2] % p == 0
384 num_chans = imgs.size(1)
385
386 h = w = imgs.shape[2] // p
387 x = imgs.reshape(shape=(imgs.shape[0], num_chans, h, p, w, p))
388 x = torch.einsum('nchpwq->nhwpqc', x)
389 x = x.reshape(shape=(imgs.shape[0], h * w, p**2 * num_chans))
390 return x
391
392 def unpatchify(self, x):
393 """

Callers 5

forward_lossMethod · 0.95
forward_decoderMethod · 0.80
forward_lossMethod · 0.80
forward_lossMethod · 0.80
forward_lossMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected