Mathematical Morphology module for PyTorch (CUDA), providing differentiable operators and learnable network layers.
Project description
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
Requires the CUDA 13.X toolkit (nvcc) and a matching torch build:
uv sync --package serron --no-dev --group build
uv build --package serron --wheel --no-build-isolation
License
MIT
Copyright © 2026 Vedran Hrabar.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file serron-0.1.0.tar.gz.
File metadata
- Download URL: serron-0.1.0.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b9f94815689aa202afe7c2b955cee3c611e7bf0ec6c7d6ed21c0e1fd55714dd
|
|
| MD5 |
e17d69a07073692cf41b9645e2daa267
|
|
| BLAKE2b-256 |
74dfb24e2899192acd1b42b07e99e5d201169e86c89924dc3be47171a2e7a4ab
|
Provenance
The following attestation bundles were made for serron-0.1.0.tar.gz:
Publisher:
publish-pypi.yml on vhrabar/serron
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
serron-0.1.0.tar.gz -
Subject digest:
6b9f94815689aa202afe7c2b955cee3c611e7bf0ec6c7d6ed21c0e1fd55714dd - Sigstore transparency entry: 2195006762
- Sigstore integration time:
-
Permalink:
vhrabar/serron@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file serron-0.1.0-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: serron-0.1.0-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 519.0 kB
- Tags: CPython 3.14, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9388d12c8355af14eb1526f4e8d27f8e7a0262fe55e4ec0abbac254ea3c0320a
|
|
| MD5 |
7a8431e2dcdb31bcf4bf1a38b31060a3
|
|
| BLAKE2b-256 |
47c941566d3ec43bc908a7e7ba3942f7dac9c921a1cf003260f99f0b69d5f661
|
Provenance
The following attestation bundles were made for serron-0.1.0-cp314-cp314-win_amd64.whl:
Publisher:
publish-pypi.yml on vhrabar/serron
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
serron-0.1.0-cp314-cp314-win_amd64.whl -
Subject digest:
9388d12c8355af14eb1526f4e8d27f8e7a0262fe55e4ec0abbac254ea3c0320a - Sigstore transparency entry: 2195006804
- Sigstore integration time:
-
Permalink:
vhrabar/serron@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file serron-0.1.0-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: serron-0.1.0-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 46.5 MB
- Tags: CPython 3.14, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26ba8f611e716c625d68b62a0bc5d2c61f42ca05b8a7a39dde520ddaef8a1cc5
|
|
| MD5 |
9e86267b3f45d46da7dcfd58291cd483
|
|
| BLAKE2b-256 |
eb76429cc5e556cab8fe61ff773f6fcc0525b47e20da6a0d808d1ce0043aa39a
|
Provenance
The following attestation bundles were made for serron-0.1.0-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
publish-pypi.yml on vhrabar/serron
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
serron-0.1.0-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
26ba8f611e716c625d68b62a0bc5d2c61f42ca05b8a7a39dde520ddaef8a1cc5 - Sigstore transparency entry: 2195006766
- Sigstore integration time:
-
Permalink:
vhrabar/serron@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file serron-0.1.0-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: serron-0.1.0-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 44.2 MB
- Tags: CPython 3.14, manylinux: glibc 2.24+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cfba3a12b7d175509e61db4973ebfeefdede762961970f6ff479833806bd802
|
|
| MD5 |
c89dbf6274add10731e91acd6e3f9037
|
|
| BLAKE2b-256 |
22a6f3c9bd8a024c9dd122f194185498e77002fd4f44d762c2b04ddab4a4c6dd
|
Provenance
The following attestation bundles were made for serron-0.1.0-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:
Publisher:
publish-pypi.yml on vhrabar/serron
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
serron-0.1.0-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl -
Subject digest:
1cfba3a12b7d175509e61db4973ebfeefdede762961970f6ff479833806bd802 - Sigstore transparency entry: 2195006789
- Sigstore integration time:
-
Permalink:
vhrabar/serron@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file serron-0.1.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: serron-0.1.0-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 523.4 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00f1ce4bbad53bb4373cb610e74a3430611326c5f9a06d712d655fa9fafbc50b
|
|
| MD5 |
5a6758372ec6a8b0061045b643f9d439
|
|
| BLAKE2b-256 |
467675cf6f6801e54a860ec48b8d3bee14ce791c19521c749780a485a6b43462
|
Provenance
The following attestation bundles were made for serron-0.1.0-cp313-cp313-win_amd64.whl:
Publisher:
publish-pypi.yml on vhrabar/serron
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
serron-0.1.0-cp313-cp313-win_amd64.whl -
Subject digest:
00f1ce4bbad53bb4373cb610e74a3430611326c5f9a06d712d655fa9fafbc50b - Sigstore transparency entry: 2195006822
- Sigstore integration time:
-
Permalink:
vhrabar/serron@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file serron-0.1.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: serron-0.1.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 46.5 MB
- Tags: CPython 3.13, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a44d65ce37a4f7f3e5cc6ca0d75118a91999d29d03361dabd31d544eb5f0569
|
|
| MD5 |
a734e0c6490853fce0d9d7dfe6b391d7
|
|
| BLAKE2b-256 |
5b110ca93ff7be1ede6336157561fbaea5375d1fc2e195a79b029057e34759c7
|
Provenance
The following attestation bundles were made for serron-0.1.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
publish-pypi.yml on vhrabar/serron
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
serron-0.1.0-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
9a44d65ce37a4f7f3e5cc6ca0d75118a91999d29d03361dabd31d544eb5f0569 - Sigstore transparency entry: 2195006814
- Sigstore integration time:
-
Permalink:
vhrabar/serron@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file serron-0.1.0-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: serron-0.1.0-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 44.2 MB
- Tags: CPython 3.13, manylinux: glibc 2.24+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56990101944f753f8366b26d97462b7199a3408cc77f1cc7a0c1123227527748
|
|
| MD5 |
56ebf6e70edc1583b75b78901778eefc
|
|
| BLAKE2b-256 |
cccbaec0d37eac851be051a59842c2047c0bbe641a65a2eee6d52da5a61ea0c1
|
Provenance
The following attestation bundles were made for serron-0.1.0-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:
Publisher:
publish-pypi.yml on vhrabar/serron
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
serron-0.1.0-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl -
Subject digest:
56990101944f753f8366b26d97462b7199a3408cc77f1cc7a0c1123227527748 - Sigstore transparency entry: 2195006831
- Sigstore integration time:
-
Permalink:
vhrabar/serron@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file serron-0.1.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: serron-0.1.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 523.4 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00cbdc23051a8d5f6e4c53ff0fc792e6646a6e1691779fa391dec14238a1ac85
|
|
| MD5 |
48d27e0198c0bca059ead695c5892f1e
|
|
| BLAKE2b-256 |
f8dd1df6f29c6d18c816fba9b588ae22bf7829af69e0f554324beb9c7a0baabd
|
Provenance
The following attestation bundles were made for serron-0.1.0-cp312-cp312-win_amd64.whl:
Publisher:
publish-pypi.yml on vhrabar/serron
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
serron-0.1.0-cp312-cp312-win_amd64.whl -
Subject digest:
00cbdc23051a8d5f6e4c53ff0fc792e6646a6e1691779fa391dec14238a1ac85 - Sigstore transparency entry: 2195006795
- Sigstore integration time:
-
Permalink:
vhrabar/serron@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file serron-0.1.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: serron-0.1.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 46.5 MB
- Tags: CPython 3.12, manylinux: glibc 2.24+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
883fb24d643913c5a9cd4d86204d70b97f3c9bd705e19ca748a69a1f687e63d0
|
|
| MD5 |
1242aa7b4e513bef6dd3583e82916249
|
|
| BLAKE2b-256 |
7a24c2bd0b715ccba411fc1abd8b52a832b1e602d3edd83fbc0a3da3788e585d
|
Provenance
The following attestation bundles were made for serron-0.1.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
publish-pypi.yml on vhrabar/serron
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
serron-0.1.0-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
883fb24d643913c5a9cd4d86204d70b97f3c9bd705e19ca748a69a1f687e63d0 - Sigstore transparency entry: 2195006779
- Sigstore integration time:
-
Permalink:
vhrabar/serron@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file serron-0.1.0-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.
File metadata
- Download URL: serron-0.1.0-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
- Upload date:
- Size: 44.2 MB
- Tags: CPython 3.12, manylinux: glibc 2.24+ ARM64, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7933db9936cbab2fc026705e00de62ae1dcb7cad089ed042411d5ad3d6f3a8a
|
|
| MD5 |
9f2ff32a9f0343e5894b20e3f8f3bc85
|
|
| BLAKE2b-256 |
2824e9421c9021fc0c3c9077b775bcb5cc227d57133fa61450b108ff4fb7d4a6
|
Provenance
The following attestation bundles were made for serron-0.1.0-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl:
Publisher:
publish-pypi.yml on vhrabar/serron
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
serron-0.1.0-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl -
Subject digest:
a7933db9936cbab2fc026705e00de62ae1dcb7cad089ed042411d5ad3d6f3a8a - Sigstore transparency entry: 2195006773
- Sigstore integration time:
-
Permalink:
vhrabar/serron@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vhrabar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@2d8507cbc26cdd8a88acd258eee19d4be5a9d52b -
Trigger Event:
workflow_run
-
Statement type: