Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

[CLIP]: Zeroshot Pipeline#1098

Merged
bfineran merged 34 commits into
mainfrom
clip_zshot
Aug 2, 2023
Merged

[CLIP]: Zeroshot Pipeline#1098
bfineran merged 34 commits into
mainfrom
clip_zshot

Conversation

@dsikka

@dsikka dsikka commented Jun 27, 2023

Copy link
Copy Markdown
Contributor

Summary

NOTE: Pipeline has been tested with MLR's Zershot models. However, these are not yet available on sparsezoo.

Screenshot 2023-07-30 at 9 35 00 PM
  • This PR is based on the Pipeline refactor and uses the new BasePipeline class
  • This PR introduces 3 new pipelines: CLIPVisualPipeline, CLIPTextPipeline and CLIPZeroShotPipeline to run zero-shot classification.
  • The text pipeline uses a tokenizer provided by OpenCLIP

Testing

  • Mock engine tests were written to test all 3 pipelines and can be found in test_clip.py

Tested with MLR's models (on the following images):

basilica.jpg
basilica
buddy.jpeg
buddy


import numpy as np

from deepsparse import BasePipeline
from deepsparse.clip import CLIPTextInput, CLIPVisualInput, CLIPZeroShotInput

possible_classes = ["ice cream", "an elephant", "a dog", "a building", "a church"]
images = ["buddy.jpeg", “basilica.jpg”]

model_path_text = "zeroshot_research/text/model.onnx"
model_path_visual = "zeroshot_research/visual/model.onnx"

kwargs = {
    "visual_model_path": model_path_visual,
    "text_model_path": model_path_text,
}
pipeline = BasePipeline.create(task="clip_zeroshot", **kwargs)

pipeline_input = CLIPZeroShotInput(
    image=CLIPVisualInput(images=images),
    text=CLIPTextInput(text=possible_classes),
)

output = pipeline(pipeline_input).text_scores
for i in range(len(output)):
    prediction = possible_classes[np.argmax(output[i])]
    print(f"Image {images[i]} is a picture of {prediction}")


Produces the output:

DeepSparse, Copyright 2021-present / Neuralmagic, Inc. version: 1.6.0.20230727 COMMUNITY | (3cb4a3e5) (optimized) (system=avx2, binary=avx2)

Image basilica.jpg is a picture of a church
Image buddy.jpeg is a picture of a dog

@dsikka dsikka marked this pull request as ready for review June 30, 2023 15:49

@bfineran bfineran left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great pending comments and getting a test model / files up

Comment thread src/deepsparse/clip/pipelines.py Outdated
Comment thread src/deepsparse/clip/pipelines.py Outdated
@dsikka dsikka force-pushed the pipeline_refactor branch from 02a1f2c to e34249e Compare July 13, 2023 15:39
@dsikka dsikka force-pushed the clip_zshot branch 5 times, most recently from 981bd2e to a06dd80 Compare July 13, 2023 17:42
Base automatically changed from pipeline_refactor to main July 18, 2023 11:16
@dsikka dsikka force-pushed the clip_zshot branch 2 times, most recently from a1c5c4a to 651595c Compare July 18, 2023 14:25
@dsikka

dsikka commented Jul 21, 2023

Copy link
Copy Markdown
Contributor Author

@bfineran Rebased and updated as per PR comments.

@dsikka dsikka requested review from Satrat and bfineran and removed request for KSGulin July 21, 2023 19:00
@dsikka

dsikka commented Jul 28, 2023

Copy link
Copy Markdown
Contributor Author

FYI This has been tested/verified with models by MLR

@dsikka

dsikka commented Jul 30, 2023

Copy link
Copy Markdown
Contributor Author

Updated with a README.md showing examples

dbogunowicz
dbogunowicz previously approved these changes Jul 31, 2023
Comment thread src/deepsparse/clip/zeroshot_pipeline.py
Comment thread src/deepsparse/clip/zeroshot_pipeline.py
Comment thread src/deepsparse/clip/zeroshot_pipeline.py
Comment thread src/deepsparse/clip/visual_pipeline.py Outdated
Comment thread tests/deepsparse/pipelines/test_clip.py
Comment thread src/deepsparse/clip/zeroshot_pipeline.py Outdated
dbogunowicz
dbogunowicz previously approved these changes Jul 31, 2023
Comment thread src/deepsparse/clip/zeroshot_pipeline.py
bfineran
bfineran previously approved these changes Jul 31, 2023
@dsikka dsikka dismissed stale reviews from bfineran and dbogunowicz via 06e958e July 31, 2023 20:18
@dsikka dsikka dismissed stale reviews from dbogunowicz and bfineran via ca54b1d August 1, 2023 14:10
@bfineran bfineran merged commit ed9b1ee into main Aug 2, 2023
@bfineran bfineran deleted the clip_zshot branch August 2, 2023 18:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants