示例#1
0
 def __call__(self, image, target=None):
     image = F.normalize(image, mean=self.mean, std=self.std)
     if target is None:
         return image, None
     target = target.copy()
     h, w = image.shape[-2:]
     if "boxes" in target:
         boxes = target["boxes"]
         boxes = box_xyxy_to_cxcywh(boxes)
         boxes = boxes / torch.tensor([w, h, w, h], dtype=torch.float32)
         target["boxes"] = boxes
     return image, target
示例#2
0
文件: detr.py 项目: zivzone/d2go
 def prepare_targets(self, targets):
     new_targets = []
     for targets_per_image in targets:
         h, w = targets_per_image.image_size
         image_size_xyxy = torch.as_tensor([w, h, w, h],
                                           dtype=torch.float,
                                           device=self.device)
         gt_classes = targets_per_image.gt_classes
         gt_boxes = targets_per_image.gt_boxes.tensor / image_size_xyxy
         gt_boxes = box_xyxy_to_cxcywh(gt_boxes)
         new_targets.append({"labels": gt_classes, "boxes": gt_boxes})
         if self.mask_on and hasattr(targets_per_image, 'gt_masks'):
             gt_masks = targets_per_image.gt_masks
             gt_masks = convert_coco_poly_to_mask(gt_masks.polygons, h, w)
             new_targets[-1].update({'masks': gt_masks})
     return new_targets
示例#3
0
 def test_box_cxcywh_to_xyxy(self):
     t = torch.rand(10, 4)
     r = box_ops.box_xyxy_to_cxcywh(box_ops.box_cxcywh_to_xyxy(t))
     self.assertLess((t - r).abs().max(), 1e-5)