CNNClassifierTorchSKTimeWrapper
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 setInstallation
Install the published package using pip or uv.
pip install sinapsis-sktime==1.0.0uv pip install sinapsis-sktime==1.0.0uv add sinapsis-sktime==1.0.0Configuration
Effective fields from the inspector schema, including nested Pydantic model fields.
Optional
Default: null
Optional
Default: "/sinapsis-hub/private/platform/sinapsis-hub/playground/publish"
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
Required
Default: null
Required
Default: null
Optional
Default: 0.01
Optional
Default: "auto"
Optional
Default: false
Optional
Default: true
Optional
Default: "ReduceLROnPlateau"
Optional
Default: "CrossEntropyLoss"
Optional
Default: "Adam"
Optional
Default: null
Optional
Default: 16
Optional
Default: 2000
Optional
Default: [6,12]
Optional
Default: null
Optional
Default: [7,7]
Optional
Default: null
Optional
Default: 3
Optional
Default: null
Optional
Default: null
Optional
Default: null
Optional
Default: "Sigmoid"
Configuration example
Generated from documented defaults. Replace any placeholders and complete required nested settings before running.
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
sinapsis_sktime.templates.sktime_classifiers.SKTimeDeepLearningClassifiersEnvironment variables
Environment definitions belong to their canonical Python modules.