Views
No views yet
1import torch
2import open_clip
3from PIL import Image
4
5# Load the model
6model, _, preprocess = open_clip.create_model_and_transforms('ViT-B-32', pretrained='openai')
7checkpoint = torch.load('model.pt', map_location='cpu')
8model.visual.load_state_dict(checkpoint['vision_encoder'])
9model.eval()
10
11# Process an image
12image = preprocess(Image.open('plant_image.jpg')).unsqueeze(0)
13with torch.no_grad():
14 image_features = model.visual(image)
15 image_features = image_features / image_features.norm(dim=-1, keepdim=True)
16
17# Use embeddings for similarity search in your vector database@inproceedings{radford2021learning,
title={Learning Transferable Visual Models From Natural Language Supervision},
author={Radford, Alec and Kim, Jong Wook and Hallacy, Chris and Ramesh, Aditya and Goh, Gabriel and Agarwal, Sandhini and Sastry, Girish and Askell, Amanda and Mishkin, Pamela and Clark, Jack and others},
booktitle={International Conference on Machine Learning},
pages={8748--8763},
year={2021},
organization={PMLR}
}