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
//! # 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_pytorch` and `cache` features,
//! both default. Fetching a checkpoint needs `fetch`.
//!
//! The geometries are [`RESNET_PREFABS`]: six
//! [`ResNetContractConfig`](super::ResNetContractConfig)s by name,
//! `resnet18` to `resnet152`, each with 1000 classes. The checkpoints are
//! 14 rows in two groups of the [`WELL_KNOWN_TABLE`]: [`TORCHVISION`], the
//! reference `ImageNet` weights, and [`TIMM`], the `ResNet` Strikes Back
//! recipes (`a1`, `a2`, `a3`) and earlier `pytorch-image-models` releases.
//! Each row names the prefab 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 [`ResNetConstruct`] 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
//! [`ResNetConstruct::with_config`]: resolve the name, set the config on
//! the deferred model's hook, then load it. `examples/resnet_tiny` swaps
//! the activation this way before the weights land:
//!
//! ```rust,no_run
//! # #[cfg(all(feature = "store_pytorch", feature = "cache"))] {
//! use std::sync::Arc;
//!
//! use bunsen::{
//! data::pretrained::{
//! PretrainedCache,
//! PretrainedCacheOptions,
//! },
//! kits::images::resnet::{
//! ResNet,
//! pretrained::{
//! RESNET_PREFABS,
//! default_resnet_factory,
//! },
//! },
//! support::testing::cpu_device,
//! };
//! use burn::nn::activation::ActivationConfig;
//!
//! let device = cpu_device();
//! let cache = PretrainedCache::new(PretrainedCacheOptions::default())?;
//!
//! let config = RESNET_PREFABS
//! .expect_lookup_prefab("resnet18")
//! .to_config()
//! .with_activation(ActivationConfig::Gelu);
//!
//! let mut model =
//! default_resnet_factory()?.resolve("timm/resnet18_a1", &cache)?;
//! model.hook = model.hook.with_config(config);
//! let resnet: ResNet =
//! Arc::unwrap_or_clone(model.load(&cache, &device)?.handle);
//! # }
//! # Ok::<(), bunsen::errors::BunsenError>(())
//! ```
pub use *;
pub use *;
pub use *;
pub use *;