Skip to content

Instantly share code, notes, and snippets.

@shubham0204
Created June 12, 2021 06:45
Show Gist options
  • Save shubham0204/eade500d54be843b17c42d35c9740ea5 to your computer and use it in GitHub Desktop.
Save shubham0204/eade500d54be843b17c42d35c9740ea5 to your computer and use it in GitHub Desktop.
# Token Mixing MLPs : Allow communication within patches.
def token_mixing( x , token_mixing_mlp_dims ):
# x is a tensor of shape ( batch_size , num_patches , channels )
x = tf.keras.layers.LayerNormalization( epsilon=1e-6 )( x )
x = tf.keras.layers.Permute( dims=[ 2 , 1 ] )( x )
# After transposition, shape of x -> ( batch_size , channels , num_patches )
x = mlp( x , token_mixing_mlp_dims )
return x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment