use alloc::{
vec,
vec::Vec,
};
use burn::{
module::Module,
nn::{
BatchNormConfig,
Linear,
LinearConfig,
PaddingConfig2d,
activation::ActivationConfig,
conv::Conv2dConfig,
norm::NormalizationConfig,
pool::{
AdaptiveAvgPool2d,
AdaptiveAvgPool2dConfig,
MaxPool2d,
MaxPool2dConfig,
},
},
prelude::{
Config,
Tensor,
},
tensor::Device,
};
use crate::{
blocks::conv::{
ConvBlock2d,
ConvBlock2dConfig,
},
burner::module::{
Indices,
ModuleInit,
Rekey,
ToStructureConfig,
},
errors::{
BunsenError,
BunsenResult,
ConstraintError,
ResultContext,
WithOkOrPanic,
},
kits::images::resnet::{
RESNET18_BLOCKS,
blocks::{
BottleneckPolicyConfig,
LayerBlock,
LayerBlockContractConfig,
LayerBlockMeta,
LayerBlockStructureConfig,
ResidualBlock,
ResidualBlockStructureConfig,
},
},
ops::{
conv::CONV_INTO_RELU_INITIALIZER,
drop::DropBlockOptions,
},
support::validators::{
expect_probability,
try_probability,
},
};
#[derive(Config, Debug)]
pub struct ResNetContractConfig {
pub layers: Vec<usize>,
pub num_classes: usize,
#[config(default = "64")]
pub stem_width: usize,
#[config(default = "32")]
pub output_stride: usize,
#[config(default = "None")]
pub bottleneck_policy: Option<BottleneckPolicyConfig>,
#[config(default = "NormalizationConfig::Batch(BatchNormConfig::new(0))")]
pub normalization: NormalizationConfig,
#[config(default = "ActivationConfig::Relu")]
pub activation: ActivationConfig,
}
impl ResNetContractConfig {
pub fn with_bottleneck(
self,
enable: bool,
) -> Self {
let policy = if enable {
Some(Default::default())
} else {
None
};
self.with_bottleneck_policy(policy)
}
#[allow(unused)]
pub fn to_layer_contracts(&self) -> Vec<LayerBlockContractConfig> {
let mut net_stride = 4;
let mut dilation = 1;
let mut prev_dilation = 1;
let mut layers: Vec<LayerBlockContractConfig> = Default::default();
let mut in_planes = self.stem_width;
for (stage_idx, &num_blocks) in self.layers.iter().enumerate() {
let downsample_input = {
let mut stride = if stage_idx == 0 { 1 } else { 2 };
if net_stride >= self.output_stride {
dilation *= stride;
stride = 1;
} else {
net_stride *= stride;
}
stride != 1
};
let first_dilation = prev_dilation;
let out_planes = if stage_idx == 0 {
match &self.bottleneck_policy {
Some(policy) => in_planes * policy.pinch_factor,
None => in_planes,
}
} else {
2 * in_planes
};
layers.push(
LayerBlockContractConfig::new(num_blocks, in_planes, out_planes)
.with_downsample_input(downsample_input)
.with_first_dilation(Some(first_dilation))
.with_dilation(dilation)
.with_bottleneck_policy(self.bottleneck_policy.clone())
.with_normalization(self.normalization.clone())
.with_activation(self.activation.clone()),
);
in_planes = out_planes;
prev_dilation = dilation;
}
layers
}
pub fn resnet18(num_classes: usize) -> Self {
Self::new(RESNET18_BLOCKS.to_vec(), num_classes) }
}
impl ToStructureConfig for ResNetContractConfig {
type Structure = ResNetStructureConfig;
fn try_to_structure(&self) -> BunsenResult<ResNetStructureConfig> {
Ok(ResNetStructureConfig::new(
ConvBlock2dConfig::new(
Conv2dConfig::new([3, self.stem_width], [7, 7])
.with_stride([2, 2])
.with_padding({
let d = 3;
PaddingConfig2d::Explicit(d, d, d, d)
})
.with_bias(false)
.with_initializer(CONV_INTO_RELU_INITIALIZER.clone()),
)
.with_norm(Some(BatchNormConfig::new(self.stem_width).into()))
.with_act(Some(self.activation.clone())),
self.to_layer_contracts()
.iter()
.map(|c| c.try_to_structure())
.collect::<BunsenResult<Vec<_>>>()?,
self.num_classes,
))
}
}
pub trait ResNetMeta {
fn num_stages(&self) -> usize;
fn head_planes(&self) -> usize;
fn num_classes(&self) -> usize;
}
#[derive(Config, Debug)]
pub struct ResNetStructureConfig {
pub input_cb: ConvBlock2dConfig,
pub layers: Vec<LayerBlockStructureConfig>,
pub num_classes: usize,
}
impl ResNetMeta for ResNetStructureConfig {
fn num_stages(&self) -> usize {
self.layers.len()
}
fn head_planes(&self) -> usize {
self.layers.last().unwrap().out_planes()
}
fn num_classes(&self) -> usize {
self.num_classes
}
}
impl ResNetStructureConfig {
pub fn try_with_standard_drop_block_prob(
self,
drop_prob: f64,
) -> BunsenResult<Self> {
let options = standard_drop_block_options(drop_prob, self.layers.len())?;
Ok(self.with_drop_block_options(options))
}
pub fn with_standard_drop_block_prob(
self,
drop_prob: f64,
) -> Self {
self.try_with_standard_drop_block_prob(drop_prob)
.ok_or_panic()
}
pub fn with_stochastic_depth_drop_path_rate(
self,
drop_path_rate: f64,
) -> Self {
let drop_path_rate = expect_probability(drop_path_rate);
let net_num_blocks = self.layers.iter().map(|b| b.len()).sum::<usize>();
let mut net_block_idx = 0;
let mut update_drop_path = |_idx: usize, block: ResidualBlockStructureConfig| {
let block_dpr = stochastic_depth_rate(drop_path_rate, net_block_idx, net_num_blocks);
net_block_idx += 1;
if block_dpr > 0.0 {
block.with_drop_path_prob(block_dpr)
} else {
block
}
};
Self {
layers: self
.layers
.into_iter()
.map(|b| b.map_blocks(&mut update_drop_path))
.collect(),
..self
}
}
pub fn with_drop_block_options(
self,
options: Vec<Option<DropBlockOptions>>,
) -> Self {
assert_eq!(options.len(), self.layers.len());
Self {
layers: self
.layers
.into_iter()
.zip(options)
.map(|(b, o)| b.with_drop_block(o))
.collect(),
..self
}
}
}
fn stochastic_depth_rate(
drop_path_rate: f64,
net_block_idx: usize,
net_num_blocks: usize,
) -> f64 {
if net_num_blocks < 2 {
return 0.0;
}
drop_path_rate * (net_block_idx as f64) / ((net_num_blocks - 1) as f64)
}
fn standard_drop_block_options(
drop_prob: f64,
num_stages: usize,
) -> BunsenResult<Vec<Option<DropBlockOptions>>> {
let drop_prob = try_probability(drop_prob).context("drop_prob")?;
let mut options = vec![None; num_stages];
if drop_prob > 0.0 {
if num_stages < 2 {
return Err(BunsenError::illegal(format!(
"the standard DropBlock schedule needs at least 2 stages, for its last two; got {num_stages}"
)));
}
options[num_stages - 2] = DropBlockOptions::default()
.with_drop_prob(drop_prob)
.with_block_size(5)
.with_gamma_scale(0.25)
.into();
options[num_stages - 1] = DropBlockOptions::default()
.with_drop_prob(drop_prob)
.with_block_size(3)
.with_gamma_scale(1.0)
.into();
}
Ok(options)
}
impl ModuleInit<ResNet> for ResNetStructureConfig {
fn try_init(
&self,
device: &Device,
) -> BunsenResult<ResNet> {
if self.layers.is_empty() {
return Err(ConstraintError::zero_or_empty("ResNetStructureConfig", "layers").into());
}
for (idx, layer) in self.layers.iter().enumerate() {
layer
.try_validate()
.with_context(|| format!("ResNet stage {idx} (layers[{idx}])"))?;
}
let head_planes = self.head_planes();
let module = ResNet {
input_cb: self.input_cb.init(device),
input_pool: MaxPool2dConfig::new([3, 3])
.with_strides([2, 2])
.with_padding({
let d = 1;
PaddingConfig2d::Explicit(d, d, d, d)
})
.init(),
layers: self
.layers
.iter()
.map(|c| c.try_init(device))
.collect::<BunsenResult<Vec<_>>>()?,
output_pool: AdaptiveAvgPool2dConfig::new([1, 1]).init(),
output_fc: LinearConfig::new(head_planes, self.num_classes).init(device),
};
Ok(module)
}
}
#[derive(Module, Debug)]
pub struct ResNet {
pub input_cb: ConvBlock2d,
pub input_pool: MaxPool2d,
pub layers: Vec<LayerBlock>,
pub output_pool: AdaptiveAvgPool2d,
pub output_fc: Linear,
}
impl ResNetMeta for ResNet {
fn num_stages(&self) -> usize {
self.layers.len()
}
fn head_planes(&self) -> usize {
self.output_fc.weight.dims()[0]
}
fn num_classes(&self) -> usize {
self.output_fc.weight.dims()[1]
}
}
impl ResNet {
pub fn debug_print(&self) {
for (idx, layer) in self.layers.iter().enumerate() {
println!(
"# Stage[{idx:?}]/{}:: {} :> {}",
layer.len(),
layer.in_planes(),
layer.out_planes()
);
layer.debug_print();
println!();
}
}
pub fn forward(
&self,
input: Tensor<4>,
) -> Tensor<2> {
let x = self.input_cb.forward(input);
let x = self.input_pool.forward(x);
let mut x = x;
for layer in self.layers.iter() {
x = layer.forward(x);
}
let x = self.output_pool.forward(x);
let x = x.flatten(1, 3);
self.output_fc.forward(x)
}
pub fn torchvision_rekey() -> Rekey {
let conv_block = |part: &'static str| Rekey::keep_rest().rename("", part);
let block = Rekey::keep_rest()
.mount_indexed("conv", "cb", conv_block("conv."))
.mount_indexed("bn", "cb", conv_block("norm."))
.rename("downsample.0.", "downsample.conv.")
.rename("downsample.1.", "downsample.norm.");
Rekey::keep_rest()
.drop_suffix(".num_batches_tracked")
.rename("conv1.", "input_cb.conv.")
.rename("bn1.", "input_cb.norm.")
.rename("fc.", "output_fc.")
.mount_indexed_with(
"layer",
"layers.",
Indices::From(1),
Rekey::keep_rest().mount_indexed("", "blocks.", block),
)
}
#[cfg(feature = "store_pytorch")]
pub fn load_pytorch_weights(
mut self,
path: impl Into<std::path::PathBuf>,
) -> BunsenResult<Self> {
use burn::store::{
ModuleStore,
PytorchStore,
PytorchStoreError,
pytorch::PytorchError,
};
use crate::errors::sys_at;
let path = path.into();
let tensors: Vec<_> = PytorchStore::from_file(path.clone())
.map_indices_contiguous(false)
.get_all_tensors()
.map_err(|e| match e {
PytorchStoreError::Io(io) | PytorchStoreError::Reader(PytorchError::Io(io)) => {
sys_at("read", &path)(io)
}
e => BunsenError::invalid_resource(format!(
"cannot read PyTorch weights from {}",
path.display()
))
.with_cause(e),
})?
.values()
.cloned()
.collect();
crate::data::pretrained::apply_rekeyed_tensors(
&mut self,
tensors,
&Self::torchvision_rekey(),
)
.with_context(|| format!("loading {}", path.display()))?;
Ok(self)
}
pub fn with_classes(
mut self,
num_classes: usize,
) -> Self {
let [d_input, _d_output] = self.output_fc.weight.dims();
self.output_fc =
LinearConfig::new(d_input, num_classes).init(&self.output_fc.weight.device());
self
}
pub fn with_stochastic_path_depth(
self,
drop_path_rate: f64,
) -> Self {
let drop_path_rate = expect_probability(drop_path_rate);
let net_num_blocks = self.layers.iter().map(|b| b.len()).sum::<usize>();
let mut net_block_idx = 0;
let mut update_drop_path = |_idx: usize, block: ResidualBlock| {
let block_dpr = stochastic_depth_rate(drop_path_rate, net_block_idx, net_num_blocks);
net_block_idx += 1;
if block_dpr > 0.0 {
block.with_drop_path_prob(block_dpr)
} else {
block
}
};
Self {
layers: self
.layers
.into_iter()
.map(|b| b.map_blocks(&mut update_drop_path))
.collect(),
..self
}
}
pub fn with_drop_block_options(
self,
options: Vec<Option<DropBlockOptions>>,
) -> Self {
assert_eq!(options.len(), self.layers.len());
Self {
layers: self
.layers
.into_iter()
.zip(options)
.map(|(b, o)| b.with_drop_block(o))
.collect(),
..self
}
}
pub fn try_with_stochastic_drop_block(
self,
drop_prob: f64,
) -> BunsenResult<Self> {
let options = standard_drop_block_options(drop_prob, self.layers.len())?;
Ok(self.with_drop_block_options(options))
}
pub fn with_stochastic_drop_block(
self,
drop_prob: f64,
) -> Self {
self.try_with_stochastic_drop_block(drop_prob).ok_or_panic()
}
pub fn map_layers<F>(
self,
f: F,
) -> Self
where
F: Fn(Vec<LayerBlock>) -> Vec<LayerBlock>,
{
Self {
layers: f(self.layers),
..self
}
}
pub fn freeze_layers(self) -> Self {
self.map_layers(|layers| layers.into_iter().map(|layer| layer.no_grad()).collect())
}
}
#[cfg(test)]
mod tests {
use serial_test::serial;
use super::*;
use crate::{
errors::{
BunsenErrorKind,
testing::ErrorMatcher,
},
kits::images::resnet::{
RESNET34_BLOCKS,
RESNET50_BLOCKS,
},
support::testing::{
DeviceMemoryGuard,
cpu_device,
performance_device,
},
};
#[cfg(all(feature = "store_pytorch", feature = "cache", feature = "fetch"))]
fn test_load_pytorch(spec: &str) -> BunsenResult<()> {
use crate::{
data::pretrained::{
PretrainedCache,
PretrainedCacheOptions,
},
kits::images::resnet::pretrained::default_resnet_factory,
};
let device = performance_device();
let cache = PretrainedCache::new(PretrainedCacheOptions::default())?;
let loaded = default_resnet_factory()?.load(spec, &cache, &device)?;
let _model: &ResNet = &loaded.handle;
Ok(())
}
#[test]
#[serial]
#[cfg(all(feature = "store_pytorch", feature = "cache", feature = "fetch"))]
fn test_load_pytorch_prefab() -> BunsenResult<()> {
test_load_pytorch("torchvision/resnet18")
}
#[test]
#[serial]
#[cfg(all(feature = "store_pytorch", feature = "cache", feature = "fetch"))]
fn test_load_pytorch_prefab_cuda() -> BunsenResult<()> {
test_load_pytorch("torchvision/resnet34")
}
#[test]
fn test_to_layers_34_basic() {
let cfg = ResNetContractConfig::new(RESNET34_BLOCKS.to_vec(), 1000);
let layers = cfg.to_layer_contracts();
println!("{:#?}", layers);
}
#[test]
#[serial]
fn test_to_layers_50_bottleneck() {
let device = performance_device();
let _memory = DeviceMemoryGuard::new(&device);
let cfg = ResNetContractConfig::new(RESNET50_BLOCKS.to_vec(), 1000).with_bottleneck(true);
let layers = cfg.to_layer_contracts();
let first_stage = layers[0].clone();
println!("block[0] cfg:\n{:#?}", first_stage);
println!();
let blocks = first_stage
.to_block_contracts()
.into_iter()
.map(|b| b.to_structure())
.collect::<Vec<_>>();
println!("blocks ...");
println!("{:#?}", blocks);
println!();
let model: ResNet = cfg.to_structure().init(&device);
model.debug_print();
}
fn assert_meta_agrees(
a: &impl ResNetMeta,
b: &impl ResNetMeta,
) {
assert_eq!(a.num_stages(), b.num_stages());
assert_eq!(a.head_planes(), b.head_planes());
assert_eq!(a.num_classes(), b.num_classes());
}
#[test]
#[serial]
fn test_policy_pathways_agree() {
let device = performance_device();
let _memory = DeviceMemoryGuard::new(&device);
let policy = ResNetContractConfig::new(vec![1, 1], 7)
.with_stem_width(8)
.with_bottleneck(true);
let structure = policy.to_structure();
assert_eq!(structure.num_stages(), 2);
assert_eq!(structure.head_planes(), 64);
assert_eq!(structure.num_classes(), 7);
let lowered: ResNet = structure.init(&device);
let direct: ResNet = policy.init(&device);
assert_meta_agrees(&direct, &lowered);
assert_meta_agrees(&direct, &structure);
}
#[test]
fn test_try_init_rejects_no_stages() {
let device = cpu_device();
let structure = ResNetStructureConfig {
layers: vec![],
..ResNetContractConfig::new(vec![1], 7)
.with_stem_width(8)
.to_structure()
};
let no_stages = ErrorMatcher::kind(BunsenErrorKind::Illegal)
.has_cause::<ConstraintError>()
.message_contains("ResNetStructureConfig.layers");
let bad: BunsenResult<ResNet> = structure.try_init(&device);
no_stages.assert_err(&bad);
let bad: BunsenResult<ResNet> = ResNetContractConfig::new(vec![], 7)
.with_stem_width(8)
.try_init(&device);
no_stages.assert_err(&bad);
}
#[test]
fn test_try_init_rejects_an_empty_stage() {
let device = cpu_device();
let bad: BunsenResult<ResNet> = ResNetContractConfig::new(vec![1, 0], 7)
.with_stem_width(8)
.try_init(&device);
ErrorMatcher::kind(BunsenErrorKind::Illegal)
.has_cause::<ConstraintError>()
.frame_contains("ResNet stage 1")
.assert_err(&bad);
}
const TIMM_DROP_PATH_2222_AT_0_1: [f64; 8] = [
0.0,
0.014285714285714287,
0.028571428571428574,
0.042857142857142864,
0.05714285714285715,
0.07142857142857142,
0.08571428571428573,
0.1,
];
fn structure_drop_path_probs(structure: &ResNetStructureConfig) -> Vec<f64> {
structure
.layers
.iter()
.flat_map(|layer| layer.blocks.iter())
.map(|block| match block {
ResidualBlockStructureConfig::Basic(config) => config.drop_path_prob,
ResidualBlockStructureConfig::Bottleneck(config) => config.drop_path_prob,
})
.collect()
}
fn module_drop_path_probs(model: &ResNet) -> Vec<f64> {
model
.layers
.iter()
.flat_map(|layer| layer.blocks.iter())
.map(|block| {
let drop_path = match block {
ResidualBlock::Basic(block) => &block.drop_path,
ResidualBlock::Bottleneck(block) => &block.drop_path,
};
drop_path.as_ref().map_or(0.0, |d| d.drop_prob)
})
.collect()
}
fn assert_rates_eq(
actual: &[f64],
expected: &[f64],
) {
assert_eq!(actual.len(), expected.len(), "{actual:?} != {expected:?}");
for (a, e) in actual.iter().zip(expected) {
assert!((a - e).abs() < 1e-12, "{actual:?} != {expected:?}");
}
}
#[test]
fn test_structure_drop_path_schedule_matches_timm() {
let structure = ResNetContractConfig::new(vec![2, 2, 2, 2], 10)
.with_stem_width(8)
.to_structure()
.with_stochastic_depth_drop_path_rate(0.1);
assert_rates_eq(
&structure_drop_path_probs(&structure),
&TIMM_DROP_PATH_2222_AT_0_1,
);
}
#[test]
fn test_module_drop_path_schedule_matches_timm() {
let device = cpu_device();
let model: ResNet = ResNetContractConfig::new(vec![2, 2, 2, 2], 10)
.with_stem_width(8)
.init(&device);
let model = model.with_stochastic_path_depth(0.1);
assert_rates_eq(&module_drop_path_probs(&model), &TIMM_DROP_PATH_2222_AT_0_1);
}
#[test]
fn test_drop_path_schedules_agree_with_one_block_per_stage() {
let structure = ResNetContractConfig::new(vec![1, 1], 10)
.with_stem_width(8)
.to_structure();
let device = cpu_device();
let model: ResNet = structure.init(&device);
let model = model.with_stochastic_path_depth(0.1);
assert_rates_eq(&module_drop_path_probs(&model), &[0.0, 0.1]);
let structure = structure.with_stochastic_depth_drop_path_rate(0.1);
assert_rates_eq(&structure_drop_path_probs(&structure), &[0.0, 0.1]);
}
fn timm_drop_blocks_2222_at_0_1() -> Vec<Option<DropBlockOptions>> {
let stage3 = DropBlockOptions::default()
.with_drop_prob(0.1)
.with_block_size(5)
.with_gamma_scale(0.25);
let stage4 = DropBlockOptions::default()
.with_drop_prob(0.1)
.with_block_size(3)
.with_gamma_scale(1.0);
vec![
None,
None,
None,
None,
Some(stage3.clone()),
Some(stage3),
Some(stage4.clone()),
Some(stage4),
]
}
fn structure_drop_blocks(structure: &ResNetStructureConfig) -> Vec<Option<DropBlockOptions>> {
structure
.layers
.iter()
.flat_map(|layer| layer.blocks.iter())
.map(|block| match block {
ResidualBlockStructureConfig::Basic(config) => config.drop_block.clone(),
ResidualBlockStructureConfig::Bottleneck(config) => config.drop_block.clone(),
})
.collect()
}
fn module_drop_blocks(model: &ResNet) -> Vec<Option<DropBlockOptions>> {
model
.layers
.iter()
.flat_map(|layer| layer.blocks.iter())
.map(|block| {
let drop_block = match block {
ResidualBlock::Basic(block) => &block.drop_block,
ResidualBlock::Bottleneck(block) => &block.drop_block,
};
drop_block.as_ref().map(|d| d.options.clone())
})
.collect()
}
#[test]
fn test_structure_drop_block_schedule_matches_timm() {
let structure = ResNetContractConfig::new(vec![2, 2, 2, 2], 10)
.with_stem_width(8)
.to_structure()
.with_standard_drop_block_prob(0.1);
assert_eq!(
structure_drop_blocks(&structure),
timm_drop_blocks_2222_at_0_1()
);
let device = cpu_device();
let model: ResNet = structure.init(&device);
assert_eq!(module_drop_blocks(&model), timm_drop_blocks_2222_at_0_1());
}
#[test]
fn test_module_drop_block_schedule_matches_timm() {
let device = cpu_device();
let model: ResNet = ResNetContractConfig::new(vec![2, 2, 2, 2], 10)
.with_stem_width(8)
.init(&device);
let model = model.with_stochastic_drop_block(0.1);
assert_eq!(module_drop_blocks(&model), timm_drop_blocks_2222_at_0_1());
}
#[test]
fn test_try_drop_block_schedules_reject_one_stage() {
let structure = ResNetContractConfig::new(vec![2], 10)
.with_stem_width(8)
.to_structure();
let device = cpu_device();
let model: ResNet = structure.init(&device);
let one_stage =
ErrorMatcher::kind(BunsenErrorKind::Illegal).message_contains("at least 2 stages");
one_stage.assert_err(&structure.clone().try_with_standard_drop_block_prob(0.1));
one_stage.assert_err(&model.clone().try_with_stochastic_drop_block(0.1));
ErrorMatcher::kind(BunsenErrorKind::Illegal)
.frame_contains("drop_prob")
.assert_err(&structure.clone().try_with_standard_drop_block_prob(1.5));
let structure = structure.try_with_standard_drop_block_prob(0.0).unwrap();
assert_eq!(structure_drop_blocks(&structure), vec![None, None]);
let model = model.try_with_stochastic_drop_block(0.0).unwrap();
assert_eq!(module_drop_blocks(&model), vec![None, None]);
}
#[test]
#[should_panic(expected = "at least 2 stages")]
fn test_drop_block_schedule_panics_on_one_stage() {
let _ = ResNetContractConfig::new(vec![2], 10)
.with_stem_width(8)
.to_structure()
.with_standard_drop_block_prob(0.1);
}
#[test]
fn test_torchvision_rekey() {
let rekey = ResNet::torchvision_rekey();
for (torchvision, bunsen) in [
("conv1.weight", Some("input_cb.conv.weight")),
("bn1.running_mean", Some("input_cb.norm.running_mean")),
("bn1.num_batches_tracked", None),
(
"layer1.0.conv1.weight",
Some("layers.0.blocks.0.cb1.conv.weight"),
),
("layer1.1.bn2.bias", Some("layers.0.blocks.1.cb2.norm.bias")),
(
"layer4.2.conv3.weight",
Some("layers.3.blocks.2.cb3.conv.weight"),
),
(
"layer2.0.downsample.0.weight",
Some("layers.1.blocks.0.downsample.conv.weight"),
),
(
"layer2.0.downsample.1.running_var",
Some("layers.1.blocks.0.downsample.norm.running_var"),
),
("layer3.5.bn3.num_batches_tracked", None),
("fc.weight", Some("output_fc.weight")),
] {
assert_eq!(rekey.apply(torchvision).as_deref(), bunsen, "{torchvision}");
}
}
}