vision_rs/models/yolo/yolo26/blocks/
bottleneck.rs1use teeny_core::{dtype::Float, graph::{Op, SymTensor}, name_scope::name_scope};
19
20use super::conv::conv;
21
22pub(super) fn elem_add(a: SymTensor, b: SymTensor) -> SymTensor {
25 let shape = a.shape.clone();
26 let node_id = a.graph.borrow_mut().add_node(
27 Op::Add, vec![a.node_id, b.node_id], a.dtype, shape.clone(),
28 );
29 SymTensor { node_id, graph: a.graph.clone(), dtype: a.dtype, shape }
30}
31
32pub fn bottleneck_std<D: Float + 'static>(c: usize, shortcut: bool) -> impl Fn(SymTensor) -> SymTensor {
38 let c_inner = (c as f32 * 0.5) as usize;
39 let cv1 = conv::<D>(c, c_inner, 3, 1);
40 let cv2 = conv::<D>(c_inner, c, 3, 1);
41 move |x: SymTensor| {
42 let y = {
43 let tmp = { let _g = name_scope("cv1"); cv1(x.clone()) };
44 let _g = name_scope("cv2"); cv2(tmp)
45 };
46 if shortcut { elem_add(x, y) } else { y }
47 }
48}
49
50pub fn bottleneck_3x3<D: Float + 'static>(c: usize, shortcut: bool) -> impl Fn(SymTensor) -> SymTensor {
54 let cv1 = conv::<D>(c, c, 3, 1);
55 let cv2 = conv::<D>(c, c, 3, 1);
56 move |x: SymTensor| {
57 let y = {
58 let tmp = { let _g = name_scope("cv1"); cv1(x.clone()) };
59 let _g = name_scope("cv2"); cv2(tmp)
60 };
61 if shortcut { elem_add(x, y) } else { y }
62 }
63}