INNER CODE UNIT · Python

_too_large_message

yurijmikhalevich/rclip · rclip/main.py:42

def _too_large_message(path: str, pixels: int, limit: int) -> str:
  size = f" ({pixels / 1_000_000:.0f} MP)" if pixels else ""
  return (
    f"skipping {path}: it is too large to process{size};"
    f" the limit is {limit / 1_000_000:.0f} MP."
    ' Raise or disable it with "--max-image-megapixels" if you want to index this image'
  )


def _read_and_preprocess(path: str) -> Tuple[str, str, npt.NDArray[np.float32]]:
  """Reads an image, computes its hash, and runs the CLIP preprocessing on it. Runs on the loader
  threads so that the decoding and resizing happen in parallel and only the
  model forward pass is left for the consumer."""
  file_hash = helpers.compute_file_hash(path)
  preprocessed = preprocess(helpers.read_image(path))
  return path, file_hash, preprocessed

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…