MCPcopy Create free account
hub / github.com/tensorflow/models / to_patch

Function to_patch

official/projects/mae/modeling/vit.py:24–33  ·  view source on GitHub ↗

Image (NHWC) to patches (N(H' W')(patch_height patch_width c)).

(images, patch_height, patch_width)

Source from the content-addressed store, hash-verified

22
23
24def to_patch(images, patch_height, patch_width):
25 """Image (NHWC) to patches (N(H' W')(patch_height patch_width c))."""
26 batch_size, h, w, c = tf_utils.get_shape_list(images)
27 num_h = h // patch_height
28 num_w = w // patch_width
29 x = tf.reshape(images,
30 (batch_size, num_h, patch_height, num_w, patch_width, c))
31 x = tf.einsum('nhpwqc->nhwpqc', x)
32 x = tf.reshape(x, (batch_size, num_h, num_w, patch_height * patch_width * c))
33 return x
34
35
36class ViTClassifier(tf_keras.Model):

Callers 1

callMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected