Zero-shot इमेज क्लासिफिकेशन

Hugging Face के साथ मल्टी-मोडल मॉडल्स

James Chapman

Curriculum Manager, DataCamp

CLIP

  • Contrastive Language-Image Pre-training
  • इमेज और टेक्स्ट के बीच समानता स्कोर करें
  • 400M इमेज-टेक्स्ट पेयर्स पर प्रशिक्षित
  • दो एन्कोडर:
    • विज़न एन्कोडर
    • टेक्स्ट एन्कोडर
  • नज़दीकी इमेज-टेक्स्ट मैच मिलते-जुलते एरे बनाते हैं

CLIP का टेक्स्ट और इमेज एन्कोडिंग डायग्राम

1 https://openai.com/index/clip/
Hugging Face के साथ मल्टी-मोडल मॉडल्स

ज़ीरो-शॉट लर्निंग

  • ऐसे टास्क करें जिन पर मॉडल को ट्रेन नहीं किया गया था

ज़ीरो-शॉट लर्निंग: विमान की रैंकिंग

1 https://openai.com/index/clip/
Hugging Face के साथ मल्टी-मोडल मॉडल्स

यूज़ केस: प्रोडक्ट कैटेगराइज़ेशन

from datasets import load_dataset
import matplotlib.pyplot as plt

dset = "rajuptvs/ecommerce_products_clip"
dataset = load_dataset(dset)

print(dataset["train"][0]["Description"])
plt.imshow(dataset["train"][0]["image"]) plt.show()
Blive High quality premium Full sleeves printed 
Shirt direct from the manufacturers.Gives you 
a clean and classy look while also 
making you feel comfortable.Trusted 
brand online and no compromise on quality.

डेटासेट से शर्ट की तस्वीर

Hugging Face के साथ मल्टी-मोडल मॉडल्स

CLIP के साथ ज़ीरो-शॉट लर्निंग

model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
processor = CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")


categories = ["shirt", "trousers", "shoes", "dress", "hat", "bag", "watch"]
inputs = processor(text=categories, images=dataset["train"][0]["image"], return_tensors="pt", padding=True) outputs = model(**inputs)
probs = outputs.logits_per_image.softmax(dim=1)
categories[probs.argmax().item()]
shirt
Hugging Face के साथ मल्टी-मोडल मॉडल्स

CLIP स्कोर

  • एन्कोडेड इमेज और एन्कोडेड डिस्क्रिप्शन की समानता
  • 100 (पूर्ण सहमति) से 0 (कोई सहमति नहीं) तक रेंज
from torchmetrics.functional.multimodal import clip_score


image = dataset["train"][0]["image"] description = dataset["train"][0]["Description"]
from torchvision.transforms import ToTensor image = ToTensor()(image)*255
score = clip_score(image, description, "openai/clip-vit-base-patch32")
print(f"CLIP score: {score}")
CLIP score: 28.495952606201172
Hugging Face के साथ मल्टी-मोडल मॉडल्स

अभ्यास करते हैं!

Hugging Face के साथ मल्टी-मोडल मॉडल्स

Preparing Video For Download...