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



bbox1 = [50, 50, 150, 150] bbox2 = [100, 100, 200, 200]bbox1 = torch.tensor(bbox1).unsqueeze(0) bbox2 = torch.tensor(bbox2).unsqueeze(0)
from torchvision.ops import box_iou
iou = box_iou(bbox1, bbox2)
print(iou)
tensor([[0.1429]])

model.eval() with torch.no_grad():output = model(input_image)print(output)
[{'boxes': tensor([[ 42.8553, 271.9481, 180.6003, 346.7082],
[191.6016, 80.4759, 247.8009, 387.5475], ....),
'scores': tensor([1.0000, 1.0000, 0.9998, ... ]),
'labels': tensor([18, 1, 20, 18, 18, 18 ...])
}]
boxes = output[0]["boxes"]scores = output[0]["scores"]


नॉन-मैक्स सप्रेशन: सबसे प्रासंगिक बाउंडिंग बॉक्स चुनने की सामान्य तकनीक
नॉन-मैक्स: कम कॉन्फिडेंस स्कोर वाले बॉक्स हटाना
सप्रेशन: कम IoU वाले बॉक्स हटाना
from torchvision.ops import nmsbox_indices = nms( boxes=boxes, scores=scores, iou_threshold=0.5, ) print(box_indices)
tensor([ 0, 1, 2, 8])
filtered_boxes = boxes[box_indices]
Boxes: बाउंडिंग बॉक्स कॉर्डिनेट्स वाले टेंसर, शेप [N, 4]
Scores: हर बॉक्स के कॉन्फिडेंस स्कोर वाला टेंसर, शेप [N]
iou_threshold: 0.0 से 1.0 के बीच थ्रेशोल्ड
आउटपुट: चुने गए बाउंडिंग बॉक्स के इंडिसेज़
PyTorch के साथ इमेज के लिए डीप लर्निंग