torch_ecg.models#

This module contains the model architectures for ECG various tasks.

Convolutional neural backbones#

ResNet(in_channels, **config)

ResNet model.

RegNet(in_channels, **config)

RegNet model.

VGG16(in_channels, **config)

CNN feature extractor of VGG architecture.

Xception(in_channels, **config)

Xception model.

DenseNet(in_channels, **config)

The core part of the SOTA model (framework) of CPSC2020.

MobileNetV1(in_channels, **config)

MobileNet V1.

MobileNetV2(in_channels, **config)

MobileNet V2.

MobileNetV3(in_channels, **config)

MobileNet V3.

MultiScopicCNN(in_channels, **config)

CNN part of the SOTA model from CPSC2019 challenge (entry 0416).

Downstream task models#

ECG_UNET(classes, n_leads[, config])

U-Net for (multi-lead) ECG wave delineation.

ECG_SUBTRACT_UNET(classes, n_leads[, config])

U-Net for ECG wave delineation.

ECG_CRNN(classes, n_leads[, config])

Convolutional (Recurrent) Neural Network for ECG tasks.

ECG_SEQ_LAB_NET(classes, n_leads[, config])

SOTA model from CPSC2019 challenge.

RR_LSTM(classes[, config])

LSTM model for RR time series classification or sequence labeling.

Saliency analysis#

GradCam(model, feature_module, ...[, ...])

Gradient-weighted Class Activation Mapping for ECG models.

Transformer backbones#

Transformer(input_size, hidden_size[, ...])

Transformer feature extractor.

Registries#

MODELS

Registry for managing and building modules.

BACKBONES

Registry for managing and building modules.

torch_ecg.model_configs#

Ready-made configurations for the model architectures and their building blocks. A config is a plain CFG; pick one, adapt it, and pass it to the model constructor together with n_leads / n_classes (see the tutorial):

>>> from torch_ecg.model_configs import ECG_CRNN_CONFIG
>>> from torch_ecg.models import ECG_CRNN
>>> config = ECG_CRNN_CONFIG.copy()
>>> config.cnn.name = "resnet_block_leadwise"
>>> model = ECG_CRNN(config, n_leads=12, n_classes=26)

Full model configs#

Each top-level *_CONFIG collects the complete specification of one architecture family (fs, cnn, rnn, attn, clf, …); its cnn / rnn / attn entries accept any of the building blocks catalogued below.

CNN building blocks (cnn submodule)#

Grouped by family; *_leadwise variants use lead-wise (per-lead) convolutions adapted to 12-lead ECG, *_gc / *_nl / *_se suffixes add global-context / non-local / squeeze-and-excitation attention to the block.

  • VGG family: vgg16, vgg16_leadwise, vgg_block_basic, vgg_block_mish, vgg_block_swish

  • vanilla ResNet: resnet_vanilla_18/34/50/101/152, wide variants resnet_vanilla_wide_50_2, resnet_vanilla_wide_101_2, blocks resnet_block_basic, resnet_bottle_neck

  • CPSC2018-style ResNet (small, contest-proven): resnet_cpsc2018, resnet_cpsc2018_leadwise, blocks cpsc_block_basic/mish/swish, cpsc_2018, cpsc_2018_leadwise

  • scaled ResNet (He et al.): resnetN, resnetNB, resnetNS, resnetNBS, bottle-neck variants resnet_bottle_neck_B/D

  • stanford ResNet: resnet_stanford, resnet_block_stanford

  • ResNet Nature Communications (Moskalenko et al.): resnet_nature_comm + _bottle_neck and _gc/_nl/_se variants

  • TResNet (together with the block configs above): tresnetN/S/M/L/P/F/XL, tresnetM_V2

  • DenseNet: densenet_vanilla, densenet_leadwise

  • Xception: xception_vanilla, xception_leadwise

  • MobileNet: mobilenet_1_vanilla, mobilenet_2_vanilla, mobilenet_3_small

  • MultiScopicCNN (CPSC2019 winner): multi_scopic, multi_scopic_block, multi_scopic_leadwise

  • ResNeXt: resnext_vanilla_50_32x4d, resnext_vanilla_101_32x8d

Attention modules (attn submodule)#

Usable as the attn entry of the CRNN-family configs:

  • squeeze_excitation (SE), global_context (GC), non_local (NL)

  • transformer – multi-head self-attention (transformer_encoder style heads)

RNN configs (rnn submodule)#

  • lstm – bidirectional LSTM used after the CNN feature extractor

  • linear – non-recurrent (linear) alternative

MLP / heads (mlp submodule)#

  • linear – plain linear head

  • mlp – multi-layer perceptron classification head (with optional dropout)

Notes

cnn.name selects a backbone (family name or full config name), e.g. to switch the CRNN backbone to the SE-enhanced Nature-Communications ResNet (the default of the cinc2021 benchmark):

config.cnn.name = "resnet_nature_comm_bottle_neck_se"

Concrete end-to-end usages are linked from the examples (the benchmarks select and adapt these configs).