MLPMixer-like models
This is the API reference for the MLPMixer-like models supported by Metalhead.jl.
The higher-level model constructors
Metalhead.MLPMixer
— TypeMLPMixer(config::Symbol; patch_size::Dims{2} = (16, 16), imsize::Dims{2} = (224, 224),
inchannels::Integer = 3, nclasses::Integer = 1000)
Creates a model with the MLPMixer architecture. (reference).
Arguments
config
: the size of the model - one of:small
,:base
,:large
or:huge
patch_size
: the size of the patchesimsize
: the size of the input imagestochastic_depth_prob
: Stochastic depth probabilityinchannels
: the number of input channelsnclasses
: number of output classes
See also Metalhead.mlpmixer
.
Metalhead.ResMLP
— TypeResMLP(config::Symbol; patch_size::Dims{2} = (16, 16), imsize::Dims{2} = (224, 224),
inchannels::Integer = 3, nclasses::Integer = 1000)
Creates a model with the ResMLP architecture. (reference).
Arguments
config
: the size of the model - one of:small
,:base
,:large
or:huge
patch_size
: the size of the patchesimsize
: the size of the input imageinchannels
: the number of input channelsnclasses
: number of output classes
See also Metalhead.mlpmixer
.
Metalhead.gMLP
— TypegMLP(config::Symbol; patch_size::Dims{2} = (16, 16), imsize::Dims{2} = (224, 224),
inchannels::Integer = 3, nclasses::Integer = 1000)
Creates a model with the gMLP architecture. (reference).
Arguments
config
: the size of the model - one of:small
,:base
,:large
or:huge
patch_size
: the size of the patchesimsize
: the size of the input imageinchannels
: the number of input channelsnclasses
: number of output classes
See also Metalhead.mlpmixer
.
The core MLPMixer function
Metalhead.mlpmixer
— Functionmlpmixer(block, imsize::Dims{2} = (224, 224); inchannels::Integer = 3, norm_layer = LayerNorm,
patch_size::Dims{2} = (16, 16), embedplanes = 512, stochastic_depth_prob = 0.,
depth::Integer = 12, nclasses::Integer = 1000, kwargs...)
Creates a model with the MLPMixer architecture. (reference).
Arguments
block
: the type of mixer block to use in the model - architecture dependent (a constructor of the formblock(embedplanes, npatches; stochastic_depth_prob, kwargs...)
)imsize
: the size of the input imageinchannels
: the number of input channelsnorm_layer
: the normalization layer to use in the modelpatch_size
: the size of the patchesembedplanes
: the number of channels after the patch embedding (denotes the hidden dimension)stochastic_depth_prob
: Stochastic depth probabilitydepth
: the number of blocks in the modelnclasses
: number of output classeskwargs
: additional arguments (if any) to pass to the mixer block. Will use the defaults if not specified.
The block functions
Metalhead.mixerblock
— Functionmixerblock(planes::Integer, npatches::Integer; mlp_layer = mlp_block,
mlp_ratio = (0.5, 4.0), dropout_prob = 0.0, stochastic_depth_prob = 0.0,
activation = gelu)
Creates a feedforward block for the MLPMixer architecture. (reference)
Arguments
planes
: the number of planes in the blocknpatches
: the number of patches of the inputmlp_ratio
: number(s) that determine(s) the number of hidden channels in the token mixing MLP and/or the channel mixing MLP as a ratio to the number of planes in the block.mlp_layer
: the MLP layer to use in the blockdropout_prob
: the dropout probability to use in the MLP blocksstochastic_depth_prob
: Stochastic depth probabilityactivation
: the activation function to use in the MLP blocks
Metalhead.resmixerblock
— Functionresmixerblock(planes, npatches; dropout_prob = 0., stochastic_depth_prob = 0., mlp_ratio = 4.0,
activation = gelu, layerscale_init = 1e-4)
Creates a block for the ResMixer architecture. (reference).
Arguments
planes
: the number of planes in the blocknpatches
: the number of patches of the inputmlp_ratio
: ratio of the number of hidden channels in the channel mixing MLP to the number of planes in the blockmlp_layer
: the MLP block to usedropout_prob
: the dropout probability to use in the MLP blocksstochastic_depth_prob
: Stochastic depth probabilityactivation
: the activation function to use in the MLP blockslayerscale_init
: initialisation constant for the LayerScale
Metalhead.SpatialGatingUnit
— TypeSpatialGatingUnit(planes::Integer, npatches::Integer; norm_layer = LayerNorm)
Creates a spatial gating unit as described in the gMLP paper. (reference)
Arguments
planes
: the number of planes in the blocknpatches
: the number of patches of the inputnorm_layer
: the normalisation layer to use
Metalhead.spatialgatingblock
— Functionspatialgatingblock(planes::Integer, npatches::Integer; mlp_ratio = 4.0,
norm_layer = LayerNorm, mlp_layer = gated_mlp_block,
dropout_prob = 0.0, stochastic_depth_prob = 0.0,
activation = gelu)
Creates a feedforward block based on the gMLP model architecture described in the paper. (reference)
Arguments
planes
: the number of planes in the blocknpatches
: the number of patches of the inputmlp_ratio
: ratio of the number of hidden channels in the channel mixing MLP to the number of planes in the blocknorm_layer
: the normalisation layer to usedropout_prob
: the dropout probability to use in the MLP blocksstochastic_depth_prob
: Stochastic depth probabilityactivation
: the activation function to use in the MLP blocks