Skip to main content

LiT: Zero-Shot Transfer with Locked-image text Tuning

Project description

pytorch-zero-lit

Converted official JAX models for LiT: Zero-Shot Transfer with Locked-image text Tuning to pytorch.

JAX -> Tensorflow -> ONNX -> Pytorch.

  • Image encoder is loaded into pytorch and supports gradients
  • Text encoder is not loaded into pytorch and runs via ONNX on cpu

Install

poetry add pytorch-zero-lit

or

pip install pytorch-zero-lit

Usage

from lit import LiT

model = LiT()

images = TF.to_tensor(
    Image.open("cat.png").convert("RGB").resize((224, 224))
)[None]
texts = [
    "a photo of a cat",
    "a photo of a dog",
    "a photo of a bird",
    "a photo of a fish",
]

image_encodings = model.encode_images(images)
text_encodings = model.encode_texts(texts)

cosine_similarity = model.cosine_similarity(image_encodings, text_encodings)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytorch-zero-lit-0.2.3.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

pytorch_zero_lit-0.2.3-py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page