def __getitem__(self, index): boxes, labels = self.get_annotation(index) image = self._read_image(index) if self.transform: image, boxes, labels = self.transform(image, boxes, labels) if self.target_transform: boxes, labels = self.target_transform(boxes, labels) target = Container(boxes=boxes, labels=labels) return image, target, index
def __getitem__(self, index): image = self.images[index] boxes, labels = self.get_annotation(index) image = image[:, :, None].repeat(3, -1) if self.transform: image, boxes, labels = self.transform(image, boxes, labels) if self.target_transform: boxes, labels = self.target_transform(boxes, labels) target = Container(boxes=boxes, labels=labels) return image, target, index
def __call__(self, batch): transposed_batch = list(zip(*batch)) images = default_collate(transposed_batch[0]) img_ids = default_collate(transposed_batch[2]) if self.is_train: list_targets = transposed_batch[1] targets = Container( {key: default_collate([d[key] for d in list_targets]) for key in list_targets[0]} ) else: targets = None return images, targets, img_ids
def __getitem__(self, index): image_id = self.ids[index] boxes, labels = self._get_annotation(image_id) image = self._read_image(image_id) if self.transform: image, boxes, labels = self.transform(image, boxes, labels) if self.target_transform: boxes, labels = self.target_transform(boxes, labels) targets = Container( boxes=boxes, labels=labels, ) return image, targets, index
def __call__(self, detections): """ Post processor of detections when we are doing inference. Applies two filter operations to remove all prior boxes that does not include an object: Confidence thresholding and non-maximum suppression. """ batches_scores, batches_boxes = detections device = batches_scores.device batch_size = batches_scores.size(0) results = [] for batch_id in range(batch_size): scores, boxes = batches_scores[batch_id], batches_boxes[ batch_id] # (N, #CLS) (N, 4) num_boxes = scores.shape[0] num_classes = scores.shape[1] boxes = boxes.view(num_boxes, 1, 4).expand(num_boxes, num_classes, 4) labels = torch.arange(num_classes, device=device) labels = labels.view(1, num_classes).expand_as(scores) # remove predictions with the background label boxes = boxes[:, 1:] scores = scores[:, 1:] labels = labels[:, 1:] # batch everything, by making every class prediction be a separate instance boxes = boxes.reshape(-1, 4) scores = scores.reshape(-1) labels = labels.reshape(-1) # remove low scoring boxes indices = torch.nonzero( scores > self.cfg.TEST.CONFIDENCE_THRESHOLD).squeeze(1) boxes, scores, labels = boxes[indices], scores[indices], labels[ indices] boxes[:, 0::2] *= self.width boxes[:, 1::2] *= self.height keep = batched_nms(boxes, scores, labels, self.cfg.TEST.NMS_THRESHOLD) # keep only topk scoring predictions keep = keep[:self.cfg.TEST.MAX_PER_IMAGE] boxes, scores, labels = boxes[keep], scores[keep], labels[keep] container = Container(boxes=boxes, labels=labels, scores=scores) container.img_width = self.width container.img_height = self.height results.append(container) return results
def __getitem__(self, index): image_id = self.image_ids[index] boxes, labels, is_difficult = self._get_annotation(image_id) if not self.keep_difficult: boxes = boxes[is_difficult == 0] labels = labels[is_difficult == 0] image = self._read_image(image_id) if self.transform: image, boxes, labels = self.transform(image, boxes, labels) if self.target_transform: boxes, labels = self.target_transform(boxes, labels) targets = Container( boxes=boxes, labels=labels, ) return image, targets, index
def __call__(self, detections): batches_scores, batches_boxes = detections device = batches_scores.device batch_size = batches_scores.size(0) results = [] for batch_id in range(batch_size): scores, boxes = batches_scores[batch_id], batches_boxes[ batch_id] # (N, #CLS) (N, 4) num_boxes = scores.shape[0] num_classes = scores.shape[1] boxes = boxes.view(num_boxes, 1, 4).expand(num_boxes, num_classes, 4) labels = torch.arange(num_classes, device=device) labels = labels.view(1, num_classes).expand_as(scores) # remove predictions with the background label boxes = boxes[:, 1:] scores = scores[:, 1:] labels = labels[:, 1:] # batch everything, by making every class prediction be a separate instance boxes = boxes.reshape(-1, 4) scores = scores.reshape(-1) labels = labels.reshape(-1) # remove low scoring boxes indices = torch.nonzero( scores > self.cfg.TEST.CONFIDENCE_THRESHOLD).squeeze(1) boxes, scores, labels = boxes[indices], scores[indices], labels[ indices] boxes[:, 0::2] *= self.width boxes[:, 1::2] *= self.height keep = batched_nms(boxes, scores, labels, self.cfg.TEST.NMS_THRESHOLD) # keep only topk scoring predictions keep = keep[:self.cfg.TEST.MAX_PER_IMAGE] boxes, scores, labels = boxes[keep], scores[keep], labels[keep] container = Container(boxes=boxes, labels=labels, scores=scores) container.img_width = self.width container.img_height = self.height results.append(container) return results