CLIP
Use OpenAI's CLIP model through our Serverless Cloud API
Code sample
2
Run the model
curl --location 'https://serverless.roboflow.com/clip/compare' \
--header 'Content-Type: application/json' \
--data '{
"api_key": "'"$ROBOFLOW_API_KEY"'",
"subject": {"type": "url", "value": "https://media.roboflow.com/notebooks/examples/dog.jpeg"},
"subject_type": "image",
"prompt": ["a photo of a dog", "a photo of a cat", "a photo of a car"],
"prompt_type": "text"
}'3
Run the model
import os
import supervision as sv
from inference_sdk import InferenceHTTPClient
image = sv.load_image_from_url("https://media.roboflow.com/notebooks/examples/dog.jpeg")
client = InferenceHTTPClient(
api_url="https://serverless.roboflow.com",
api_key=os.environ["ROBOFLOW_API_KEY"],
)
result = client.clip_compare(
subject=image,
prompt=[
"a photo of a dog",
"a photo of a cat",
"a photo of a car",
],
subject_type="image",
prompt_type="text",
)
# similarity is a list of cosine similarity scores, one per prompt
print(result["similarity"])[0.2726989686489105, 0.19865083694458008, 0.20997387170791626]Inference speed
Model
Latency (ms)
Use with Inference (self-hosted)
Available checkpoints
Further reading
Last updated
Was this helpful?