शुरू करेंमुफ़्त में शुरू करें

CV फाइन-ट्यूनिंग: मॉडल क्लासेज

इस अभ्यास में, आप एक pretrained मॉडल लोड करेंगे और आउटपुट को इस तरह अनुकूलित करेंगे कि यह मूल ImageNet ट्रेनिंग में उपयोग हुई 1000 क्लासेज की जगह Stanford Cars डेटासेट से कार मॉडल टाइप्स के नए classification को सपोर्ट करे। इस डेटासेट में कारों की लेबल की गई इमेजें हैं.

डेटासेट (dataset) लोड कर दिया गया है, और transformers से AutoModelForImageClassification भी उपलब्ध है। डेटासेट को फ़िल्टर कर दिया गया है ताकि तीन मॉडल टाइप्स शामिल हों.

यह अभ्यास पाठ्यक्रम का हिस्सा है

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

पाठ्यक्रम देखें

अभ्यास निर्देश

  • डेटासेट से नए लेबल नाम प्राप्त करें।
  • मॉडल लोड करते समय नया id2label मैपिंग जोड़ें।
  • संबंधित label2id मैपिंग जोड़ें।
  • क्लासेज की संख्या बदलने के लिए आवश्यक फ़्लैग जोड़ें.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Obtain the new label names from the dataset
labels = dataset["train"].features["____"].____

label2id, id2label = dict(), dict()
for i, label in enumerate(labels):
    label2id[label] = str(i)
    id2label[str(i)] = label

model = AutoModelForImageClassification.from_pretrained(
    "google/mobilenet_v2_1.0_224",
    num_labels=len(labels),
    # Add the id2label mapping
    id2label=____,
    # Add the corresponding label2id mapping
    label2id=____,
    # Add the required flag to change the number of classes
    ignore_mismatched_sizes=____
)
कोड संपादित करें और चलाएँ