Skip to main content

Serron

Mathematical Morphology module for PyTorch (CUDA), providing differentiable operators and learnable network layers.

Install

Prebuilt wheels are published for CPython 3.12–3.14 on Linux (x86_64, aarch64) and Windows (x86_64). A working CUDA-enabled PyTorch (torch >= 2.12) must already be installed in the environment.

pip install serron

Usage

Alpha: the CUDA kernels are not wired up yet, so the operators below currently raise NotImplementedError.

Serron works on standard PyTorch tensors laid out as (N, C, H, W) and living on a CUDA device.

Functional operators

Stateless operators live in serron.functional and are re-exported at the top level. Each takes an input tensor, a structuring element, and an optional border mode:

import torch
import serron
from serron import BorderMode
from serron import structuring_element as se

x = torch.rand(1, 1, 256, 256, device="cuda")
kernel = se.disk(3, device="cuda")

eroded = serron.erosion(x, kernel)
dilated = serron.dilatation(x, kernel)
opened = serron.opening(x, kernel)
closed = serron.closing(x, kernel)

# Derived operators
grad = serron.gradient(x, kernel)  # dilate(x) - erode(x)
white = serron.top_hat(x, kernel)  # x - open(x)
black = serron.black_hat(x, kernel)  # close(x) - x

# Control border handling
eroded_reflect = serron.erosion(x, kernel, border=BorderMode.REFLECT)

Available operators: erosion, dilatation, opening, closing, gradient, top_hat, black_hat.

Structuring elements

serron.structuring_element builds common SE shapes on the requested device:

from serron import structuring_element as se

se.square(5, device="cuda")  # (5, 5) full square
se.cross(5, device="cuda")  # (5, 5) plus shape
se.disk(3, device="cuda")  # (7, 7) disk, radius 3
se.diamond(3, device="cuda")  # (7, 7) diamond, radius 3
se.from_tensor(my_weights)  # wrap an arbitrary 2-D tensor as a grayscale SE

Border modes

BorderMode controls how out-of-bounds neighbors are handled:

Mode Behavior
BorderMode.REPLICATE Repeat the edge value (default)
BorderMode.REFLECT Mirror across the edge
BorderMode.CONSTANT Pad with a constant

Learnable layers

serron also exposes torch.nn.Module layers with a learnable structuring element, so morphology can be trained end-to-end inside a network. Each layer takes the number of channels and a kernel_size:

import torch
from serron import Erosion2d, Dilation2d, Opening2d, Closing2d
from serron import BorderMode

layer = Erosion2d(channels=3, kernel_size=5, border=BorderMode.REPLICATE).cuda()

x = torch.rand(8, 3, 64, 64, device="cuda")
y = layer(x)  # forward pass; layer.weight is a trainable (C, k, k) SE
y.sum().backward()  # gradients flow into layer.weight

Available layers: Erosion2d, Dilation2d, Opening2d, Closing2d.

Building from source

Clone repo

git clone git@github.com:vhrabar/serron.git
cd serron

Choosing a torch build

torch is pulled from a specific wheel index via mutually-exclusive extras. Pick the one matching your machine — plain uv sync (no extra) falls back to the default CUDA-enabled wheel from PyPI:

uv sync --extra cu132   # CUDA build
uv sync --extra cpu     # CPU-only build

Building the wheel

Building the CUDA extension from source needs the CUDA 13.X toolkit (nvcc):

uv sync --package serron --no-dev --group build --extra cu132
uv build --package serron --wheel --no-build-isolation

On a GPU-less machine, sync the CPU torch build instead, the extension then builds C++ only (no nvcc required):

uv sync --package serron --no-dev --group build --extra cpu
uv build --package serron --wheel --no-build-isolation

License

MIT

Copyright © 2026 Vedran Hrabar.

Download files

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

Source Distribution

serron-0.1.1.tar.gz (14.4 kB view details)

Uploaded Source

Built Distributions

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

serron-0.1.1-cp314-cp314-win_amd64.whl (524.1 kB view details)

Uploaded CPython 3.14Windows x86-64

serron-0.1.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (46.5 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

serron-0.1.1-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (44.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

serron-0.1.1-cp313-cp313-win_amd64.whl (528.1 kB view details)

Uploaded CPython 3.13Windows x86-64

serron-0.1.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (46.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

serron-0.1.1-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (44.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

serron-0.1.1-cp312-cp312-win_amd64.whl (528.1 kB view details)

Uploaded CPython 3.12Windows x86-64

serron-0.1.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (46.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

serron-0.1.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (44.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

File details

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

File metadata

  • Download URL: serron-0.1.1.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for serron-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0a00a93c7e5f7b60fac95c1a0b1a9d49cdca26b6aface38fcce4adaaf42068d6
MD5 956a3c513efc6baacb38a13166336f82
BLAKE2b-256 31aa56fab0866f29b4270892cbe7feef16376cf8d77a36e1d3447db7fd0bd0d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.1.1.tar.gz:

Publisher: publish-pypi.yml on vhrabar/serron

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file serron-0.1.1-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: serron-0.1.1-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 524.1 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for serron-0.1.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 8ed89d8c059eac5d17817cb0006cbefdcaa6ca85e7e62705654a63ffb1a75bf5
MD5 70c45575ac4a5f49e67130e355872f77
BLAKE2b-256 3f787a115a46f287ede43cd3907c02dde1aad4ad66c230341c203645c74eedfa

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.1.1-cp314-cp314-win_amd64.whl:

Publisher: publish-pypi.yml on vhrabar/serron

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file serron-0.1.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for serron-0.1.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 27fae28b9cda08a1e67d5bd32016a1639131ac8048ddd6cb78c9e656eebd7f07
MD5 a7ec050a2648ee7d91b56ae03b84c681
BLAKE2b-256 5573856d5dda096f7841737e398577d8c53c7bc3145c19498e455be1006b02de

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.1.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish-pypi.yml on vhrabar/serron

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file serron-0.1.1-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for serron-0.1.1-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f0b14eed081ca8d245cfbf6ef556886dd0ea27e359c17d5cba1a7714cb48cd28
MD5 c312d23245c348399f64621b56d7eea9
BLAKE2b-256 44f93e868974e76e3b907e9db540d7edd5930d05d638ba280f1363c7d8ee4bdf

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.1.1-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:

Publisher: publish-pypi.yml on vhrabar/serron

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file serron-0.1.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: serron-0.1.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 528.1 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for serron-0.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 77394eaa2735b7df69bc289d00ad198bdcf8ed26708a39c172bf2294930856a4
MD5 72f6ea8616ee956558d1eb5beeaf1273
BLAKE2b-256 7c45bfaf8179d7669bf24292d1bf7717b2e40c1052d3e4b0c0020a7ea00503c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.1.1-cp313-cp313-win_amd64.whl:

Publisher: publish-pypi.yml on vhrabar/serron

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file serron-0.1.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for serron-0.1.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e46f9e0c05e24197f32ec74c3dd48849844700cf7cb5ed29e405dc347e56ba67
MD5 dc3da87f896fa8f195182fb966c2fbf2
BLAKE2b-256 ba3c92f665fdc5f9f151c846409930ba563bef9acb3e7e1a2ee8a7dec391234d

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.1.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish-pypi.yml on vhrabar/serron

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file serron-0.1.1-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for serron-0.1.1-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 dcaee2d31bc87a2d41160d67d87282bcb4b10ff3424aa57602f6062fbe623242
MD5 57224ef02cfb32cac5a4a39310a9e307
BLAKE2b-256 de171d011dc8506817effa2b77c159ecc1bce36ff0bcc00478fec7c6248f2e8e

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.1.1-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:

Publisher: publish-pypi.yml on vhrabar/serron

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file serron-0.1.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: serron-0.1.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 528.1 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for serron-0.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 840132c9ecc29862313aeca8f07a96ef2647d5fbb167652bfb8889c983495989
MD5 5ac52396e9fbfe3609c6b411fa3063c5
BLAKE2b-256 e7953eb4a945cf118032b7b3f2580a1ef7bd72040fa5bece4c2e9b64e66413bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.1.1-cp312-cp312-win_amd64.whl:

Publisher: publish-pypi.yml on vhrabar/serron

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file serron-0.1.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for serron-0.1.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6fe3e99b2155ce7054e1e5b65ecd184b18e9685ce0e63546f0f30dc997065ec2
MD5 4767f93a8d408491b6f627b16b8b4c8e
BLAKE2b-256 0827038cea14c230a968c5f0d7c8bc03adf397c0a9dfb4bc148a0f7917ce396f

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.1.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish-pypi.yml on vhrabar/serron

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file serron-0.1.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for serron-0.1.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3c0360928090f18f6c022eb0a11411662ab161f38a65b743796e0d29fccfbb82
MD5 f9f204517f583ded7d03937a34e41571
BLAKE2b-256 e2cccb3ca445949bab52c83f7f232c2769194d0e08b532acdec96a811f7b2535

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.1.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:

Publisher: publish-pypi.yml on vhrabar/serron

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.3.1

10 files

0.2.0

10 files

This release

0.1.1 This release

10 files

0.1.0

10 files

0.0.1

10 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page