Stochastic-depth ResNet training library extracted from a thesis project
Project description
sdhd
sdhd stands for Stochastic Depth for High-Depth residual networks.
It is a reusable Python library extracted from my thesis codebase on stochastic-depth regularization for residual CNNs.
What the library provides
- ResNet models without stochastic depth;
- ResNet models with stochastic depth in two modes:
- per-batch gating,
- per-sample gating;
- CIFAR-style residual networks with 3x3 basic blocks;
- bottleneck residual networks (ResNet-50 / ResNet-101 style);
- folder-based image loading;
- CIFAR-100 loading;
- LMDB-backed datasets for large-scale training;
- a generic PyTorch training loop with checkpoint save/load support;
- a small command-line interface for training experiments.
Installation
Local editable install
pip install -e ./sdhd
With LMDB support
pip install -e './sdhd[lmdb]'
Quick examples
Build a CIFAR-style model
from sdhd import StochasticDepthConfig, CIFARResNetConfig, build_cifar_resnet
sd = StochasticDepthConfig(enabled=True, mode="sample", final_survival_prob=0.5)
config = CIFARResNetConfig(depth=110, num_classes=100, stochastic_depth=sd)
model = build_cifar_resnet(config)
Build a bottleneck ResNet
from sdhd import StochasticDepthConfig, BottleneckResNetConfig, build_bottleneck_resnet
sd = StochasticDepthConfig(enabled=True, mode="batch", final_survival_prob=0.5)
config = BottleneckResNetConfig(depth=50, num_classes=365, stochastic_depth=sd)
model = build_bottleneck_resnet(config)
Create CIFAR-100 dataloaders
from sdhd import create_cifar100_dataloaders
train_loader, test_loader = create_cifar100_dataloaders("/path/to/cifar100", batch_size=256)
Train a built-in ResNet in one function call
from sdhd import TrainerConfig, train_resnet
trainer = TrainerConfig(epochs=5, lr=0.01, output_dir="runs/example", compile_model=False)
result = train_resnet(
architecture="bottleneck",
dataset_type="folder",
data_dir="/path/to/dataset",
depth=50,
batch_size=8,
trainer_config=trainer,
enable_sd=True,
sd_mode="sample",
)
print(result.best_val_accuracy)
Train your own custom PyTorch model
import torch.nn as nn
from sdhd import TrainerConfig, train_custom_model
model = nn.Sequential(
nn.Flatten(),
nn.Linear(3 * 224 * 224, 102),
)
trainer = TrainerConfig(epochs=5, lr=0.01, output_dir="runs/custom", compile_model=False)
result = train_custom_model(
model,
dataset_type="folder",
data_dir="/path/to/dataset",
batch_size=8,
trainer_config=trainer,
)
print(result.best_val_accuracy)
Lower-level training API
from sdhd import TrainerConfig, train_classifier
trainer = TrainerConfig(epochs=100, lr=0.1, output_dir="runs/example")
result = train_classifier(model, train_loader, test_loader, trainer)
print(result.best_val_accuracy)
CLI
After installation, you can run:
sdhd-train --help
Or:
python -m sdhd --help
Thesis background
This package comes from a thesis project on stochastic depth for regularizing residual CNNs. The main thesis-specific contributions preserved in this library are:
- explicit support for per-sample vs per-batch stochastic depth;
- stochastic depth for bottleneck residual blocks;
- support for large-scale LMDB datasets.
Full documentation
The package keeps its public-facing documentation concentrated in this README, in-code docstrings, and the printable LaTeX manual:
docs/tex/sdhd_manual.tex
Additional private/helper Markdown notes for workspace management are intentionally kept outside the standalone sdhd repository.
Release and maintenance
Use GitHub Releases together with Trusted Publishing to publish to PyPI.
Recommendation for the LaTeX manual
Keep the LaTeX source in the repository and optionally publish the compiled PDF through GitHub Releases. PyPI should stay focused on the concise package README.
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 sdhd-0.1.0.tar.gz.
File metadata
- Download URL: sdhd-0.1.0.tar.gz
- Upload date:
- Size: 26.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6613ca1b002d720ffed1500571f705e2313ddc558239c888c1e268812612c5b
|
|
| MD5 |
a1674612bc68e6af212e2f0e62f8d102
|
|
| BLAKE2b-256 |
60d1604ab72f3e089cbbfb3d31264bf54c8f5c6f6ecbd90aa6fbcf0932b37e98
|
Provenance
The following attestation bundles were made for sdhd-0.1.0.tar.gz:
Publisher:
release.yml on gerageragera39/sdhd
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sdhd-0.1.0.tar.gz -
Subject digest:
d6613ca1b002d720ffed1500571f705e2313ddc558239c888c1e268812612c5b - Sigstore transparency entry: 1351567043
- Sigstore integration time:
-
Permalink:
gerageragera39/sdhd@e6137f8f495a28614abec66703bcc994ca80a350 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/gerageragera39
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e6137f8f495a28614abec66703bcc994ca80a350 -
Trigger Event:
release
-
Statement type:
File details
Details for the file sdhd-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sdhd-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
596278e5f7765471fbd0b9fc1eca50dd0aad02729c5f3a91773b742b125aad9d
|
|
| MD5 |
0a3e10b1d83edded230890898a9f6165
|
|
| BLAKE2b-256 |
bd10a292fe5067226716d31af9c00da6a0d1790328653df1ff031f8b862d4aaa
|
Provenance
The following attestation bundles were made for sdhd-0.1.0-py3-none-any.whl:
Publisher:
release.yml on gerageragera39/sdhd
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sdhd-0.1.0-py3-none-any.whl -
Subject digest:
596278e5f7765471fbd0b9fc1eca50dd0aad02729c5f3a91773b742b125aad9d - Sigstore transparency entry: 1351567136
- Sigstore integration time:
-
Permalink:
gerageragera39/sdhd@e6137f8f495a28614abec66703bcc994ca80a350 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/gerageragera39
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e6137f8f495a28614abec66703bcc994ca80a350 -
Trigger Event:
release
-
Statement type: