Docs /Templates/ sinapsis-sktime

CNNClassifierTorchSKTimeWrapper

sinapsis-sktimeSKTimedynamicinferencemodelsprediction

Python template · sinapsis_sktime.templates.sktime_classifiers

Overview

Template for SkTime classification model training and inference for the deep_learning module.

CNNClassifierTorch — inherited documentation

Time Convolutional Neural Network (CNN) in PyTorch, as described in [1]_.

Zhao et al. 2017 uses MSE loss and sigmoid activation in all layers. To obtain same behaviour as Zhao et al. 2017, set activation and criterion to "sigmoid" and "MSELoss" respectively.

Adapted from the implementation from Fawaz et. al https://github.com/hfawaz/dl-4-tsc/blob/master/classifiers/cnn.py

Parameters ---------- num_epochs : int, default = 2000 Number of epochs to train the model. batch_size : int, default = 16 Size of each mini-batch. kernel_sizes : tuple of int, default = (7, 7) A tuple of length equal to the number of conv layers with each entry in the tuple specifies the kernel size for the corresponding convolutional layer. The length of ``kernel_sizes`` must be equal to the length of ``filter_sizes``. avg_pool_size : int, default = 3 Size of the average pooling window. filter_sizes : tuple of int, default = (6, 12) A tuple of length equal to the number of conv layers with each entry in the tuple specifies the filter size for the corresponding convolutional layer. The length of ``filter_sizes`` must be equal to the length of ``kernel_sizes``. padding : str, default = "auto" Padding for conv layers. "auto": "same" if series_length < 60 else "valid"; "valid" or "same" otherwise. use_bias : bool, default = True Whether to use bias in output layer. activation : str, 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.

activation_hidden : str, Callable, or None, default="Sigmoid" 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: ``Sigmoid``, ``ReLU``, ``Tanh``, ``Softmax``, ``LogSoftmax``. optimizer : str or callable, default = "Adam" Optimizer to use. Same as TF default (Adam). optimizer_kwargs : dict or None, default = None Additional keyword arguments for the optimizer. criterion : str or callable, default = "CrossEntropyLoss" Loss function for training. criterion_kwargs : dict or None, default = None Additional keyword arguments for the criterion. callbacks : None or str or tuple of str, default = "ReduceLROnPlateau" Learning rate schedulers as callbacks. callback_kwargs : dict or None, default = None Keyword arguments for callbacks. lr : float, default = 0.01 Learning rate (TF CNN uses Adam(lr=0.01)). verbose : bool, default = False Whether to print progress 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_state : int or None, default = None Seed for reproducibility.

References ---------- .. [1] Zhao et al. Convolutional neural networks for time series classification, Journal of Systems Engineering and Electronics, 28(1):2017.

Examples -------- >>> from sktime.classification.deep_learning.cnn import CNNClassifierTorch >>> 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 = CNNClassifierTorch(num_epochs=20, batch_size=4) # doctest: +SKIP >>> clf.fit(X_train, y_train) # doctest: +SKIP CNNClassifierTorch(...)

Capabilities

Capabilities: not set

Installation

Install the published package using pip or uv.

Terminalbash
pip install sinapsis-sktime==1.0.0
uv pip install sinapsis-sktime==1.0.0
uv add sinapsis-sktime==1.0.0

Configuration

Effective fields from the inspector schema, including nested Pydantic model fields.

metadata
sinapsis_core.template_base.base_models.TemplateMetadata | None
Optional
Default: null
root_dir
str
Optional
Default: "/sinapsis-hub/private/platform/sinapsis-hub/playground/publish"
model_save_pathRequired
Path where the trained model will be saved. cnnclassifiertorch_init num_epochs <class 'int'>: default: 2000 batch_size <class 'int'>: default: 16 kernel_sizes typing.Optional[tuple[int, ...]]: default: (7, 7)… Read full field description

Path where the trained model will be saved. cnnclassifiertorch_init num_epochs <class 'int'>: default: 2000 batch_size <class 'int'>: default: 16 kernel_sizes typing.Optional[tuple[int, ...]]: default: (7, 7) avg_pool_size <class 'int'>: default: 3 filter_sizes typing.Optional[tuple[int, ...]]: default: (6, 12) padding <class 'str'>: default: auto use_bias <class 'bool'>: default: True activation typing.Union[str, collections.abc.Callable, NoneType]: default: None activation_hidden typing.Union[str, collections.abc.Callable, NoneType]: default: Sigmoid optimizer typing.Union[str, collections.abc.Callable, NoneType]: default: Adam optimizer_kwargs typing.Optional[dict]: default: None criterion typing.Union[str, collections.abc.Callable, NoneType]: default: CrossEntropyLoss criterion_kwargs typing.Optional[dict]: default: None callbacks typing.Union[NoneType, str, tuple[str, ...]]: default: ReduceLROnPlateau callback_kwargs typing.Optional[dict]: default: None lr <class 'float'>: default: 0.01 verbose <class 'bool'>: default: False init_weights typing.Optional[str]: default: None random_state typing.Optional[int]: default: None

str
Required
Default: null
cnnclassifiertorch_initRequired
CNNClassifierTorchAttributes
Required
Default: null
lr
float
Optional
Default: 0.01
padding
str
Optional
Default: "auto"
verbose
bool
Optional
Default: false
use_bias
bool
Optional
Default: true
callbacks
typing.Union[NoneType, str, tuple[str, ...]]
Optional
Default: "ReduceLROnPlateau"
criterion
typing.Union[str, collections.abc.Callable, NoneType]
Optional
Default: "CrossEntropyLoss"
optimizer
typing.Union[str, collections.abc.Callable, NoneType]
Optional
Default: "Adam"
activation
typing.Union[str, collections.abc.Callable, NoneType]
Optional
Default: null
batch_size
int
Optional
Default: 16
num_epochs
int
Optional
Default: 2000
filter_sizes
typing.Optional[tuple[int, ...]]
Optional
Default: [6,12]
init_weights
typing.Optional[str]
Optional
Default: null
kernel_sizes
typing.Optional[tuple[int, ...]]
Optional
Default: [7,7]
random_state
typing.Optional[int]
Optional
Default: null
avg_pool_size
int
Optional
Default: 3
callback_kwargs
typing.Optional[dict]
Optional
Default: null
criterion_kwargs
typing.Optional[dict]
Optional
Default: null
optimizer_kwargs
typing.Optional[dict]
Optional
Default: null
activation_hidden
typing.Union[str, collections.abc.Callable, NoneType]
Optional
Default: "Sigmoid"

Configuration example

Generated from documented defaults. Replace any placeholders and complete required nested settings before running.

yaml
templates:
  - template_name: "CNNClassifierTorchSKTimeWrapper"
    class_name: "CNNClassifierTorchSKTimeWrapper"
    attributes:
      root_dir: "/sinapsis-hub/private/platform/sinapsis-hub/playground/publish"
      model_save_path: "<required>"
      cnnclassifiertorch_init:
        lr: 0.01
        padding: "auto"
        verbose: false
        use_bias: true
        callbacks: "ReduceLROnPlateau"
        criterion: "CrossEntropyLoss"
        optimizer: "Adam"
        activation: null
        batch_size: 16
        num_epochs: 2000
        filter_sizes: [6, 12]
        init_weights: null
        kernel_sizes: [7, 7]
        random_state: null
        avg_pool_size: 3
        callback_kwargs: null
        criterion_kwargs: null
        optimizer_kwargs: null
        activation_hidden: "Sigmoid"

Inheritance

Immediate parent: sinapsis_sktime.templates.sktime_classifiers.SKTimeDeepLearningClassifiers

Environment variables

Environment definitions belong to their canonical Python modules.

SINAPSIS_BUILD_DOCS · defined elsewhere