Downloads · 30 days
6
23% of all-time downloads
Shoriful025/clip-zero-shot-ecommerce-v1
clip-zero-shot-ecommerce-v1 is a machine learning model from Shoriful025. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This model is based on OpenAI's CLIP (Contrastive Language–Image Pre-training) architecture, specifically fine-tuned for high-quality, zero-shot classification in the e-commerce domain. It can classify an image based…
Downloads · 30 days
6
23% of all-time downloads
All-time downloads
26
Public
Repo size
—
Likes
0
Public
Click a slice to open those files.
.md3.6 KB · 59%
From the Hugging Face model README
This model is based on OpenAI's CLIP (Contrastive Language–Image Pre-training) architecture, specifically fine-tuned for high-quality, zero-shot classification in the e-commerce domain. It can classify an image based on a set of text labels (classes) provided at inference time, without needing explicit retraining for those new labels. This is ideal for quickly categorizing new product images into evolving or granular hierarchies (e.g., "Sweaters" vs. "Cashmere Crewneck").
CLIPModel)To classify a product image using zero-shot inference:
from transformers import CLIPProcessor, CLIPModel
from PIL import Image
import torch
# Load model and processor
model_name = "YourOrg/clip-zero-shot-ecommerce-v1"
model = CLIPModel.from_pretrained(model_name)
processor = CLIPProcessor.from_pretrained(model_name)
# 1. Define Candidate Labels
candidate_labels = ["a photo of a ceramic mug", "a photo of a woolen scarf", "a photo of a leather belt"]
text_inputs = processor(text=candidate_labels, return_tensors="pt", padding=True)
# 2. Load the Image (Conceptual - Replace with actual image loading)
# image = Image.open("path/to/product_image.jpg")
dummy_image = Image.new('RGB', (224, 224), color = 'red')
image_inputs = processor(images=dummy_image, return_tensors="pt")
# 3. Calculate Similarity (Inference)
with torch.no_grad():
outputs = model(**text_inputs, **image_inputs)
logits_per_image = outputs.logits_per_image # (1, num_labels)
probs = logits_per_image.softmax(dim=1)
# Find the best match
best_match_index = probs.argmax().item()
predicted_label = candidate_labels[best_match_index]
confidence = probs[0][best_match_index].item()
print(f"Predicted Class: {predicted_label} (Confidence: {confidence:.2f})")