def test_boundbox_rescale(boxes): scale = (3, 4) scales = (4, 3) * 4 boundbox_array = BoundBoxArray.from_boxes(boxes) scaled_boxes = [tuple(x / s for x, s in zip(box, scales)) for box in boxes] scaled_boundbox_array = BoundBoxArray.from_boxes(scaled_boxes) assert scaled_boundbox_array.equals(boundbox_array.rescale(scale))
def plot_matching_bboxes(self, save_path, default_boxes, threshold, class_mapping, colormap, background_class, filename=None): """Plot and save image with matching bounding boxes""" filename = filename or self.filename if not filename: raise ValueError("`filename` should be specified either on image" " creation or when calling this function.") normalized = self if self._bboxes_normalized else self.normalize_bboxes( ) labels, offsets = normalized.labels_and_offsets( default_boxes, threshold, class_mapping) reverse_mapping = reverse_dict(class_mapping) reverse_mapping[background_class] = "background" classnames = [reverse_mapping[label] for label in labels] # recover default boxes height, width = self.size scale = (1 / height, 1 / width) recovered = default_boxes.rescale(scale) matched = BoundBoxArray.from_boxes(recovered.as_matrix(), classnames) matched = matched[matched.classnames != "background"] plot_with_bboxes(normalized.image, matched, colormap, save_path, filename)
def test_boundbox_clipping(boxes): boundbox_array = BoundBoxArray.from_boxes(boxes) clipped = boundbox_array.clip((40, 50), (40, 50)) assert (clipped.x_min >= 40).all() assert (clipped.y_min >= 40).all() assert (clipped.x_max <= 50).all() assert (clipped.y_max <= 50).all()
def test_boundbox_creation(boundboxes, centerboxes, boxes, classnames): from_boundboxes = BoundBoxArray.from_boundboxes(boundboxes, classnames) assert from_boundboxes.shape == (2, 8) assert (from_boundboxes.index == classnames).all() from_centerboxes = BoundBoxArray.from_centerboxes(centerboxes, classnames) assert from_boundboxes.equals(from_centerboxes) from_boxes = BoundBoxArray.from_boxes(boxes, classnames) assert from_boundboxes.equals(from_boxes) assert from_centerboxes.equals(from_boxes)