Views
No views yet
ViT-B-32 on an e-commerce fashion catalog containing 14,833 products across 23 categories for Visual Product Search, "Shop the Look", and Cross-Modal Semantic Retrieval.ViT-B-32 (Vision Transformer Base, 32x32 patch size)openai1import torch
2import open_clip
3from PIL import Image
4
5# 1. Load model and preprocessing transforms directly from Hugging Face Hub
6model, _, preprocess = open_clip.create_model_and_transforms('hf-hub:Panavath/fashion-clip-b32')
7tokenizer = open_clip.get_tokenizer('ViT-B-32')
8
9model.eval()
10
11# 2. Embed an image
12image = preprocess(Image.open('path_to_clothing.jpg')).unsqueeze(0)
13with torch.no_grad():
14 image_features = model.encode_image(image)
15 image_features /= image_features.norm(dim=-1, keepdim=True)
16
17# 3. Embed a text query
18text = tokenizer(['black tactical cargo pants', 'formal striped button down shirt'])
19with torch.no_grad():
20 text_features = model.encode_text(text)
21 text_features /= text_features.norm(dim=-1, keepdim=True)
22
23# 4. Compute cosine similarity
24similarity = (image_features @ text_features.T).squeeze(0)
25print('Similarity scores:', similarity)