Skip to main content

This package provides the reference implementation of the Convolutional Set Transformer (Chinello & Boracchi, 2025). It includes reusable Keras 3 layers for building CST architectures, and provides an easy interface to load and use the CST-15 model pre-trained on ImageNet.

Project description

Convolutional Set Transformer (cstmodels)

The cstmodels package provides the reference implementation of the Convolutional Set Transformer (Chinello & Boracchi, 2025). It includes reusable Keras 3 layers for building CST architectures, and provides an easy interface to load and use CST-15, the first set-learning backbone pre-trained on ImageNet.

If you have any questions or concerns, please feel free to contact me at federico.chinello@studbocconi.it. Full API documentation available Here.

Table of Contents

About Convolutional Set Transformers

Highlights:

  • CST is a novel deep learning architecture for processing image sets of arbitrary cardinality that are visually heterogeneous yet share high-level semantics (e.g., a common category, scene, or concept).
  • CST is general-purpose and supports a broad range of applications, including set-based classification tasks and Set Anomaly Detection.
  • In the domain of image-set processing, CST outperforms existing set-learning approaches such as Deep Sets and Set Transformer. Unlike these methods, which are inherently opaque, CST is fully compatible with standard CNN explainability tools, including Grad-CAM.
  • While Deep Sets and Set Transformer are typically trained from scratch, CST supports Transfer Learning: it can be pre-trained on large-scale datasets and then effectively adapted to diverse downstream tasks. We publicly release CST-15, the first set-learning backbone pre-trained on ImageNet.

Want to dive deeper? Check out our paper!

Unlike Deep Sets and Set Transformer, which are inherently opaque, CST is fully compatible with standard CNN explainability tools. The Figure above shows Grad-CAM overlays for an image set provided as input to CST-15, with respect to the ground-truth class.

Installation

You can install the latest release of cstmodels from PyPI:

pip install cstmodels

Loading CST-15

Instantiate CST-15 with or without pre-trained ImageNet weights:

from cstmodels import CST15

model = CST15(pretrained=True)

Building a CST from scratch

The package provides the tools needed to build a Convolutional Set Transformer from the ground up, including:

  • SetConv2D: the reference implementation of the SetConv2D block introduced in Chinello & Boracchi, 2025.
  • SmartReshape2D: a utility layer that reshapes tensors depending on whether a set dimension is present. It automatically converts between
    • (batch, set_size, H, W, C)(batch*set_size, H, W, C)
    • (batch*set_size, H, W, C)(batch, set_size, H, W, C)
      This is useful when switching between layers that operate per-image and those that require an explicit set structure.
from keras import layers
from cstmodels import SetConv2D, SmartReshape2D

def CST():
    input_layer = layers.Input(shape=(None, None, None, 3))
    # Input is: (batch_size, set_size, heigh, width, channels)
    # We reshape to: (batch_size * set_size, heigh, width, channels)
    x, set_size = SmartReshape2D()(input_layer)

    x = SetConv2D(32, 3, activation='relu', padding='same')(
        x, set_size=set_size
    )
    x = SetConv2D(32, 3, activation='relu', padding='same')(
        x, set_size=set_size
    )
    x = layers.MaxPooling2D()(x)

    x = SetConv2D(64, 3, activation='relu', padding='same')(
        x, set_size=set_size
    )
    x = SetConv2D(64, 3, activation='relu', padding='same')(
        x, set_size=set_size
    )
    x = layers.MaxPooling2D()(x)

    x = SetConv2D(128, 3, activation='relu', padding='same')(
        x, set_size=set_size
    )
    x = SetConv2D(128, 3, activation='relu', padding='same')(
        x, set_size=set_size
    )
    x = layers.MaxPooling2D()(x)

    x = layers.GlobalAveragePooling2D()(x) # -> (batch_size * set_size, channels)

    output_layer = layers.Dense(units=10, activation='softmax')(x)

    model = keras.Model(inputs=input_layer, outputs=output_layer)

    return model

model = CST()

Tutorial Notebooks

We provide two self-contained tutorials notebooks here:

  • cst_from_scratch.ipynb demonstrates how to build and train a CST from scratch on the CIFAR-10 dataset;
  • cst15_transfer_learning.ipynb illustrates how to adapt the pre-trained CST-15 backbone to new tasks, using colorectal histopathology images as a case study for Transfer Learning.

Citation

If you use this package in your research, please cite:

@misc{chinello2025convolutionalsettransformer,
      title={Convolutional Set Transformer}, 
      author={Federico Chinello and Giacomo Boracchi},
      year={2025},
      eprint={2509.22889},
      archivePrefix={arXiv},
      primaryClass={cs.CV},
      url={https://arxiv.org/abs/2509.22889}, 
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cstmodels-0.1.1.tar.gz (2.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cstmodels-0.1.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file cstmodels-0.1.1.tar.gz.

File metadata

  • Download URL: cstmodels-0.1.1.tar.gz
  • Upload date:
  • Size: 2.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for cstmodels-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0a5f4e8b75565afef05c2a317fb34d386e46abdd8f63d699ba622389446018e7
MD5 a0916c433772f37392138679e25302e7
BLAKE2b-256 cccc162d6d9216504b662958b66a4a77404fa2b5973696ec8893a62460056901

See more details on using hashes here.

File details

Details for the file cstmodels-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: cstmodels-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for cstmodels-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f3a4892bb4c9f7d3fbb19c1a61c75acfdfa45d6cc036c01b99fe2ccef7bc38a0
MD5 279a81a4bb1e9ab04a9d63155b9f07e6
BLAKE2b-256 c481cd2467ef154042e95f82167811cd99dda2048ff1f34dd6babbfacddfedff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page