Update README.md
Browse files
README.md
CHANGED
|
@@ -49,6 +49,7 @@ This repository contains the **MobileCLIP2-S0** checkpoint.
|
|
| 49 |
import torch
|
| 50 |
import open_clip
|
| 51 |
from PIL import Image
|
|
|
|
| 52 |
from timm.utils import reparameterize_model
|
| 53 |
|
| 54 |
model, _, preprocess = open_clip.create_model_and_transforms('MobileCLIP2-S0', pretrained='dfndr2b')
|
|
@@ -64,7 +65,7 @@ image = Image.open(urlopen(
|
|
| 64 |
image = preprocess(image).unsqueeze(0)
|
| 65 |
text = tokenizer(["a diagram", "a dog", "a cat", "a doughnut"])
|
| 66 |
|
| 67 |
-
with torch.no_grad(), torch.
|
| 68 |
image_features = model.encode_image(image)
|
| 69 |
text_features = model.encode_text(text)
|
| 70 |
image_features /= image_features.norm(dim=-1, keepdim=True)
|
|
|
|
| 49 |
import torch
|
| 50 |
import open_clip
|
| 51 |
from PIL import Image
|
| 52 |
+
from urllib.request import urlopen
|
| 53 |
from timm.utils import reparameterize_model
|
| 54 |
|
| 55 |
model, _, preprocess = open_clip.create_model_and_transforms('MobileCLIP2-S0', pretrained='dfndr2b')
|
|
|
|
| 65 |
image = preprocess(image).unsqueeze(0)
|
| 66 |
text = tokenizer(["a diagram", "a dog", "a cat", "a doughnut"])
|
| 67 |
|
| 68 |
+
with torch.no_grad(), torch.amp.autocast(image.device.type):
|
| 69 |
image_features = model.encode_image(image)
|
| 70 |
text_features = model.encode_text(text)
|
| 71 |
image_features /= image_features.norm(dim=-1, keepdim=True)
|