pyhgf.model.conv.im2col_adapter#
- pyhgf.model.conv.im2col_adapter(filter_shape, strides=(1, 1), padding='SAME')[source]#
Build a frozen patch extractor: images in, one row per patch out.
Forward,
xof shape(batch, C, H, W)becomes(batch, n_patches, C*kh*kw)viajax.lax.conv_general_dilated_patches, the same “one row per sample” layoutDeepNetworkAdapterexpects for token positions, so the following per-patch network needs no special-casing. Backward (fold / col2im) is the geometric adjoint: each of thekh*kwkernel taps is a strided slice of the (padded) image, so its gradient is scattered back withjax.numpy.ndarray.at.add()at the same stride, a closed-form sum over overlapping patches unrolled over the statically-sized kernel taps. The adjoint is written out rather than obtained by differentiating the forward at call time; it matchesjax.vjpof this forward (tests/test_conv.py).