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).

pip install serron

Usage

Serron works on standard PyTorch tensors laid out as (N, C, H, W) and living on a CUDA or CPU 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.dilation(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, dilation, 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 13.2 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.3.1.tar.gz (18.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.3.1-cp314-cp314-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.14Windows x86-64

serron-0.3.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (47.4 MB view details)

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

serron-0.3.1-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (45.1 MB view details)

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

serron-0.3.1-cp313-cp313-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.13Windows x86-64

serron-0.3.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (47.4 MB view details)

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

serron-0.3.1-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (45.1 MB view details)

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

serron-0.3.1-cp312-cp312-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.12Windows x86-64

serron-0.3.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (47.4 MB view details)

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

serron-0.3.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (45.1 MB view details)

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

File details

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

File metadata

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

File hashes

Hashes for serron-0.3.1.tar.gz
Algorithm Hash digest
SHA256 5097e28263ae1b498d57792ebe2ac4a93b0a8079aa09a94a012f5a882ecd4270
MD5 139bf1c53618190db1d8370013882adf
BLAKE2b-256 94d98753a3ab849c4121a93d7bf1228216f4682b1a2b349c14e34843313e0f2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.3.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.3.1-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: serron-0.3.1-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for serron-0.3.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 d60d887ba9d089b9b6c69531f48f0a42d895b72e1ed89b09e90b863cd4918ccb
MD5 5a688113c176555ea0aa7e8c6e67e06a
BLAKE2b-256 cb551fdf7e56f6d5a2537a2466e73fff441a8d50698a50eb441aff8fa79a6396

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.3.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.3.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for serron-0.3.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c3dc7b04bb57f9999b8e5d856d966230a530dc298907f981965b0597db158c24
MD5 218ddc680b55864a32420d50f17e1557
BLAKE2b-256 94b462aea6a5c6a6f7c92e2af3d10a48810f0470bbb2a70bcfc74c8d4f21920f

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.3.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.3.1-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for serron-0.3.1-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d37f24c616b2f1cd47250f9a239cd8d2286736740fbc6b2639f5f5adbe7e7d3c
MD5 2a80dd147aac8c01cf064bd780b382e8
BLAKE2b-256 4d7404ae4386f468ed847ddbc744422c6103d06713fef10d538e39a60761a7f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.3.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.3.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: serron-0.3.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for serron-0.3.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 47ce899497abde8d609a0ce7e66cc9fb75067ec27ce010c68a9f484e7c3b4e0e
MD5 4693a25c5f6a030f0cc529912452147c
BLAKE2b-256 20ec1cd37d255966a26baf77650594f23af26107ba4547660622906f87678050

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.3.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.3.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for serron-0.3.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 60d5cb59bc4dfc9ed7fcfbdc2327a70962f0f77da26e0cb0f463042d66caa151
MD5 2356f6ff3f6ae456a60b161726c3f356
BLAKE2b-256 b2e551b04abaa9fce664f59a23ce529f94ad53f7443db320430e6131b2ec5d0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.3.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.3.1-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for serron-0.3.1-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 39d10d5acdc14d5837fa56dc6aeb10d299f08777afa07bd569e83676ba26ed1a
MD5 49ed16ea1888eb481f04fa09f8427ecf
BLAKE2b-256 1af946fdcc193e351bb94e35f6b9dc3f4fb8e18965ddf30187eb19805f1c5fd2

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.3.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.3.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: serron-0.3.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for serron-0.3.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 49e51f438115f4ae07e40d45e960ebb5a8e014347cc8e4b31b6b172455bdeab6
MD5 6b3e929b049b92fb1f64ecb03d67ef49
BLAKE2b-256 11685b26c4de7592cfa80a7a8034377b6ef2ca0fa3de2f5d3c3400e56898e9d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.3.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.3.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for serron-0.3.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3c83c58ec3b04ebb5307afdbfb8dd6a1ee33e9f8ce67ad8611b077431f190298
MD5 46e013a3ed3e6541f671a05d52a18b6e
BLAKE2b-256 f29cc053e088e3f4d5ee6acccebaaeec1266ec6cc4128b7bfeb50550523d8d5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.3.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.3.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for serron-0.3.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 c9d200f9b1bf29075a971be6f4b0021d064405ebb0f1c281ea890be8e645ba35
MD5 de2aefc121ab7ead9f6f0dd6e7deb250
BLAKE2b-256 53424d044084d72abb6811b2816188d773939b5d628484088c726f53b78e7405

See more details on using hashes here.

Provenance

The following attestation bundles were made for serron-0.3.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

This release

0.3.1 This release

10 files

0.2.0

10 files

0.1.1

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