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

Object detection

इस अभ्यास में, आप पहले वाले ही flickr डेटासेट का उपयोग करेंगे, जिसमें 30,000 इमेज और उनसे जुड़ी captions हैं. अब आप मॉडल द्वारा डिटेक्ट किए गए objects के bounding boxes ढूँढेंगे.

Photo of 2 people, 1 is playing the guitar

सैंपल इमेज (image) और पाइपलाइन मॉड्यूल (pipeline) लोड किए जा चुके हैं.

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

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

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

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

  • facebook/detr-resnet-50 pretrained मॉडल के साथ object-detection पाइपलाइन लोड करें.
  • डिटेक्ट किए गए object का label निकालें.
  • डिटेक्ट किए गए object का संबंधित confidence score निकालें.
  • डिटेक्ट किए गए object के bounding box के coordinates निकालें.

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

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

# Load the object-detection pipeline
pipe = pipeline("____", "____", revision="no_timm")
pred = pipe(image)
outputs = pipe(image)

for n, obj in enumerate(outputs):
    # Find the detected label
    label = ____
    # Find the confidence score of the prediction
    confidence = ____
    # Obtain the bounding box coordinates
    box = ____
    
    plot_args = {"linewidth": 1, "edgecolor": colors[n], "facecolor": 'none'}
    rect = patches.Rectangle((box['xmin'], box['ymin']), box['xmax']-box['xmin'], box['ymax']-box['ymin'], **plot_args)
    ax.add_patch(rect)
    print(f"Detected {label} with confidence {confidence:.2f} at ({box['xmin']}, {box['ymin']}) to ({box['xmax']}, {box['ymax']})")

plt.show()
कोड संपादित करें और चलाएँ