nachiket273 / loss-tryout

PyTorch implementation of polyloss and cyclic focal loss and their performance with sample dataset/s.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

loss-tryout

PyTorch implementation of POLYLOSS: A POLYNOMIAL EXPANSION PERSPECTIVE OF CLASSIFICATION LOSS FUNCTIONS

polyloss.py contains the implementation of Poly-1 loss and Poly-1 focal loss.
While polynloss.py contains simple implementations of Poly-N and Poly-N focal loss. Note that this implemenation of Poly-N loss is just for experimenation.

Simple_Example_Polyloss.ipynb is notebook with simple examples of Poly-1 loss usage.

Usage

  1. Git clone the repoository and change to directory
git clone https://github.com/nachiket273/loss-tryout.git
cd loss-tryout
  1. Import
from polyloss import PolyLoss, PolyFocalLoss
  1. Poly crossentropy loss example
import torch
inputs = torch.rand((20, 5))
targets = torch.randint(high=5, size=(20,))
ploss = PolyLoss()
ploss(inputs, targets)
  1. Poly focal loss example
import torch
inputs = torch.rand((20, 5))
targets = torch.randint(high=5, size=(20,))
pfloss = PolyFocalLoss()
pfloss(inputs, targets)

Citations

@misc{POLYLOSS,
    title={POLYLOSS: A POLYNOMIAL EXPANSION PERSPECTIVE OF CLASSIFICATION LOSS FUNCTIONS},
    author={Zhaoqi Leng, Mingxing Tan, Chenxi Liu, Ekin Dogus Cubuk, Xiaojie Shi, Shuyang Cheng, Dragomir Anguelov},
    year={2022},
    url={https://arxiv.org/pdf/2204.12511.pdf},
}

About

PyTorch implementation of polyloss and cyclic focal loss and their performance with sample dataset/s.

License:MIT License


Languages

Language:Jupyter Notebook 92.0%Language:Python 8.0%