MCPcopy Create free account
hub / github.com/allenai/molmo / preprocess

Method preprocess

olmo/data/model_preprocessor.py:596–615  ·  view source on GitHub ↗

Preprocesses a single image Returns: crops: (n_crops, n_patches, patch_dim) individual crops, `n_crops` might change between images but the other dimension are fixed tokens: (n_tokens,) int32 tokens, pad tokens indicate where to insert the

(self, image, is_training: bool, rng=None)

Source from the content-addressed store, hash-verified

594 return image_input_idx
595
596 def preprocess(self, image, is_training: bool, rng=None):
597 """Preprocesses a single image
598
599 Returns:
600 crops: (n_crops, n_patches, patch_dim) individual crops, `n_crops` might
601 change between images but the other dimension are fixed
602 tokens: (n_tokens,) int32 tokens, pad tokens indicate where to insert the
603 patch features, might include other special tokens as well
604 image_idx: (n_crops, n_patches) index in `tokens` to put the patch features from the
605 crops after pooling, negative values indicates patches features to exclude
606 padding_mask: (n_crops, n_patches) what percent of each crop is padding, can be None
607 if the image mask is not being used.
608 """
609 crops, image_tokens, patch_ordering, img_mask = self.image_to_patches_and_tokens(
610 image, is_training, rng)
611 patch_idx = self.build_image_input_idx(
612 image_tokens,
613 patch_ordering,
614 )
615 return crops, image_tokens, patch_idx, img_mask
616
617 def __call__(
618 self,

Callers 1

__call__Method · 0.95

Calls 2

build_image_input_idxMethod · 0.95

Tested by

no test coverage detected