Local hyperparameter search and cross-validation for image classifiers using Ray Tune + timm
Project description
cvic
Local, automated hyperparameter search for image classifiers — from dataset to tuned model with one command, distributed across your local GPUs.
cvic uses off-the-shelf models and packages, so you won't get SOTA performance. But it can get surprisingly close, with almost zero effort. Useful as a baseline, or for experimentation with architectures and GPUs.
Built on Ray Tune, Optuna, and timm. Requires Python ≥ 3.12.
It ships two commands:
tunic— hold-out hyperparameter tuning (single train/validation split).cvic— k-fold cross-validation hyperparameter search (for smaller datasets where a single split is noisy).
This is the local subset of krunic. The cloud launcher (SkyPilot/AWS) lives in krunic; cvic runs entirely on your own machine.
Install
pipx install cvic
or with uv:
uv tool install cvic
Quick start
Hold-out tuning:
tunic --data /path/to/dataset --model resnet50 --n_trials 30 --epochs 30 --output results.json
Cross-validation tuning:
cvic --data /path/to/dataset --model resnet50 --n-trials 30 --epochs 30 --folds 5
Train final model from tuning results:
tunic --final results.json --data /path/to/dataset --epochs 50 --amp
Smoke test (synthetic data, no dataset needed):
tunic --smoke-test
cvic --smoke-test
Dataset format
The dataset format is auto-detected:
- ImageFolder — standard
split/class/image.extlayout - WebDataset — sharded TAR files; detected when
wds/dataset_info.jsonexists
tunic — hold-out hyperparameter search
tunic --data PATH --model MODEL [options]
| Flag | Default | Description |
|---|---|---|
--data |
required | Dataset root (ImageFolder or WebDataset) |
--model |
required | Any timm model name |
--n_trials |
80 | Number of Optuna trials |
--epochs |
30 | Training epochs per trial (also used for --final) |
--tune-metric |
val_auroc |
Metric for trial selection and pruning |
--training_fraction |
1.0 | Fraction of training data (val always uses 1.0) |
--batch-size |
32 | Batch size per trial |
--amp |
Enable automatic mixed precision | |
--resume |
Warm-start from a previous experiment directory | |
--final |
Skip tuning; train final model from results JSON | |
--combine |
Train final model on train+val combined | |
--final-model |
tunic_final.pt |
Output path for final model weights |
--device |
auto |
auto, cuda, mps, or cpu |
--smoke-test |
Quick end-to-end test with synthetic data |
cvic — cross-validation hyperparameter search
cvic --data PATH --model MODEL [options]
| Flag | Default | Description |
|---|---|---|
--data |
required | Dataset root (ImageFolder or WebDataset) |
--model |
required | Any timm model name |
--n-trials |
Number of Optuna trials | |
--epochs |
Training epochs per trial | |
--folds |
Number of cross-validation folds | |
--repeats |
Repeated cross-validation runs | |
--stratified |
Use stratified folds | |
--tune-metric |
val_auroc |
Metric for trial selection |
--batch-size |
32 | Batch size per trial |
--test-data |
Held-out test set for final evaluation | |
--amp |
Enable automatic mixed precision | |
--device |
auto |
auto, cuda, mps, or cpu |
--smoke-test |
Quick end-to-end test with synthetic data |
Run cvic --help / tunic --help for the full list of flags.
Search space
| Parameter | Range |
|---|---|
| Optimizer | AdamW, SGD |
| Learning rate | 1e-5 – 1e-1 (log) |
| Weight decay | 1e-6 – 1e-1 (log) |
| Label smoothing | 0 – 0.3 |
| Dropout rate | 0 – 0.5 |
| RandAugment magnitude | 1 – 15 |
| RandAugment num ops | 1 – 4 |
| Mixup alpha | 0 – 0.5 |
| CutMix alpha | 0 – 1.0 |
Override any part with a YAML file via --search-space.
License
MIT
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 cvic-0.1.0.tar.gz.
File metadata
- Download URL: cvic-0.1.0.tar.gz
- Upload date:
- Size: 46.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
167288aa7c54b5a0d8bc0efab373feaf7eb77f7c614d4078711ac196d6a54e1d
|
|
| MD5 |
95f9f21643623fc5e73adcfb173d60de
|
|
| BLAKE2b-256 |
eefc0ebad1f3f5d550b11678b9720dc11722b852684984980ccfca5a46c14273
|
File details
Details for the file cvic-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cvic-0.1.0-py3-none-any.whl
- Upload date:
- Size: 38.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1c73684e5f9e8217ab8e1e72a334cd46c24d00ff41cc35d816df7b7a7728747
|
|
| MD5 |
8953059f1c0b9c5970813da4c393ede9
|
|
| BLAKE2b-256 |
310444183b463b6e296d3ed10d9dd007905938de6a2f1525abfc5729560d1b07
|