topoloss
Project description
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
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
topoloss-0.0.2.tar.gz
(8.0 kB
view details)
Built Distribution
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 topoloss-0.0.2.tar.gz.
File metadata
- Download URL: topoloss-0.0.2.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63a0a17203789066bca19a8dd1c67bd4b5c6a8806f46a6652de6f41527aeea7a
|
|
| MD5 |
3264bd39123ea3fbe1d2ba27d8966072
|
|
| BLAKE2b-256 |
e97c6d4af494bd873b67346d9800560809f0234138a7de75602ca4884acfcdf0
|
File details
Details for the file topoloss-0.0.2-py3-none-any.whl.
File metadata
- Download URL: topoloss-0.0.2-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17c21413bfc51ee11c6d6ea35deaf770c2203c569ff6f5afc2f7616c9dac2b0e
|
|
| MD5 |
1f1f219163577de8922501157f7171de
|
|
| BLAKE2b-256 |
dd9083fefa5a5c195ff342cc17f4322e735b15db715fc21c199a639ee509d923
|