torchoutil
Collection of functions and modules to help development in PyTorch.
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.2%) to scientific vocabulary
Keywords
Repository
Collection of functions and modules to help development in PyTorch.
Basic Info
- Host: GitHub
- Owner: Labbeti
- License: mit
- Language: Python
- Default Branch: main
- Homepage: https://pypi.org/project/torchoutil/
- Size: 1.21 MB
Statistics
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 9
Topics
Metadata Files
README.md
torchoutil
Installation
bash
pip install torchoutil
The main requirement is PyTorch.
To check if the package is installed and show the package version, you can use the following command in your terminal:
bash
torchoutil-info
This library works on all Python versions >=3.8, all PyTorch versions >= 3.10, and on Linux, Mac and Windows systems.
Examples
torchoutil functions and modules can be used like torch ones. The default acronym for torchoutil is to.
Label conversions
Supports multiclass labels conversions between probabilities, classes indices, classes names and onehot encoding.
```python import torchoutil as to
probs = to.astensor([[0.9, 0.1], [0.4, 0.6]]) names = to.probstoname(probs, idxto_name={0: "Cat", 1: "Dog"})
["Cat", "Dog"]
```
This package also supports multilabel labels conversions between probabilities, classes multi-indices, classes multi-names and multihot encoding.
```python import torchoutil as to
multihot = to.astensor([[1, 0, 0], [0, 1, 1], [0, 0, 0]]) indices = to.multihotto_indices(multihot)
[[0], [1, 2], []]
```
Typing
```python import torchoutil as to
x1 = to.astensor([1, 2]) print(isinstance(x1, to.Tensor2D)) # False x2 = to.astensor([[1, 2], [3, 4]]) print(isinstance(x2, to.Tensor2D)) # True ```
```python import torchoutil as to
x1 = to.as_tensor([1, 2], dtype=to.int) print(isinstance(x1, to.SignedIntegerTensor)) # True
x2 = to.as_tensor([1, 2], dtype=to.long) print(isinstance(x2, to.SignedIntegerTensor)) # True
x3 = to.as_tensor([1, 2], dtype=to.float) print(isinstance(x3, to.SignedIntegerTensor)) # False ```
Padding
```python import torchoutil as to
x1 = to.rand(10, 3, 1) x2 = to.paddim(x, targetlength=5, dim=1, pad_value=-1)
x2 has shape (10, 5, 1)
```
```python import torchoutil as to
tensors = [to.rand(10, 2), to.rand(5, 3), to.rand(0, 5)] padded = to.padandstackrec(tensors, padvalue=0)
padded has shape (10, 5)
```
Masking
```python import torchoutil as to
x = to.astensor([3, 1, 2]) mask = to.lengthstononpadmask(x, maxlen=4)
Each row i contains x[i] True values for non-padding mask
tensor([[True, True, True, False],
[True, False, False, False],
[True, True, False, False]])
```
```python import torchoutil as to
x = to.astensor([1, 2, 3, 4]) mask = to.astensor([True, True, False, False]) result = to.masked_mean(x, mask)
result contains the mean of the values marked as True: 1.5
```
Others tensors manipulations!
```python import torchoutil as to
x = to.astensor([1, 2, 3, 4]) result = to.insertat_indices(x, indices=[0, 2], values=5)
result contains tensor with inserted values: tensor([5, 1, 2, 5, 3, 4])
```
```python import torchoutil as to
perm = to.randperm(10) invperm = to.getinverse_perm(perm)
x1 = to.rand(10) x2 = x1[perm] x3 = x2[inv_perm]
inv_perm are indices that allow us to get x3 from x2, i.e. x1 == x3 here
```
Pre-compute datasets to HDF files
Here is an example of pre-computing spectrograms of torchaudio SPEECHCOMMANDS dataset, using pack_dataset function:
```python from torchaudio.datasets import SPEECHCOMMANDS from torchaudio.transforms import Spectrogram from torchoutil import nn from torchoutil.extras.hdf import packtohdf
speechcommandsroot = "path/to/speechcommands" packedroot = "path/to/packed_dataset.hdf"
dataset = SPEECHCOMMANDS(speechcommandsroot, download=True, subset="validation")
dataset[0] is a tuple, contains waveform and other metadata
class MyTransform(nn.Module): def init(self) -> None: super().init() self.spectrogram_extractor = Spectrogram()
def forward(self, item):
waveform = item[0]
spectrogram = self.spectrogram_extractor(waveform)
return (spectrogram,) + item[1:]
packtohdf(dataset, packed_root, MyTransform()) ```
Then you can load the pre-computed dataset using HDFDataset:
```python
from torchoutil.extras.hdf import HDFDataset
packedroot = "path/to/packeddataset.hdf" packeddataset = HDFDataset(packedroot) packed_dataset[0] # == first transformed item, i.e. transform(dataset[0]) ```
Extras requirements
torchoutil also provides additional modules when some specific package are already installed in your environment.
All extras can be installed with pip install torchoutil[extras]
- If
tensorboardis installed, the functionload_event_filecan be used. It is useful to load manually all data contained in an tensorboard event file. - If
numpyis installed, the classesNumpyToTensorandToNumpycan be used and their related function. It is meant to be used to compose dynamic transforms intoSequentialmodule. - If
h5pyis installed, the functionpack_to_hdfand classHDFDatasetcan be used. Can be used to pack/read dataset to HDF files, and supports variable-length sequences of data. - If
pyyamlis installed, the functionsto_yamlandload_yamlcan be used.
Contact
Maintainer: - Étienne Labbé "Labbeti": labbeti.pub@gmail.com
Owner
- Name: Labbeti
- Login: Labbeti
- Kind: user
- Location: Toulouse, France
- Company: IRIT
- Website: labbeti.github.io
- Repositories: 5
- Profile: https://github.com/Labbeti
PhD student at IRIT (Institut de Recherche en Informatique de Toulouse), working mainly on Automated Audio Captioning.
Citation (CITATION.cff)
# -*- coding: utf-8 -*-
cff-version: 1.2.0
title: torchoutil
message: 'If you use this software, please cite it as below.'
type: software
authors:
- given-names: Étienne
family-names: Labbé
email: labbeti.pub@gmail.com
affiliation: IRIT
orcid: 'https://orcid.org/0000-0002-7219-5463'
repository-code: 'https://github.com/Labbeti/torchoutil/'
abstract: Collection of functions and modules to help development in PyTorch.
keywords:
- pytorch
- deep-learning
- utilities
license: MIT
version: 0.6.0
date-released: '2025-04-09'
GitHub Events
Total
- Release event: 2
- Watch event: 1
- Push event: 154
- Create event: 2
Last Year
- Release event: 2
- Watch event: 1
- Push event: 154
- Create event: 2
Committers
Last synced: about 1 year ago
Top Committers
| Name | Commits | |
|---|---|---|
| Labbeti | e****1@g****m | 8 |
| LABBE Etienne | e****e@i****r | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 8 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 32 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 9
- Total maintainers: 1
pypi.org: torchoutil
Collection of functions and modules to help development in PyTorch.
- Homepage: https://pypi.org/project/torchoutil/
- Documentation: https://torchoutil.readthedocs.io/
- License: MIT License Copyright (c) 2025 Labbeti Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-
Latest release: 0.6.0
published about 1 year ago
Rankings
Maintainers (1)
Dependencies
- actions/checkout v2 composite
- actions/setup-python v4 composite
- sphinx-press-theme >=0.8.0
- black ==23.11.0 development
- flake8 * development
- ipython * development
- pre-commit * development
- pytest * development
- twine * development
- torch >=1.4.0
- h5py *
- numpy *
- tensorboard *
- tqdm *