Discrete Distribution Network
Project description
Discrete Distribution Network
Exploration into Discrete Distribution Network, by Lei Yang out of Beijing
Besides the split-and-prune, may also throw in an option for crossover (mixing of top 2 nodes to replace the pruned)
Install
$ discrete-distribution-network
Usage
import torch
from discrete_distribution_network import DDN
ddn = DDN(
dim = 32,
image_size = 256
)
images = torch.randn(2, 3, 256, 256)
loss = ddn(images)
loss.backward()
# after much training
sampled = ddn.sample(batch_size = 1)
assert sampled.shape == (1, 3, 256, 256)
The proposed GuidedSampler in the paper
import torch
from discrete_distribution_network import GuidedSampler
sampler = GuidedSampler(
dim = 16, # feature dimension
dim_query = 3, # the query image dimension
codebook_size = 10, # the codebook size K in the paper, which is K separate projections of the features, which is then measured distance wise to the query image guide
)
features = torch.randn(20, 16, 32, 32)
query_image = torch.randn(20, 3, 32, 32)
out, codes, commit_loss = sampler(features, query_image)
# (20, 3, 32, 32), (20,), ()
assert torch.allclose(sampler.forward_for_codes(features, codes), out, atol = 1e-5)
# after optimizer step, this needs to be called
# there is also a helper function by the same name that can take in your module and will invoke all of the guided samplers
sampler.split_and_prune_()
Oxford flowers
Install uv, which will probably become the default in the near future
$ pip install uv
Then
$ uv run train_oxford_flowers.py
Citations
@misc{yang2025discretedistributionnetworks,
title = {Discrete Distribution Networks},
author = {Lei Yang},
year = {2025},
eprint = {2401.00036},
archivePrefix = {arXiv},
primaryClass = {cs.CV},
url = {https://arxiv.org/abs/2401.00036},
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file discrete_distribution_network-0.1.9.tar.gz.
File metadata
- Download URL: discrete_distribution_network-0.1.9.tar.gz
- Upload date:
- Size: 676.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd60b095c71f9c321bd06db1ff4ded71ecabbe8dba516b732a5a8fa211dbe813
|
|
| MD5 |
dfcce41ed3028eb866debf70f286f725
|
|
| BLAKE2b-256 |
d0232f056745b7ab6b2c0df138f52f12630caa93670e2237e8cc4f111d76b118
|
File details
Details for the file discrete_distribution_network-0.1.9-py3-none-any.whl.
File metadata
- Download URL: discrete_distribution_network-0.1.9-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.24
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12c0605f480835ac166b3d9d83620b5c35514cfa5f2e02bd22e15795981daa5f
|
|
| MD5 |
c107c825218fabe55995e34def41d99b
|
|
| BLAKE2b-256 |
d16b0f6b2f0b865da850957f33cf229d561880eef15703e40e768f2268dfa164
|