Skip to content

InceptionTimeClassifierTorch

InceptionTimeClassifierTorch

class InceptionTimeClassifierTorch(num_epochs: int = 1500, n_conv_layers: int = 3, n_filters: int = 32, batch_size: int = 64, kernel_size: int = 40, use_residual: bool = True, use_bottleneck: bool = True, bottleneck_size: int = 32, depth: int = 6, activation: str | Callable | None = None, activation_hidden: str | Callable = 'ReLU', activation_inception: str | Callable | None = None, optimizer: str | None | Callable = 'Adam', optimizer_kwargs: dict | None = None, criterion: str | None | Callable = 'CrossEntropyLoss', criterion_kwargs: dict | None = None, callbacks: None | str | tuple[str, ...] = None, callback_kwargs: dict | None = None, metrics: None | str | Callable | tuple[str | Callable, ...] = None, lr: float = 0.001, init_weights: str | None = None, verbose: bool = False, random_state: int | None = None)[source]

InceptionTime Deep Learning Classifier in PyTorch.

Adapted from the implementation from Fawaz et. al https://github.com/hfawaz/InceptionTime/blob/master/classifiers/inception.py

InceptionTimeClassifierTorch is a single instance of InceptionTime model described in the original publication [1]_, which uses an ensemble of 5 single instances.

To build an ensemble of models mirroring [1]_, use the BaggingClassifier with n_estimators=5, bootstrap=False, and estimator being an instance of this InceptionTimeClassifierTorch.

Parameters:
num_epochsint, default=1500

The number of epochs to train the model.

n_conv_layersint, default=3

Number of convolutional branches in each inception module. Make sure base kernel size is divisible by 2^(n_conv_layers-1) to avoid errors. This implementation is adapted from [1].

n_filtersint, default=32

Number of filters in the convolution layers

batch_sizeint, default=64

The size of each mini-batch during training.

kernel_sizeint, default=40

Base kernel size for inception modules

use_residualbool, default=True

If True, uses residual connections

use_bottleneckbool, default=True

If True, uses bottleneck layer in inception modules.

bottleneck_sizeint, default=32

Size of the bottleneck layer.

depthint, default=6

Number of inception modules to stack.

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 (output from inception modules).

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.

activation_inceptionstr, Callable, or None, default=None

Activation applied inside the inception modules.

Permitted values:

  • None: no activation is applied inside the inception modules.

  • 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, None.

optimizercase insensitive str or None or an instance of optimizers

defined in torch.optim, default = “Adam” 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 = None

Currently only learning rate schedulers are supported as callbacks.

callback_kwargsdict or None, default = None

The keyword arguments to be passed to the callbacks.

metricsNone or str or Callable or tuple of str and/or Callable, default = None

Metrics to compute during training. If None, no metrics are computed beyond the loss. Metrics are computed from torchmetrics library. If a string/Callable is passed, it must be one of the metrics defined in https://lightning.ai/docs/torchmetrics/stable/ Examples: “Accuracy”, “F1Score”, “Precision”, “Recall”

lrfloat, default = 0.001

The learning rate to use for the optimizer.

init_weightsstr 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.

verbosebool, default = False

Whether to print progress information during training.

random_stateint or None, default = None

Seed to ensure reproducibility.

Attributes:
is_fitted

Whether fit has been called.

Notes

..[1] Fawaz et. al, InceptionTime: Finding AlexNet for Time Series Classification, Data Mining and Knowledge Discovery, 34, 2020

Examples

Single instance of InceptionTime model: >>> from sktime.classification.deep_learning.inceptiontime import ( … InceptionTimeClassifierTorch … ) >>> 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 = InceptionTimeClassifierTorch( # doctest: +SKIP … num_epochs=50, batch_size=2 … ) >>> clf.fit(X_train, y_train) # doctest: +SKIP InceptionTimeClassifierTorch(…)

To build an ensemble of models mirroring [1]_, use the BaggingClassifier: >>> from sktime.classification.ensemble import BaggingClassifier >>> from sktime.classification.deep_learning.inceptiontime import ( … InceptionTimeClassifierTorch … ) >>> from sktime.datasets import load_unit_test >>> X_train, y_train = load_unit_test(split=”train”) # doctest: +SKIP >>> X_test, y_test = load_unit_test(split=”test”) # doctest: +SKIP >>> clf = BaggingClassifier( … InceptionTimeClassifierTorch(), … n_estimators=5, … bootstrap=False … ) # doctest: +SKIP >>> clf.fit(X_train, y_train) # doctest: +SKIP BaggingClassifier(…)

Methods

check_is_fitted([method_name])

Check if the estimator has been fitted.

clone()

Obtain a clone of the object with same hyper-parameters and config.

clone_tags(estimator[, tag_names])

Clone tags from another object as dynamic override.

create_test_instance([parameter_set])

Construct an instance of the class, using first test parameter set.

create_test_instances_and_names([parameter_set])

Create list of all test instances and a list of names for them.

fit(X, y)

Fit time series classifier to training data.

fit_predict(X, y[, cv, change_state])

Fit and predict labels for sequences in X.

fit_predict_proba(X, y[, cv, change_state])

Fit and predict labels probabilities for sequences in X.

get_class_tag(tag_name[, tag_value_default])

Get class tag value from class, with tag level inheritance from parents.

get_class_tags()

Get class tags from class, with tag level inheritance from parent classes.

get_config()

Get config flags for self.

get_fitted_params([deep])

Get fitted parameters.

get_param_defaults()

Get object's parameter defaults.

get_param_names([sort])

Get object's parameter names.

get_params([deep])

Get a dict of parameters values for this object.

get_tag(tag_name[, tag_value_default, ...])

Get tag value from instance, with tag level inheritance and overrides.

get_tags()

Get tags from instance, with tag level inheritance and overrides.

get_test_params([parameter_set])

Return testing parameter settings for the estimator.

is_composite()

Check if the object is composed of other BaseObjects.

load_from_path(serial)

Load object from file location.

load_from_serial(serial)

Load object from serialized memory container.

predict(X)

Predicts labels for sequences in X.

predict_proba(X)

Predicts labels probabilities for sequences in X.

reset()

Reset the object to a clean post-init state.

save([path, serialization_format])

Save serialized self to bytes-like object or to (.zip) file.

score(X, y)

Scores predicted labels against ground truth labels on X.

set_config(**config_dict)

Set config flags to given values.

set_params(**params)

Set the parameters of this object.

set_random_state([random_state, deep, ...])

Set random_state pseudo-random seed parameters for self.

set_tags(**tag_dict)

Set instance level tag overrides to given values.