torch-baidu-ctc
Pytorch bindings for Baidu's Warp-CTC. These bindings were inspired by SeanNaren's but these include some bug fixes, and offer some additional features.
import torch
from torch_baidu_ctc import ctc_loss, CTCLoss
# Activations. Shape T x N x D.
# T -> max number of frames/timesteps
# N -> minibatch size
# D -> number of output labels (including the CTC blank)
x = torch.rand(10, 3, 6)
# Target labels
y = torch.tensor(
[
# 1st sample
1, 1, 2, 5, 2,
# 2nd
1, 5, 2,
# 3rd
4, 4, 2, 3,
],
dtype=torch.int,
)
# Activations lengths
xs = torch.tensor([10, 6, 9], dtype=torch.int)
# Target lengths
ys = torch.tensor([5, 3, 4], dtype=torch.int)
# By default, the costs (negative log-likelihood) of all samples are summed.
# This is equivalent to:
# ctc_loss(x, y, xs, ys, average_frames=False, reduction="sum")
loss1 = ctc_loss(x, y, xs, ys)
# You can also average the cost of each sample among the number of frames.
# The averaged costs are then summed.
loss2 = ctc_loss(x, y, xs, ys, average_frames=True)
# Instead of summing the costs of each sample, you can perform
# other `reductions`: "none", "sum", or "mean"
#
# Return an array with the loss of each individual sample
losses = ctc_loss(x, y, xs, ys, reduction="none")
#
# Compute the mean of the individual losses
loss3 = ctc_loss(x, y, xs, ys, reduction="mean")
#
# First, normalize loss by number of frames, later average losses
loss4 = ctc_loss(x, y, xs, ys, average_frames=True, reduction="mean")
# Finally, there's also a nn.Module to use this loss.
ctc = CTCLoss(average_frames=True, reduction="mean", blank=0)
loss4_2 = ctc(x, y, xs, ys)
# Note: the `blank` option is also available for `ctc_loss`.
# By default it is 0.
Requirements
- C++11 compiler (tested with GCC 4.9).
- Python: 2.7, 3.5, 3.6, 3.7 (tested with versions 2.7, 3.5 and 3.6).
- PyTorch >= 1.1.0 (tested with version 1.1.0).
- For GPU support: CUDA Toolkit.
Installation
The installation process should be pretty straightforward assuming that you have correctly installed the required libraries and tools.
The setup process compiles the package from source, and will compile with CUDA support if this is available for PyTorch.
From Pypi (recommended)
pip install torch-baidu-ctc
From GitHub
git clone --recursive https://github.com/jpuigcerver/pytorch-baidu-ctc.git
cd pytorch-baidu-ctc
python setup.py build
python setup.py install
AVX512 related issues
Some compiling problems may arise when using CUDA and newer host compilers
with AVX512 instructions. Please, install GCC 4.9 and use it as the host
compiler for NVCC. You can simply set the CC and CXX environment variables
before the build/install commands:
CC=gcc-4.9 CXX=g++-4.9 pip install torch-baidu-ctc
or (if you are using the GitHub source code):
CC=gcc-4.9 CXX=g++-4.9 python setup.py build
Testing
You can test the library once installed using unittest. In particular,
run the following commands:
python -m unittest torch_baidu_ctc.test
All tests should pass (CUDA tests are only executed if supported).
Metadata
Release files for torch-baidu-ctc 0.3.0
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 |
|---|---|---|---|---|
| torch-baidu-ctc-0.3.0.tar.gz | 54.9 kB | Without provenance | Details for torch-baidu-ctc-0.3.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| torch_baidu_ctc-0.3.0-cp37-cp37m-manylinux1_x86_64.whl | CPython 3.7 | CPython 3.7 pymalloc | Linux glibc 2.5+ x86-64 | Details for torch_baidu_ctc-0.3.0-cp37-cp37m-manylinux1_x86_64.whl |
| torch_baidu_ctc-0.3.0-cp36-cp36m-manylinux1_x86_64.whl | CPython 3.6 | CPython 3.6 pymalloc | Linux glibc 2.5+ x86-64 | Details for torch_baidu_ctc-0.3.0-cp36-cp36m-manylinux1_x86_64.whl |
| torch_baidu_ctc-0.3.0-cp35-cp35m-manylinux1_x86_64.whl | CPython 3.5 | CPython 3.5 pymalloc | Linux glibc 2.5+ x86-64 | Details for torch_baidu_ctc-0.3.0-cp35-cp35m-manylinux1_x86_64.whl |
| torch_baidu_ctc-0.3.0-cp27-cp27mu-manylinux1_x86_64.whl | CPython 2.7 | CPython 2.7 pymalloc wide-unicode | Linux glibc 2.5+ x86-64 | Details for torch_baidu_ctc-0.3.0-cp27-cp27mu-manylinux1_x86_64.whl |
Total release size: 10.8 MB
Release files / torch-baidu-ctc-0.3.0.tar.gz
| Download URL | torch-baidu-ctc-0.3.0.tar.gz |
|---|---|
| Size | 54.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1675682ca93d0915bfd54591b978bdd4bb78f12f73b9190326be29825b5e6e36
|
|
BLAKE2b-256 checksum How to use checksums |
46aab9a7c86f1fae5754f8fe108e05e9f4340a5aec1ff0d5afefcc55c91a6ff4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
|
Release files / torch_baidu_ctc-0.3.0-cp37-cp37m-manylinux1_x86_64.whl
| Download URL | torch_baidu_ctc-0.3.0-cp37-cp37m-manylinux1_x86_64.whl |
|---|---|
| Size | 2.7 MB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
2518a0a5d651f474e817e88d1b20093499e701067290d445154693b31c3dfeec
|
|
BLAKE2b-256 checksum How to use checksums |
182717d47d7eded8cfcbf6fc75b9281d5a0c5a6cb6da43161be539cd16eca154
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
|
Release files / torch_baidu_ctc-0.3.0-cp36-cp36m-manylinux1_x86_64.whl
| Download URL | torch_baidu_ctc-0.3.0-cp36-cp36m-manylinux1_x86_64.whl |
|---|---|
| Size | 2.7 MB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
84cfdcc044f044a1c71a120eac84e58f0e7a67d636433c2295bc0f15f3c2a97a
|
|
BLAKE2b-256 checksum How to use checksums |
547feadf62c7e541430ecb7dab16adabb7bdb757dafcbfc584e61c20187ed407
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
|
Release files / torch_baidu_ctc-0.3.0-cp35-cp35m-manylinux1_x86_64.whl
| Download URL | torch_baidu_ctc-0.3.0-cp35-cp35m-manylinux1_x86_64.whl |
|---|---|
| Size | 2.7 MB |
| Tags | CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
7a0e4da260d6d6e84351095ae00a8e333bf9a579d3825b200d7c9de383364edc
|
|
BLAKE2b-256 checksum How to use checksums |
5836989ef546ae94e276f4f31ec55d1ffa7d3b790b6f8d69cbe8d63aec137e5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
|
Release files / torch_baidu_ctc-0.3.0-cp27-cp27mu-manylinux1_x86_64.whl
| Download URL | torch_baidu_ctc-0.3.0-cp27-cp27mu-manylinux1_x86_64.whl |
|---|---|
| Size | 2.7 MB |
| Tags | CPython 2.7 CPython 2.7 pymalloc wide-unicode Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
db81e32f5e630ae91586328333222a9127eee747c9b72f3cca79c8b57729381b
|
|
BLAKE2b-256 checksum How to use checksums |
7d890275e493bcf97542363dba7481dd4e979a39a01753a605bd3de2b940516a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8
|
Security for torch-baidu-ctc 0.3.0
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.