Faster R-CNN के साथ Region नेटवर्क प्रस्ताव

PyTorch के साथ इमेज के लिए डीप लर्निंग

Michal Oleszak

Machine Learning Engineer

Regions और anchor boxes

  • Region: इमेज का छोटा हिस्सा जिसमें रुचि के ऑब्जेक्ट हो सकते हैं, दृश्य गुणों से समूहित

region proposals

PyTorch के साथ इमेज के लिए डीप लर्निंग

Regions और anchor boxes

  • Region: इमेज का छोटा हिस्सा जिसमें रुचि के ऑब्जेक्ट हो सकते हैं, दृश्य गुणों से समूहित

region proposals

  • Anchor box: अलग-अलग साइज़ और शेप के पूर्व-परिभाषित bounding box टेम्पलेट
PyTorch के साथ इमेज के लिए डीप लर्निंग

Faster R-CNN मॉडल

Faster R-CNN: R-CNN का उन्नत संस्करण

rcnn layers

  • Backbone (convolutional layers)
1 Edward Raff. 2022. Inside Deep Learning.
PyTorch के साथ इमेज के लिए डीप लर्निंग

Faster R-CNN मॉडल

Faster R-CNN: R-CNN का उन्नत संस्करण rcnn layers

  • Backbone (convolutional layers)
  • Bounding box प्रस्तावों के लिए Region proposal network (RPN)
1 Edward Raff. 2022. Inside Deep Learning.
PyTorch के साथ इमेज के लिए डीप लर्निंग

Faster R-CNN मॉडल

Faster R-CNN: R-CNN का उन्नत संस्करण

rcnn layers

  • Convolution लेयर्स (backbone): feature maps
  • Region proposal network (RPN): bounding box प्रस्ताव
  • प्रिडिक्शन के लिए classifier और regressor
1 Edward Raff. 2022. Inside Deep Learning.
PyTorch के साथ इमेज के लिए डीप लर्निंग

Region proposal network (RPN)

region proposal network architecture

PyTorch के साथ इमेज के लिए डीप लर्निंग

Region proposal network (RPN)

region proposal network architecture

  • Anchor generator:
    • अलग-अलग साइज़ और aspect ratios के anchor boxes का सेट बनाएँ
PyTorch के साथ इमेज के लिए डीप लर्निंग

Region proposal network (RPN)

region proposal network architecture

  • Anchor generator:
    • अलग-अलग साइज़ और aspect ratios के anchor boxes का सेट बनाएँ
  • Classifier और regressor:
    • बॉक्स में ऑब्जेक्ट है या नहीं, और coordinates प्रिडिक्ट करें
PyTorch के साथ इमेज के लिए डीप लर्निंग

Region proposal network (RPN)

region proposal network architecture

  • Anchor generator:
    • अलग-अलग साइज़ और aspect ratios के anchor boxes का सेट बनाएँ
  • Classifier और regressor:
    • बॉक्स में ऑब्जेक्ट है या नहीं, और coordinates प्रिडिक्ट करें
  • Region of interest (RoI) pooling:
    • RPN प्रस्ताव को fully connected लेयर्स के लिए fixed साइज़ में रिसाइज़ करें
PyTorch के साथ इमेज के लिए डीप लर्निंग

PyTorch में RPN

from torchvision.models.detection.rpn import AnchorGenerator


anchor_generator = AnchorGenerator( sizes=((32, 64, 128),), aspect_ratios=((0.5, 1.0, 2.0),), )
from torchvision.ops import MultiScaleRoIAlign


roi_pooler = MultiScaleRoIAlign( featmap_names=["0"], output_size=7, sampling_ratio=2, )
PyTorch के साथ इमेज के लिए डीप लर्निंग

Fast R-CNN loss functions

  • RPN classification loss:
    • region में ऑब्जेक्ट है या नहीं
    • binary cross-entropy
    • rpn_cls_criterion = nn.BCEWithLogitsLoss()

 

  • RPN box regression loss:
    • bounding box coordinates
    • mean squared error
    • rpn_reg_criterion = nn.MSELoss()
  • R-CNN classification loss:
    • कई object classes
    • cross-entropy
    • rcnn_cls_criterion = nn.CrossEntropyLoss()

 

  • R-CNN box regression loss:
    • bounding box coordinates
    • mean squared error
    • rcnn_reg_criterion = nn.MSELoss()
PyTorch के साथ इमेज के लिए डीप लर्निंग

PyTorch में Faster R-CNN

from torchvision.models.detection import FasterRCNN


backbone = torchvision.models.mobilenet_v2(weights="DEFAULT").features
backbone.out_channels = 1280
model = FasterRCNN( backbone=backbone, num_classes=num_classes, rpn_anchor_generator=anchor_generator, box_roi_pool=roi_pooler, )
PyTorch के साथ इमेज के लिए डीप लर्निंग

PyTorch में Faster R-CNN

Pre-trained Faster R-CNN लोड करें

from torchvision.models.detection.faster_rcnn import FastRCNNPredictor

model = torchvision.models.detection.fasterrcnn_resnet50_fpn(weights="DEFAULT")

क्लासों की संख्या और classifier input size परिभाषित करें

num_classes = 2

in_features = model.roi_heads.box_predictor.cls_score.in_features

मॉडल के classifier को इच्छित क्लासों वाले से बदलें

model.roi_heads.box_predictor = FastRCNNPredictor(in_features, num_classes)
PyTorch के साथ इमेज के लिए डीप लर्निंग

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

PyTorch के साथ इमेज के लिए डीप लर्निंग

Preparing Video For Download...