tract_pulse/ops/cnn/
conv.rs

1use crate::internal::*;
2use crate::ops::cnn::pools::pulsify_pooled_input;
3use tract_core::ops::cnn::Conv;
4
5register_all!(Conv: pulsify);
6
7fn pulsify(
8    op: &Conv,
9    source: &TypedModel,
10    node: &TypedNode,
11    target: &mut PulsedModel,
12    mapping: &HashMap<OutletId, OutletId>,
13    _symbol: &Symbol,
14    _pulse: &TDim,
15) -> TractResult<Option<TVec<OutletId>>> {
16    let fact = target.outlet_fact(mapping[&node.inputs[0]])?;
17    let zero = Tensor::zero_scalar_dt(fact.datum_type)?;
18    if let Some((wire, pool_spec)) =
19        pulsify_pooled_input(&op.pool_spec, source, node, target, mapping, Some(zero))?
20    {
21        let mut wires: TVec<_> = node.inputs.iter().map(|i| mapping[i]).collect();
22        wires[0] = wire;
23        Ok(Some(target.wire_node(&node.name, Conv { pool_spec, ..op.clone() }, &wires)?))
24    } else {
25        Ok(None)
26    }
27}
28
29impl PulsedOp for Conv {
30    fn pulsed_output_facts(&self, inputs: &[&PulsedFact]) -> TractResult<TVec<PulsedFact>> {
31        let dt = self.q_params.unwrap_or(inputs[0].datum_type);
32        super::pools::pulsed_output_facts(&self.pool_spec, inputs, dt)
33    }
34
35    as_op!();
36    pulsed_op_to_typed_op!();
37}