https://github.com/bentoml/clip-api-service

CLIP as a service - Embed image and sentences, object recognition, visual reasoning, image classification and reverse image search

https://github.com/bentoml/clip-api-service

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.9%) to scientific vocabulary

Keywords

ai-applications clip cloud-native mlops model-inference model-inference-service model-serving openai-clip

Keywords from Contributors

bentoml fine-tuning llama llama2 llama3-1 llama3-2 llama3-2-vision llm-inference llm-ops llm-serving
Last synced: 5 months ago · JSON representation

Repository

CLIP as a service - Embed image and sentences, object recognition, visual reasoning, image classification and reverse image search

Basic Info
  • Host: GitHub
  • Owner: bentoml
  • License: apache-2.0
  • Language: Jupyter Notebook
  • Default Branch: main
  • Homepage: https://bentoml.com
  • Size: 1.01 MB
Statistics
  • Stars: 64
  • Watchers: 4
  • Forks: 4
  • Open Issues: 1
  • Releases: 3
Topics
ai-applications clip cloud-native mlops model-inference model-inference-service model-serving openai-clip
Created almost 3 years ago · Last pushed 7 months ago
Metadata Files
Readme License

README.md

CLIP API Service


Discover the effortless integration of OpenAI's innovative CLIP model with our streamlined API service.
Powered by BentoML 🍱


[!CAUTION] This repo is deprecated and won't receive updates in the future. Please go to BentoCLIP for the latest usage.

📖 Introduction 📖

CLIP, or Contrastive Language-Image Pretraining, is a cutting-edge AI model that comprehends and connects text and images, revolutionizing how we interpret online data.

This library provides you with an instant, easy-to-use interface for CLIP, allowing you to harness its capabilities without any setup hassles. BentoML takes care of all the complexity of serving the model!

🔧 Installation 🔧

Ensure that you have Python 3.8 or newer and pip installed on your system. We highly recommend using a Virtual Environment to avoid any potential package conflicts.

To install the service, enter the following command: bash pip install clip-api-service

🏃 Quick start 🏃

Once the installation process is complete, you can start the service by running: bash clip-api-service serve --model-name=ViT-B-32:openai Your service is now running! Interact with it via the Swagger UI at localhost:3000 SwaggerUI

Or try this tutorial in Google Colab: CLIP demo.

🎯 Use cases 🎯

Harness the capabilities of the CLIP API service across a range of applications:

Encode

  1. Text and Image Embedding
    • Use encode to transform text or images into meaningful embeddings. This makes it possible to perform tasks such as:
      1. Neural Search: Utilize encoded embeddings to power a search engine capable of understanding and indexing images based on their textual descriptions, and vice versa.
      2. Custom Ranking: Design a ranking system based on embeddings, providing unique ways to sort and categorize data according to your context.

Rank

  1. Zero-Shot Image Classification

    • Use rank to perform image classification without any training. For example:
      1. Given a set of images, classify an image as being "a picture of a dog" or "a picture of a cat".
      2. More complex classifications such as recognizing different breeds of dogs can also be performed, illustrating the versatility of the CLIP API service.
  2. Visual Reasoning

    • The rank function can also be used to provide reasoning about visual scenarios. For instance:

| Visual Scenario | Query Image | Candidates | Output | |-----------------|-------|---------------|--------| | Counting Objects | Three Dog | This is a picture of 1 dog
This is a picture of 2 dogs
This is a picture of 3 dogs | Image matched with "3 dogs" | | Identifying Colors | Blue Car | The car is red
The car is blue
The car is green | Image matched with "blue car" | | Understanding Motion | Parked Car | The car is parked
The car is moving
The car is turning| Image matched with "parked car" | | Recognizing Location | Suburb Car | The car is in the suburb
The car is on the highway
The car is in the street| Image matched with "car in the street" | | Relative Positioning | Big Small car | The big car is on the left, the small car is on the right
The small car is on the left, the big car is on the right| Image matched with the provided description |

🚀 Deploying to Production 🚀

Effortlessly transition your project into a production-ready application using BentoCloud, the production-ready platform for managing and deploying machine learning models.

Start by creating a BentoCloud account. Once you've signed up, log in to your BentoCloud account using the command:

bash bentoml cloud login --api-token <your-api-token> --endpoint <bento-cloud-endpoint>

Note: Replace <your-api-token> and <bento-cloud-endpoint> with your specific API token and the BentoCloud endpoint respectively.

Next, build your BentoML service using the build command:

bash clip-api-service build --model-name=ViT-B-32:openai

Then, push your freshly-built Bento service to BentoCloud using the push command:

bash bentoml push <name:version>

Lastly, deploy this application to BentoCloud with a single bentoml deployment create command following the deployment instructions.

BentoML offers a number of options for deploying and hosting online ML services into production, learn more at Deploying a Bento.

📚 Reference 📚

API reference

/encode

Accepts either: * img_uri : An Image URI, i.e https://hips.hearstapps.com/hmg-prod/images/dog-puppy-on-garden-royalty-free-image-1586966191.jpg * text : A string * img_blob : Base64 encoded string

Returns a vector of embeddings of length 768.

Example: curl -X 'POST' \ 'http://localhost:3000/encode' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '[ { "img_uri": "https://hips.hearstapps.com/hmg-prod/images/dog-puppy-on-garden-royalty-free-image-1586966191.jpg" }, { "text": "picture of a dog" }, { "img_blob": "iVBORw0KGgoAAAANSUhEUgAAABIAAAAPCAYAAADphp8SAAAABHNCSVQICAgIfAhkiAAAABl0RVh0U29mdHdhcmUAZ25vbWUtc2NyZWVuc2hvdO8Dvz4AAAApdEVYdENyZWF0aW9uIFRpbWUARnJpIDI2IE1heSAyMDIzIDA0OjE2OjIxIEFNCXIaIQAAAnhJREFUOI1Fk82OY0UMhT+7qu6dJPfmZ3p6EhYR3QSGnk0P6QV/4rlYsOIBeKrhIQAJtZCgNQsmEWiQSG5V2SwSeixZtiydYx9blpsJPpv2fPP1V3zx5ee8vHnJbDFlNl/Q9GMQBwLUAM7JcXADN9wN3Im1wOaja7afbfnk4xcsVytS25DaFsyptSDiaIyAnMn8kVTOMc6mI+62d2w2G5bLFZOuBxUkJsyNYoIGRVXfTyMCLmByIseJm+trbl58ynL5nK7v0dTgOGgENyQqsWlxdxxH4FEW7og7mBHvtq+4vHxG381IqQF3qjvBnOrgKBIiOR/fA89gMUPdoRpxe/uKbjym6zton4AZ6oZoRNxQUQiJOhzO3R1xeyTiXItXV1csLi4gRjADOIHdEEBEoGSCCOaOmUGtKI4CQQMIxL7vmIwmcBygAdoWAKuV6o5GwUwQB/HzjkTOufC/xZRaSi6IOjHFU1UVrRkrmTwcERViiohDQFANiAmYYbUgBnE8miAiDDlT/j0gQ0aj4qoklZMkHBsKIShBFJXTJLVWai64GbGUQnrSEori7ljO5Gy4gMZIahMpRA7DABZAwXGsVnIulOGIuxFfv/6RUdtwcfmM2XTKfDEnNYlcCjkP1BJIqYUChuNU3J1aM+Us382Jv97f8/d+x3w+YzbtWa5WLD94ztOnCyZdR0QRM8TkdACr1FqoJeNuuFUAwg/fffu9m7Hf73j4/Q9+/uUn3jw8YG6MRyNijFgtJG0wM8owMBwPlJKppZ6+RiA2TWK9XvPhes27f96x3+04Hg/s/vyLe/2N29ueyWxCzQe8Gvu3b0GUXCu7/Y5ijgblP3zyX4rqQyp1AAAAAElFTkSuQmCC" } ]'

/rank

Accepts a list of queries and a list of candidates. Similar to above, queries and candidates are either: * img_uri : An Image URI, i.e https://hips.hearstapps.com/hmg-prod/images/dog-puppy-on-garden-royalty-free-image-1586966191.jpg * text : A string * img_blob : Base64 encoded string

Returns a list of probabilies and cosine similarities of each candidate with respect to the query.

Example: curl -X 'POST' \ 'http://localhost:3000/rank' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "queries": [ { "img_uri": "https://hips.hearstapps.com/hmg-prod/images/dog-puppy-on-garden-royalty-free-image-1586966191.jpg" } ], "candidates": [ { "text": "picture of a dog" }, { "text": "picture of a cat" }, { "text": "picture of a bird" }, { "text": "picture of a car" }, { "text": "picture of a plane" }, { "text": "picture of a boat" } ] }' And the response looks like: { "probabilities": [ [ 0.9958375692367554, 0.0022114247549325228, 0.001514736912213266, 0.00011969256593147293, 0.00019143625104334205, 0.0001251235808013007 ] ], "cosine_similarities": [ [ 0.2297772467136383, 0.16867777705192566, 0.16489382088184357, 0.13951312005519867, 0.14420939981937408, 0.13995687663555145 ] ] }

CLI reference

serve

Spins up a HTTP Server with the model of your choice.

Arguments: * --model-name : Name of the CLIP model. Use list_models to see the list of available model. Default: openai/clip-vit-large-patch14

build

Builds a Bento with the model of your choice

Arguments: * --model-name : Name of the CLIP model. Use list_models to see the list of available model. Default: openai/clip-vit-large-patch14

list_models

List all available CLIP models.

Owner

  • Name: BentoML
  • Login: bentoml
  • Kind: organization
  • Location: San Francisco

The most flexible way to serve AI models in production

GitHub Events

Total
  • Watch event: 15
  • Push event: 1
  • Fork event: 2
Last Year
  • Watch event: 15
  • Push event: 1
  • Fork event: 2

Committers

Last synced: about 2 years ago

All Time
  • Total Commits: 26
  • Total Committers: 4
  • Avg Commits per committer: 6.5
  • Development Distribution Score (DDS): 0.423
Past Year
  • Commits: 26
  • Committers: 4
  • Avg Commits per committer: 6.5
  • Development Distribution Score (DDS): 0.423
Top Committers
Name Email Commits
Jian Shen j****2@g****m 15
Chaoyu p****g@g****m 9
xianxian.zhang 1****l 1
Steve Guo 4****o 1

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 0
  • Total pull requests: 2
  • Average time to close issues: N/A
  • Average time to close pull requests: 5 days
  • Total issue authors: 0
  • Total pull request authors: 2
  • Average comments per issue: 0
  • Average comments per pull request: 1.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • barabum0 (2)
  • xianml (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 36 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 3
  • Total maintainers: 2
pypi.org: clip-api-service

Build AI applications with any CLIP models - embed image and sentences, object recognition, visual reasoning, image classification and reverse image search

  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 36 Last month
Rankings
Dependent packages count: 7.3%
Average: 24.3%
Dependent repos count: 41.3%
Maintainers (2)
Last synced: 6 months ago

Dependencies

pyproject.toml pypi
  • Pillow *
  • accelerate *
  • bentoml *
  • bentoml >=1.0.20
  • open-clip-torch *
  • optimum *
  • pydantic *
  • torch *
  • transformers *
  • typer *
requirements-dev.txt pypi
  • Pillow * development
  • accelerate * development
  • bentoml * development
  • open_clip_torch * development
  • optimum * development
  • pydantic * development
  • torch * development
  • transformers * development
  • typer * development
requirements-tests.txt pypi