Patchify#

class deeplay.models.visiontransformer.Patchify(*args, **kwargs)#

Bases: DeeplayModule

Patchify module.

Splits an image into patches, linearly embeds them, and (optionally) applies dropout to the embeddings.

Parameters#

in_channels: int or None

Number of input features. If None, the input shape is inferred from the first forward pass.

out_featuresint

Number of output features.

patch_sizeint

Size of the patch. The image is divided into patches of size patch_size x patch_size pixels.

Constraints#

  • input_shape: (batch_size, in_channels, height, width)

  • output_shape: (batch_size, num_patches, out_features)

Examples

>>> embedder.dropout.configure(p=0.1)

Return Values#

The forward method returns the processed tensor.

Methods Summary

forward(x)

Define the computation performed at every call.

Methods Documentation

forward(x)#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.