-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed0ea55
commit 12a55d0
Showing
148 changed files
with
8,377 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import torch | ||
import torch.nn.functional as F | ||
from urllib.request import urlopen | ||
from PIL import Image | ||
from open_clip import create_model_from_pretrained, get_tokenizer | ||
|
||
model, preprocess = create_model_from_pretrained('hf-hub:UCSC-VLAA/ViT-L-14-CLIPS-Recap-DataComp-1B') | ||
tokenizer = get_tokenizer('hf-hub:UCSC-VLAA/ViT-L-14-CLIPS-Recap-DataComp-1B') | ||
|
||
image = Image.open(urlopen( | ||
'https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/beignets-task-guide.png' | ||
)) | ||
image = preprocess(image).unsqueeze(0) | ||
|
||
text = tokenizer(["a diagram", "a dog", "a cat", "a beignet"], context_length=model.context_length) | ||
|
||
with torch.no_grad(), torch.cuda.amp.autocast(): | ||
image_features = model.encode_image(image) | ||
text_features = model.encode_text(text) | ||
image_features = F.normalize(image_features, dim=-1) | ||
text_features = F.normalize(text_features, dim=-1) | ||
|
||
text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1) | ||
|
||
print("Label probs:", text_probs) # prints: [[0., 0., 0., 1.0]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from .version import __version__ | ||
|
||
from .coca_model import CoCa | ||
from .constants import OPENAI_DATASET_MEAN, OPENAI_DATASET_STD | ||
from .factory import create_model, create_model_and_transforms, create_model_from_pretrained, get_tokenizer, create_loss | ||
from .factory import list_models, add_model_config, get_model_config, load_checkpoint | ||
from .loss import ClipLoss, DistillClipLoss, CoCaLoss | ||
from .model import CLIP, CustomTextCLIP, CLIPTextCfg, CLIPVisionCfg, \ | ||
convert_weights_to_lp, convert_weights_to_fp16, trace_model, get_cast_dtype, get_input_dtype, \ | ||
get_model_tokenize_cfg, get_model_preprocess_cfg, set_model_preprocess_cfg | ||
from .openai import load_openai_model, list_openai_models | ||
from .pretrained import list_pretrained, list_pretrained_models_by_tag, list_pretrained_tags_by_model, \ | ||
get_pretrained_url, download_pretrained_from_url, is_pretrained_cfg, get_pretrained_cfg, download_pretrained | ||
from .push_to_hf_hub import push_pretrained_to_hf_hub, push_to_hf_hub | ||
from .tokenizer import SimpleTokenizer, tokenize, decode | ||
from .transform import image_transform, AugmentationCfg | ||
from .zero_shot_classifier import build_zero_shot_classifier, build_zero_shot_classifier_legacy | ||
from .zero_shot_metadata import OPENAI_IMAGENET_TEMPLATES, SIMPLE_IMAGENET_TEMPLATES, IMAGENET_CLASSNAMES |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.