Various loss function in tf, some of them were implemented by official tensorflow, but I prefer to pack them into a Layer class.
- CTC Loss
- Focal CTC Loss
- CTC Center Loss
- pytorch version from here
from unit_test import test_ctc_center_loss
n_class = 100
dims = 128
x = np.random.normal(size=(32, 16, dims)).astype(np.float32)
labels = np.random.randint(0, n_class, (32, 16)).astype(np.int32)
test_ctc_center_loss(x, labels, n_class, dims)
results:
torch loss: 127.31403
tf loss: 127.314026
loss diff: 7.6293945e-06
- BCE Loss
- CE Loss
- Center Loss
- Smooth L1 Loss
- Dice BCE Loss
- Dice Loss
- IoU Loss
from losses import *
# e.g. CTC Loss
loss = CTCLoss()
x = tf.random.normal([2, 10, 20])
y = tf.random.uniform([2, 10], maxval=20, dtype=tf.int32)
out = loss(x, y)
print(out)