Skip to main content

preprocess

Function preprocess 

Source
pub fn preprocess(img: &Rgb8, cfg: &PreprocessConfig) -> Result<Tensor, String>
Expand description

Full preprocessing: resize, normalize, and patchify into the [n_patches, patch_dim] matrix a patch-embedding matmul consumes.

Rows are patches in row-major grid order (left-to-right, then top-to- bottom), which must match the order of the tower’s position-embedding table; column-major here would pair every patch with the wrong position and degrade silently.

Within a row, values are ordered channel-plane first (all R of the patch, then all G, then all B) — the CHW convention the weights are stored against.