ExhaustiveWeightedRandomSampler
ExhaustiveWeightedRandomSampler can exhaustively sample the indices with a specific weight over epochs.
Installation
pip install exhaustive-weighted-random-sampler
Usage & Comparasion
import torch
from torch.utils.data import WeightedRandomSampler
from exhaustive_weighted_random_sampler import ExhaustiveWeightedRandomSampler
sampler = WeightedRandomSampler([1, 1, 1, 1, 1, 1, 1, 1, 1, 10], num_samples=5)
for i in range(5):
print(list(sampler))
"""
output:
[4, 3, 9, 3, 4]
[0, 5, 0, 9, 8]
[9, 9, 0, 9, 2]
[9, 9, 7, 9, 9]
[9, 9, 9, 9, 9]
explain: there are no 1 and 6, but 0 appears three times
"""
sampler = ExhaustiveWeightedRandomSampler([1, 1, 1, 1, 1, 1, 1, 1, 1, 10], num_samples=5)
for i in range(5):
print(list(sampler))
"""
output:
[4, 6, 9, 9, 9]
[1, 0, 9, 9, 5]
[9, 7, 3, 8, 9]
[9, 2, 1, 9, 9]
[8, 9, 7, 3, 2]
explain: all the 0 to 8 appears in the yield results.
"""
Use in DDP
It can be used in DDP if pytorch-ignite has been installed.
from ignite.distributed import DistributedProxySampler
from torch.utils.data import DataLoader
dataset = ...
sampler = DistributedProxySampler(
ExhaustiveWeightedRandomSampler(weights, num_samples=10000)
)
loader = DataLoader(dataset, sampler=sampler, ...)
Metadata
Release files for exhaustive-weighted-random-sampler 0.0.2
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 |
|---|---|---|---|---|
| exhaustive-weighted-random-sampler-0.0.2.tar.gz | 3.3 kB | Without provenance | Details for exhaustive-weighted-random-sampler-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| exhaustive_weighted_random_sampler-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for exhaustive_weighted_random_sampler-0.0.2-py3-none-any.whl |
Total release size: 7.2 kB
Release files / exhaustive-weighted-random-sampler-0.0.2.tar.gz
| Download URL | exhaustive-weighted-random-sampler-0.0.2.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6aec0368a6cb3e73380b487b78812a38f0399c64272336e7993592bf76e428f6
|
|
BLAKE2b-256 checksum How to use checksums |
c7f26752de715714a48ef8f4491d5ded9838cb0bd5107688ed8ce3d6334a88d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.1
|
Release files / exhaustive_weighted_random_sampler-0.0.2-py3-none-any.whl
| Download URL | exhaustive_weighted_random_sampler-0.0.2-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0592f9ee40b8bb8299f339bb54816da5ccead2ca04164de0d27e33ccaeab1894
|
|
BLAKE2b-256 checksum How to use checksums |
918c1b72273e8b92f614e06efcba32990dcaac64486071771271f1747c88e0df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.1
|
Security for exhaustive-weighted-random-sampler 0.0.2
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.