1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//! # Pretrained `ResNet` models
//!
//! From a model's name to a loaded model, through the data layer's
//! pretrained machinery ([`data::pretrained`](crate::data::pretrained)).
//! The prefab map is always here: a geometry needs no features. The tables,
//! the hook and the factory need the `store` and `cache` features,
//! both default. Fetching a checkpoint needs `fetch`.
//!
//! The geometries are
//! [`ResNetContractConfig`](crate::kits::images::resnet::ResNetContractConfig)'
//! s prefabs: six
//! [`ResNetContractConfig`](super::ResNetContractConfig)s by name,
//! `resnet18` to `resnet152`, each with 1000 classes. The checkpoints are
//! 14 rows, the built-in catalog's builds of [`RESNET_CATALOG_CONTRACT`], in
//! two namespaces: `torchvision`, the
//! reference `ImageNet` weights, and `timm`, the `ResNet` Strikes Back
//! recipes (`a1`, `a2`, `a3`) and earlier `pytorch-image-models` releases.
//! Each row states the prefab's geometry it instantiates, and is one `.pth`
//! file under its group's base URL, pinned to its digest. A spec is
//! `torchvision/resnet50`, `timm/resnet18_a1`, or a bare `resnet50`, which
//! the torchvision group answers first.
//!
//! [`default_resnet_factory`] is the index, and [`ResNetConstructConfig`] its
//! hook: it builds the model from the row's prefab and reads the
//! checkpoint into it with
//! [`ResNet::load_pytorch_weights`](super::ResNet::load_pytorch_weights). A
//! checkpoint does not describe its own geometry, so a model built from
//! any other config, or a checkpoint given as a path, needs
//! [`ResNetConstructConfig::with_config`]: resolve the name, set the config on
//! the deferred model's construct config, then load it. `examples/resnet_tiny`
//! swaps the activation this way before the weights land:
//!
//! ```rust,no_run
//! # #[cfg(feature = "store")] {
//! use std::sync::Arc;
//!
//! use bunsen::{
//! blocks::activation::BunsenActivationConfig,
//! data::{
//! pretrained::Prefabs,
//! resources::{
//! ResourceCache,
//! ResourceCacheOptions,
//! },
//! },
//! kits::images::resnet::{
//! ResNet,
//! ResNetContractConfig,
//! pretrained::default_resnet_factory,
//! },
//! support::testing::cpu_device,
//! };
//!
//! let device = cpu_device();
//! let cache = ResourceCache::new(ResourceCacheOptions::default())?;
//!
//! let config = ResNetContractConfig::expect_prefab("resnet18")
//! .with_activation(BunsenActivationConfig::Gelu);
//!
//! let mut model =
//! default_resnet_factory()?.resolve("timm/resnet18_a1", &cache)?;
//! model.config = model.config.with_config(config);
//! let resnet: ResNet = Arc::unwrap_or_clone(
//! model
//! .load(
//! &cache,
//! &device,
//! bunsen::data::formats::LoadPolicy::performance(),
//! )?
//! .handle,
//! );
//! # }
//! # Ok::<(), bunsen::errors::BunsenError>(())
//! ```
pub use *;
pub use *;
pub use *;