focal-loss-pytorch
Simple vectorized PyTorch implementation of binary unweighted focal loss as specified by [1].
Installation
This package can be installed using pip as follows:
python3 -m pip install focal-loss-pytorch
Example Usage
Here is a quick example of how to import the BinaryFocalLoss class and use it to train a model:
from focal_loss_pytorch.focal_loss_pytorch.focal_loss import BinaryFocalLoss
import torch
#Initialize device
device = 'cuda' if torch.cuda.is_available() else 'cpu'
#Initialize loss fn + optimizer
loss_fn = BinaryFocalLoss(gamma=5)
optimizer = torch.optim.Adam(model.parameters(), lr=learning_rate)
#Load datasets
train_loader = DataLoader(train_set, batch_size=10, shuffle=False)
val_loader = DataLoader(val_set, batch_size=10, shuffle=False)
#Train! :)
for e in range(epochs):
for data in train_loader:
model.train()
input_img = data['img'].to(device)
ref_img = data['ref'].to(device)
output_img = model(input_img)
loss = loss_fn(output_img, ref_img)
optimizer.zero_grad()
loss.backward()
optimizer.step()
Documentation
Documentation for this package is available on Read the Docs.
References
[1] Lin, T. Y., et al. "Focal loss for dense object detection." arXiv 2017." arXiv preprint arXiv:1708.02002 (2002).
Metadata
Release files for focal-loss-pytorch 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| focal_loss_pytorch-0.0.3.tar.gz | 14.5 kB | Without provenance | Details for focal_loss_pytorch-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| focal_loss_pytorch-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for focal_loss_pytorch-0.0.3-py3-none-any.whl |
Total release size: 28.9 kB
Release files / focal_loss_pytorch-0.0.3.tar.gz
| Download URL | focal_loss_pytorch-0.0.3.tar.gz |
|---|---|
| Size | 14.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5f3817152cbf07f6fb7374097f2ba0de24c8a197e695e1172f361cbf92a7a55f
|
|
BLAKE2b-256 checksum How to use checksums |
fa5bbf6154bfa8b2004fb995741f09fdab6bc55ffed15a0081d3c83cf021b620
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / focal_loss_pytorch-0.0.3-py3-none-any.whl
| Download URL | focal_loss_pytorch-0.0.3-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
42e6f325ea58df1a7824898457ec732f95c0f82948ca6fddd73f823c480e2c0d
|
|
BLAKE2b-256 checksum How to use checksums |
eeb8cba34303d9ae307750561de5e12f66c805d5b13cc13b60d982b8c9a575d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Security for focal-loss-pytorch 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.