Back to models
Classifier

MACNNClassifierTorch

Multi-Scale Attention Convolutional Neural Network (MACNN) classifier in PyTorch.

This classifier implements a multi-scale attention mechanism that learns feature representations across different temporal scales.

Quickstart

python
from sktime.classification.deep_learning.macnn import MACNNClassifierTorch

estimator = MACNNClassifierTorch(padding: str='same', pool_size: int=3, strides: int=2, repeats: int=2, filter_sizes: tuple=(64, 128, 256), kernel_sizes: tuple=(3, 6, 12), reduction: int=16, activation: str | Callable | None=None, activation_hidden: str | Callable='ReLU', num_epochs: int=100, batch_size: int=1, optimizer: str | None | Callable='RMSprop', optimizer_kwargs: dict | None=None, criterion: str | None | Callable='CrossEntropyLoss', criterion_kwargs: dict | None=None, callbacks: None | str | tuple [str, ... ]='ReduceLROnPlateau', callback_kwargs: dict | None=None, lr: float=0.001, verbose: bool=False, init_weights: str | None=None, random_state: int=0)

Parameters(21)

paddingstr, default=”same”
The type of padding to be provided in MACNN Blocks. Used for pooling layers only. Convolution layers always use “same” padding, so that multi-scale outputs can be concatenated.
pool_sizeint, default=3
A single value representing pooling windows which are applied between two MACNN Blocks.
stridesint, default=2
A single value representing strides to be taken during the pooling operation.
repeatsint, default=2
The number of MACNN Blocks to be stacked.
filter_sizestuple of int, default=(64, 128, 256)
The filter sizes of Conv1D layers within each MACNN Block.
kernel_sizestuple of int, default=(3, 6, 12)
The kernel sizes of Conv1D layers within each MACNN Block.
reductionint, default=16
The factor by which the first dense layer of a MACNN Block will be divided by.
activationstr, Callable, or None, default=None

Activation applied to the output layer.

Permitted values:

  • None: no activation is applied to the output layer and the network returns raw outputs (logits). This is typically required when using CrossEntropyLoss, which expects logits as input.

  • str: name of a class in torch.nn. Case-sensitive names are recommended and must match PyTorch (e.g., "ReLU", "LeakyReLU"). Lowercase aliases for common activations are also accepted (e.g., "relu" is resolved to "ReLU"). The class is instantiated with default constructor arguments. Must be a valid torch.nn activation; see https://pytorch.org/docs/stable/nn.html#non-linear-activations-weighted-sum-nonlinearity

  • torch.nn.Module: an instance of a torch.nn.Module subclass, for example torch.nn.ReLU(). Arbitrary callables are not supported.

Recommended activations: ReLU, Tanh, Sigmoid, LeakyReLU, ELU, SELU, GELU.

activation_hiddenstr, Callable, or None, default=”ReLU”

Activation applied to the hidden layers.

Permitted values:

  • None: no activation is applied to the hidden layers.

  • str: name of a class in torch.nn. Case-sensitive names are recommended and must match PyTorch (e.g., "ReLU", "LeakyReLU"). Lowercase aliases for common activations are also accepted (e.g., "relu" is resolved to "ReLU"). The class is instantiated with default constructor arguments. Must be a valid torch.nn activation; see https://pytorch.org/docs/stable/nn.html#non-linear-activations-weighted-sum-nonlinearity

  • torch.nn.Module: an instance of a torch.nn.Module subclass, for example torch.nn.ReLU(). Arbitrary callables are not supported.

Recommended activations: ReLU, Tanh, Sigmoid, LeakyReLU, ELU, SELU, GELU.

num_epochsint, default=1500
The number of epochs to train the model.
batch_sizeint, default=4
The size of each mini-batch during training.
optimizercase insensitive str or None or an instance of optimizers
defined in torch.optim, default = “RMSprop” The optimizer to use for training the model.
optimizer_kwargsdict or None, default = None
Additional keyword arguments to pass to the optimizer.
criterioncase insensitive str or None or an instance of a loss function
defined in PyTorch, default = “CrossEntropyLoss” The loss function to be used in training the neural network.
criterion_kwargsdict or None, default = None
Additional keyword arguments to pass to the loss function.
callbacksNone or str or a tuple of str, default = “ReduceLROnPlateau”
Currently only learning rate schedulers are supported as callbacks.
callback_kwargsdict or None, default = None
The keyword arguments to be passed to the callbacks.
lrfloat, default = 0.001
The learning rate to use for the optimizer.
verbosebool, default = False
Whether to print progress information during training.
init_weights: str or None, default = None
The method to initialize the weights of the conv layers. Supported values are ‘kaiming_uniform’, ‘kaiming_normal’, ‘xavier_uniform’, ‘xavier_normal’, or None for default PyTorch initialization.
random_stateint, default = 0
Seed to ensure reproducibility.

Examples

>>> from sktime.classification.deep_learning.macnn import MACNNClassifierTorch
>>> from sktime.datasets import load_unit_test
>>> X_train, y_train = load_unit_test (split = "train")
>>> X_test, y_test = load_unit_test (split = "test")
>>> clf = MACNNClassifierTorch (num_epochs = 50, batch_size = 2)
>>> clf. fit (X_train, y_train) MACNNClassifierTorch(
... )

References

[1]

Wei Chen et. al, Multi-scale Attention Convolutional

Neural Network for time series classification, Neural Networks, Volume 136, 2021, Pages 126-140, ISSN 0893-6080, https://doi.org/10.1016/j.neunet.2021.01.001.