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

Method unpatchify

star/models/mae_base.py:392–406  ·  view source on GitHub ↗

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

(self, x)

Source from the content-addressed store, hash-verified

390 return x
391
392 def unpatchify(self, x):
393 """
394 x: (N, L, patch_size**2 *chans)
395 imgs: (N, chans, H, W)
396 """
397 p = self.patch_embed.patch_size[0]
398 h = w = int(x.shape[1]**.5)
399 assert h * w == x.shape[1]
400 num_chans = x.size(-1)//(p**2)
401 assert p**2 * num_chans == x.size(-1)
402
403 x = x.reshape(shape=(x.shape[0], h, w, p, p, num_chans))
404 x = torch.einsum('nhwpqc->nchpwq', x)
405 imgs = x.reshape(shape=(x.shape[0], num_chans, h * p, h * p))
406 return imgs
407
408 def random_masking(self, x, mask_ratio):
409 """

Callers 4

forwardMethod · 0.95
late_fusionMethod · 0.80
forward_decoderMethod · 0.80
forward_decoderMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected