TopoLoss
Induce brain-like topographic structure in your neural networks.
Read the paper (ICLR 2025), check out the colab notebook and play with the pre-trained models 🤗
pip install topoloss
Example
import torchvision.models as models
from topoloss import TopoLoss, LaplacianPyramid
model = models.resnet18(weights = "DEFAULT")
topo_loss = TopoLoss(
losses = [
LaplacianPyramid.from_layer(
model=model,
layer = model.fc, ## supports nn.Linear and nn.Conv2d
factor_h=8.0,
factor_w=8.0,
scale = 1.0
),
],
)
loss = topo_loss.compute(model=model)
## >>> tensor(0.8407, grad_fn=<DivBackward0>)
loss.backward()
loss_dict = topo_loss.compute(model=model, reduce_mean = False) ## {"fc": }
## >>> {'fc': tensor(0.8407, grad_fn=<MulBackward0>)}
Running tests
pytest -vvx tests
Metadata
Release files for topoloss 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| topoloss-0.0.2.tar.gz | 8.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| topoloss-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.3 kB
Release files / topoloss-0.0.2.tar.gz
| Download URL | topoloss-0.0.2.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
63a0a17203789066bca19a8dd1c67bd4b5c6a8806f46a6652de6f41527aeea7a
|
|
BLAKE2b-256 checksum How to use checksums |
e97c6d4af494bd873b67346d9800560809f0234138a7de75602ca4884acfcdf0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.16
|
Release files / topoloss-0.0.2-py3-none-any.whl
| Download URL | topoloss-0.0.2-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
17c21413bfc51ee11c6d6ea35deaf770c2203c569ff6f5afc2f7616c9dac2b0e
|
|
BLAKE2b-256 checksum How to use checksums |
dd9083fefa5a5c195ff342cc17f4322e735b15db715fc21c199a639ee509d923
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.16
|